Complete guide to hooks in Glood.AI section templates
onSectionInit
is called when section is first created
getProductDetailsQuery
is called to prepare GraphQL query
postProductFetch
processes raw product data
transformProductData
transforms individual product data
afterSectionRendered
is called once section is rendered on the page and ready to be used.
Note: This is an optional hook, if you want to perform certain task, you can add your logic in this hook.
initSwiper
(if carousel is enabled)
onVariantChange
handles variant selection
Note: This is an optional hook, if you want to perform certain task, you can add your logic in this hook.
onSwatchChange
handles swatch interactions
Note: This is an optional hook, if you want to perform certain task, you can add your logic in this hook.
beforeAddToCart
validates cart operations
afterAddToCart
handles post-cart updates
Note: This is an optional hook, if you want to perform custom logic, you can setup your logic in this hook.
args
contains:
cb
(Callback Function):
gloodUtils
provides:
Function | Description |
---|---|
formatMoney | Formats price values according to store’s money format |
optimizeImage | Optimizes image URLs with specified dimensions and crop settings |
getVariantFromOptions | Finds a variant based on selected options |
findVariantById | Retrieves a variant using its ID |
getSelectedVariant | Gets currently selected variant for a product |
getDefaultVariant | Returns the default/first available variant |
addToCart | Handles adding items to cart with proper validation |
updateCart | Updates existing cart items (quantity, properties) |
getProductUrl | Generates product URL with tracking parameters |
getDiscountedPrice | Calculates discounted price based on rules |
formatDiscount | Formats discount text with proper currency/percentage |
getTranslation | Retrieves translated text with fallback support |
trackEvent | Sends tracking events to analytics |
refreshSection | Re-renders section with updated data |
showNotification | Displays toast/notification messages |
recommendation
contains:
section
object with:
id
(number): Unique section identifierlayout
(String): Section layout typediscount_config
(Object): Discount settingswidget_message
(String): Custom message templateproducts
(Array): Currently loaded productstemplate
(Object): Template-specific settingsglood
provides:
shop
object containing:
money_format
(String): Store currency formatlocale
(String): Store language codeproduct
object with:
id
(String): Current product context (format: “gid://shopify/Product/”)handle
(String): Product URL handlelocalization
settings for:
args
(Object):
products
(Array): Raw product data arrayrecommendation
(Object): Section configurationtemplate
(Object): Template settingsutils
(Object): Helper functionsproduct
(Raw GraphQL data) contains:
id
(String): GraphQL product ID (format: “gid://shopify/Product/”)handle
(String): Product URL handletitle
(String): Product titlevendor
(String): Product vendorfeaturedImage
(Object): Main product imageimages
(Object): Additional product imagespriceRange
(Object): Min/max pricescompareAtPriceRange
(Object): Original pricesvariants
(Object): Product variants datavariantsCount
(Object): Total variants countoptions
(Array): Product optionsselectedOptions
(Array): Default selectionsavailableForSale
(Boolean): Stock statustags
(Array): Product tagsrecommendation
provides:
section
settings:
Product
object containing:
Swiper
(Constructor Class):
templateSettings
contains:
template.settings
with:
carousel
(Object): Carousel-specific settingsbreakpoints
(Object): Responsive configuration:
small
(Object): Mobile settingsmedium
(Object): Tablet settingslarge
(Object): Desktop settingsscreenSize
(Number): Width breakpointcardsPerView
(Number): Visible slidesgutter
(Number): Space between slidescontainer
(HTMLElement):
params
contains:
recommendation
:
section
(Object): Section configurationproducts
(Array): Product datadefaultSettings
contains:
utils
provides:
merge
: Deep object mergingSwiper
instance if initialization succeedsundefined
if initialization failsargs
contains:
variant
information:
product
datautils
provides:
args
contains:
option
object with:
name
(String): Option name (e.g., “Color”, “Size”)value
(String): Selected option valuetype
(String): Swatch type (color/size/material)swatchImage
(String, optional): Custom swatch image URLproduct
object containing:
variants
(Array): All product variantsoptions
(Array): Available option typesselectedVariant
(Object): Currently selected variantimages
(Array): Product imagescontainer
(HTMLElement): Product card DOM elementutils
provides:
updateSwatchUI
: Updates swatch selection statefindMatchingVariant
: Finds variant by optionsupdateProductImage
: Updates product imageupdatePriceDisplay
: Updates price displayargs
contains:
operation
(String): Type of operation (‘add’|‘update’|‘remove’)response
object with:
cart
(Object): Updated cart stateitems
(Array): Modified cart itemstotal
(Number): New cart totalcount
(Number): Updated item countsection
containing:
container
(HTMLElement): Section containerutils
provides:
updateCartUI
: Updates cart displayshowNotification
: Displays notificationsupdateInventory
: Updates stock statusgloodUtils
provides:
trackCartEvent
: Analytics trackingformatCartData
: Data formattingupdateShopifyCart
: Cart sync utilitiespayload
contains:
recommendation
provides:
section
configurationutils
and gloodUtils
:
args
contains:
products
array with raw product data:
id
(number): Product identifiertitle
(String): Product titlehandle
(String): Product URL handlefeaturedImage
(Object): Main product imagevariants
(Array): Raw variant dataoptions
(Array): Product optionstags
(Array): Product tagssection
object with:
template
containing:
utils
provides:
processImages
: Image optimization utilitiesformatProductData
: Data formatting helpersvalidateProducts
: Data validation functionsenrichProductData
: Data enrichment utilitieshandleErrors
: Error handling functionsbodyElem
(HTMLElement):
Boolean
- True if AJAX cart is active and should be loaded
Example:
bodyElem
(HTMLElement):
Boolean
- True if AJAX cart is inactive and should be unloaded
Example:
formatMoney
: Price formattinggetVariantById
: Variant lookupupdateUrl
: URL manipulationmerge
: Object mergingimageOptimizer
: Image optimizationglood
: Store configurationtranslations
: Text stringstemplate
: Template settingssection
: Section configurationutils
: Common utilitiestransformProductData
needs data from getProductDetailsQuery
afterSectionRendered
needs data from transformProductData
onVariantChange
afterSectionRendered