Changing basket item properties in Shopify

Is it possible to change the properties of a position after they have been added to the basket? (Either through a regular form feed, or through AJAX?)

I tried POST to / cart / change with the key "properties [MyProperty]", but so far no luck. This is due to the line parameter to indicate a unique position.

Any ideas? Or is it just no?

+5
source share
2 answers

Using the Shopify API, you cannot use cart / change.js to change position properties. The reason is that cart / change.js uses "properties" to find the position you need. The API documentation does not. Here is an example:

When I do a POST in cart / add.js with the following URL encoded parameters:

quantity=9403&id=278440178&properties%5Bmy-property%5D=property%20BAR

The answer will include

"properties":{"my-property":"property BAR"}

POST cart/change.js, BAR FOO,

id=278440178&properties%5Bmy-property%5D=property%20FOO

,

"properties":{"my-property":"property BAR"}

, . , , API cart/change.js - , .

, , POST cart/change.js quantity=0, :

quantity=0&id=278440178&properties%5Bmy-property%5D=property%20FOO

property FOO , ( property BAR), . , , :

POST: quantity=0&id=278440178&properties%5Bmy-property%5D=property%20BAR

.

: cart/change.js, shopify , 'id', , . , cart/change.js , .

+5

, POST /change.js . - :

$('.line-item-property__field').on('change', 'input[type="checkbox"]', function() {
    var $el = $(this),
        itemIndex = $el.closest('.cart-list__row').data('row'),
        giftWrap;

    if ($el.prop('checked'))
        giftWrap = 'Yes';
    else
        giftWrap = '';

    jQuery.ajax({
        url: '/cart/change.js',
        type: 'post',
        dataType: 'json',
        data: { line: itemIndex, properties: { 'Gift wrap': giftWrap } },
        success: function (data) {
            console.log(data)
        },
        error: function () {
            alert(data.description);
        }
    });
});

, ( "" undefined) .

0

All Articles