Properties vs customAttributes: can someone help me understand the difference?

Solved
funko
New Member
2 1 2

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?

Accepted Solution (1)

Accepted Solutions
funko
New Member
2 1 2

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

View solution in original post

Replies 2 (2)
funko
New Member
2 1 2

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

View solution in original post

PaulNewton
Shopify Partner
3351 215 642

In case of confusion cart.attributes and checkout.attributes are not accessible in shopifycheckoutscripts.

https://help.shopify.com/en/manual/apps/apps-by-shopify/script-editor/limitations#cart-checkout-attr...

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

Problem Solved? ✔️Accept and ? Like the solution so you can help others.
Buy me a coffee ☕ paypal.me/paulnewton or donate to eff.org
Confused? Busy? Buy a custom solution paull.newton+shopifyforum@gmail.com