Personalized checkout and custom promotions with Shopify Scripts
I can read properties via a Shopify Script.
And I can set customAttributes via the JS Buy SDK.
But I can't figure out how to get the script to read the customAttributes or how to get the JS Buy SDK to write properties.
Can someone point me in the right direction?
Solved! Go to the solution
This is an accepted solution.
I answered my own question. Setting values with customAttributes via JS Buy allows you to read them as properties in the shopify scripts API.
JS Buy SDK:
{ variantId: item.variantId, quantity: item.quantity, customAttributes: [ { key: 'foo', value: 'bar' } ] }
Scripts API:
line_item.properties.each do |key,val| if (key === 'foo') then puts val #do something with your val end end
This is an accepted solution.
I answered my own question. Setting values with customAttributes via JS Buy allows you to read them as properties in the shopify scripts API.
JS Buy SDK:
{ variantId: item.variantId, quantity: item.quantity, customAttributes: [ { key: 'foo', value: 'bar' } ] }
Scripts API:
line_item.properties.each do |key,val| if (key === 'foo') then puts val #do something with your val end end
In case of confusion cart.attributes and checkout.attributes are not accessible in shopifycheckoutscripts.
The above "customAttributes" of the JSbuy sdk is poorly named and is on par with Line Item Properties on products
https://github.com/Shopify/js-buy-sdk/blob/master/README.md#adding-line-items
Save time & money ,Ask Questions The Smart Way
Confused? Busy? Get the solution you need paull.newton+shopifyforum@gmail.com
Problem Solved? ✔Accept and Like solutions to help future merchants
Answers powered by coffee Buy Paul a ☕ Coffee for more answers or donate to eff.org
REST API -> For line_items it's properties. For draftOder or order it's note_attributes.
GRAPHQL API -> CustomAttributes in both cases
LIQUID / email template: properties for the line items and attributes for the note_attributes.
Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024The Hydrogen Visual Editor is now available to merchants in Shopify Editions | Summer '...
By JasonH Sep 2, 2024Note: Customizing your CSS requires some familiarity with CSS and HTML. Before you cust...
By JasonH Aug 12, 2024