Home
Wiki
Home
Wiki
  1. 3. Reusables
  • Back to home
  • 1. Themes
  • Vs Code
    • Getting Started
  • Kitchenware
    • Layout
      • New Layout
      • Legacy Layout
    • Components
      • Announcement
      • Banner Carousel
      • Banner With Products Carousel
      • Blog Category List
      • Blog List
      • Brand List
      • Brands Carousel
      • Breadcrumb
      • Call To Action
      • Cart
      • Categories List
      • Change Password
      • Checkout
      • Cookie Manager
      • Filter list
      • Footer
      • Forgot Password
      • Form
      • Hero Carousel
      • Icon Block
      • Invitation
      • Last Visited Products
      • Layout
      • Login
      • Map
      • Nav Bar
      • Offer
      • Product Attachments
      • Product Attributes
      • Product Documentation
      • Product Expected
      • Product Modal
      • Products Block
      • Products Carousel
      • Product Single
      • Profile
      • Quote
      • Register
      • Related Products
      • Search
      • Stores
      • Subscribe Newsletter
      • Text with Image
      • Top Bar
      • Video
    • Reusables
      • Getting Started
    • Assets
      • Getting Started
    • SDK
      • Products
        • _findProductsByCategory
        • _findProductsByIds
        • _findProductsByTitle
        • _findProductsByFilter
        • _findProductsByCriteria
        • _findProductsAndCalculate
        • _findProductsThenCalculate
        • _getProductAttributeSet
        • _setLastVisited
      • Categories
        • _findCategoryTreeById
        • _findCategoriesByIds
        • _findCategoryByAlias
        • _findCategoryTreeByAlias
        • _getCategoryContent
      • Collections
        • _getCollectionContent
        • _findCollectionsByIds
        • _findCollectionsByIdsThenCalculate
      • Brands
        • _getBrandContent
        • _findBrandsByIds
      • Cart
        • _addToCartMulti
        • _addToCart
        • _setCart
        • _clearCart
        • _setCartListener
        • _removeFromCart
        • _calculateCart
      • Checkout
        • _startCheckout
        • _updateCheckout
        • _completeCheckout
      • Shopping Lists
        • _getShoppingLists
        • _updateShoppingList
        • _createShoppingList
        • _deleteShoppingList
        • _getShoppingListByAlias
      • Navigation
        • _getFooterMenu
        • _getHeaderMenu
      • Users
        • _getUserById
      • Utils
        • _calculateCurrency
        • _getCurrencySymbol
        • _getCulture
        • _subscribeToNewsletter
        • _findUnitsByIds
  • Noir
    • 0. Introduction
    • 6. FAQ
    • 1. Structure
      • _Overview
      • LayoutA.liquid
      • ComponentsList.liquid
      • Metas.liquid
      • CssVariables.liquid
      • Json.liquid
      • GoogleTagManager.liquid
      • StagingButton.liquid
    • 2. Components
      • _Overview
      • Announcement
      • BannerCarousel
      • BlogCategoryList
      • BlogHighlights
      • BlogList
      • BrandList
      • Breadcrumb
      • Cart
      • CategoriesList
      • ChangePassword
      • Checkout
      • CookieManager
      • CustomTable
      • Faq
      • FilterList
      • Footer
      • ForgotPassword
      • Form
      • IconBlock
      • Invitation
      • LastVisitedProducts
      • Login
      • Map
      • NavBar
      • Offer
      • ProductAttachments
      • ProductAttributes
      • ProductComparison
      • ProductDocumentation
      • ProductMixList
      • ProductsBlock
      • ProductsCarousel
      • ProductSingle
      • Profile
      • Quote
      • Register
      • RelatedProducts
      • SingleBlog
      • Stores
      • TextWithImage
      • ThankYouPage
      • TopBar
      • Wishlist
      • OrderReviews
      • ProductReviews
      • Newsletter
    • 3. Reusables
      • _Overview
      • Addresses
      • AddressForm
      • AnnouncementModal
      • BackToTop
      • BillingRetail
      • BlogPostingStructuredData
      • BrandListStructuredData
      • CollectionStructuredData
      • Company
      • General
      • GroupChildrenTable
      • Login
      • LoginModal
      • MonthlyTransactions
      • Offers
      • Orders
      • Payment
      • ProductAttachments
      • ProductAttributes
      • ProductAvailabilityAction
      • ProductComparisonButton
      • ProductComparisonFloatingButton
      • ProductGridItem
      • ProductGridItemClassic
      • ProductListItem
      • ProductModal
      • ProductStructuredData
      • ProfileInfo
      • PromptModal
      • Quotes
      • Register
      • Services
      • Shipping
      • ShoppingLists
      • ShoppingListsButton
      • ShoppingListsNavbar
      • StoresStructuredData
      • Toast
      • Transactions
      • Users
      • VariantContent
      • VariantContentClassic
      • WishlistButton
      • ProductRating
      • ClientHelpers
    • 4. Assets
      • Fonts
      • Images
      • Templates
      • Javascript
        • _Overview
        • theme.js
      • Css - Scss
        • _Overview
        • ThemeClasses
    • 5. SDK
      • _Overview
      • LiquidGlobals
      • ServicesSDK
  1. 3. Reusables

