All questions

Targeting carts that contain a specific product line on Hydrogen

Asked by Sasha Lindgren on

SLSasha Lindgren

I want a bundle upsell banner that only shows when the cart already contains an item from our serum line. My attempts so far:

// attempt 1: does not match anythingcart's items contains "serum"
// attempt 2: editor rejects itcart's items' name matches "serum"

I suspect I need some kind of quantifier over the items but I cant find the exact form. What are the operator semantics for matching against a list of cart items?

Was this helpful?

1 answer

EDElif DemirAccepted answer

You guessed right, it is a quantifier. The documented form is:

some item in cart's items satisfies item's name matches "t-shirt"

Adapted to your line:

some item in cart's items satisfies item's name matches "serum"

The some ... satisfies construct binds item to each element of cart's items and the whole condition is true if any item matches. Your first attempt failed because contains on the items list compares whole elements, not a field inside them, and the second failed because possessives do not distribute over lists.

Beyond items, cart attributes like total, subtotal, and coupon are queryable in the same audience if you want to combine conditions (e.g. only upsell above a certain subtotal).

On the data side you need nothing extra: cart updates are auto-tracked by the Hydrogen SDK, so the audience reacts mid-session as soon as the serum lands in the cart. There is a longer walkthrough of the quantifier syntax in How do quantifiers work over cart items in CQL?.

Was this helpful?
SLSasha Lindgren

Works perfectly, and the explanation of why contains failed is exactly what I was missing. Thanks!

Still have questions?