ClientHelpers

Purpose#

ClientHelpers holds small browser-side helpers that several Noir components and reusables share. It exists so a rule that must behave identically everywhere is written once instead of being copied into each component.
Nothing in it comes from the server: it has no model, no Liquid output and no API calls. It only registers the global JavaScript object clienthelpersreusabledefault.

Where it's rendered#

No direct Liquid render call was found for Reusables/ClientHelpers/Default in this workspace. Like Services, it is a JavaScript-only reusable whose global is consumed by other reusables.

Inputs (Liquid render parameters)#

This reusable is rendered without Liquid parameters.

Template behavior (Liquid + Alpine)#

This reusable does not render UI. Default.liquid is empty and Default.json holds no translations.

Data contract (JS runtime)#

The global object is a plain set of functions. They take the calling Alpine component as an argument and call its own methods, so the component keeps its side effects (store updates, quantity, images).

JavaScript#

The functions are grouped into three sections in Default.js: Product Variant picker, Product stock and Product analytics (GA).

Product Variant picker#

preselectSingleItemDimensions(component)#

Variant picker helper.
What it does
Goes through dimension1 and dimension2 of component.product.
When a dimension has exactly one item and the component has no selection for it yet, selects that item. A Color dimension goes through component.setSelectedColor(id, label); a non-color dimension that matches component.otherDimKey goes through component.setSelectedOther(id, label); any other dimension (when the product has no Color dimension, so otherDimKey is null) goes through component.setDimension("Dim1" | "Dim2", id, label).
Does nothing when the product is missing.
Key behaviors / edge cases
A dimension with a single item is selected even when the product's other dimension still has several options.
A dimension that already has a selection (selectedDim1Id / selectedDim2Id) is left unchanged.
The component must have detected its colorDimKey / otherDimKey before calling it, and must expose setSelectedColor and setSelectedOther.
Used by
ReusableCalled from
ProductGridIteminit()
ProductGridItemClassicinit()
ProductListIteminit()
VariantContentreInitWithProduct()
VariantContentClassicreInitWithProduct()

setSelectedColor(component, id, label)#

Stores the chosen color item on the component (selectedDimColorId, selectedDimColorLabel), copies it to selectedDim1* or selectedDim2* depending on component.colorDimKey, then calls component.updateSelectedVariant().

setSelectedOther(component, id, label)#

Same as setSelectedColor for the non-color dimension: stores selectedDimOtherId and selectedDimOtherLabel, copies them to selectedDim1* or selectedDim2* depending on component.otherDimKey, then calls component.updateSelectedVariant().

setDimension(component, key, id, label)#

Stores selected<key>Id and selected<key>Label for one dimension (for example Dim1), then calls component.updateSelectedVariant().
Used by (setSelectedColor, setSelectedOther, setDimension)
Each of the five components keeps its own method with the same name and signature without component. The method only forwards this to the helper, so templates call setSelectedColor(id, label) as before.
Reusable
ProductGridItem
ProductGridItemClassic
ProductListItem
VariantContent
VariantContentClassic

Product stock#

formatStockQuantity(quantity)#

Formats a stock quantity with the page language (document.documentElement.lang) and at most 3 decimals. Returns an empty string for null, undefined, an empty string or a value that is not a number.

stockTextFor(sa, availableText, outOfStockText)#

Returns the text for a stock availability object sa:
Available returns availableText.
OutOfStock returns outOfStockText.
Varies returns -.
Anything else (a custom availability) returns its own message, or an empty string.
Used by: the same five components, through their own formatStockQuantity and stockTextFor methods, which forward to the helper. currentStock, stockText and stockQuantityText stay in each component because they read the selected variant index.

Product analytics (GA)#

sendSelectEvent(product, listName, position)#

Sends the GA selectItem event for the product, using prepareListProducts and sendGAEvent. listName defaults to an empty string.

sendSelectEventAndRedirect(product, listName, position)#

Sends the same event, then goes to /product/<product.alias>.
Used by: ProductGridItem, ProductGridItemClassic and ProductListItem, through their own methods with the same names, which forward to the helper.

Notes#

Group helpers in Default.js with //SECTION and //ANCHOR comments, one //ANCHOR comment per function describing what it does.
Add new shared client-side helpers here, and list their callers on this page.
Modified at 2026-11-17 10:35:31
Previous
ProductRating
Next
Fonts
Built with