<p>Try just POSTing the new absolute quantity you want to change to - e.g. if you have 5 in your cart and want to decrement by one, you'd POST something along these lines:</p>
<pre><code>{
    &quot;redirect&quot;: &quot;6bb2a73aac3479c68e0946e4455624e2c1b840bc2b6356074a51ba01ee1234d/cart&quot;,
    &quot;action&quot;: &quot;commerce/cart/update-cart&quot;,
    &quot;lineItems[82503][qty]&quot;: &quot;4&quot;,
    &quot;lineItems[82503][options][note]&quot;: &quot;&quot;
}
</code></pre>
<p>That's what we do, and it works.</p>
<p>Result:</p>
<pre><code>{
    &quot;lineItems&quot;: [
        {
            &quot;id&quot;: 82503,
            &quot;weight&quot;: 0,
            &quot;length&quot;: 0,
            &quot;height&quot;: 0,
            &quot;width&quot;: 0,
            &quot;qty&quot;: 4,
            &quot;note&quot;: &quot;&quot;,
            &quot;privateNote&quot;: &quot;&quot;,
            &quot;purchasableId&quot;: &quot;5115&quot;,
            &quot;orderId&quot;: 145817,
            &quot;lineItemStatusId&quot;: null,
            &quot;taxCategoryId&quot;: 1,
            &quot;shippingCategoryId&quot;: 1,
            &quot;dateCreated&quot;: &quot;2020-10-29T11:55:02+11:00&quot;,
            &quot;dateUpdated&quot;: &quot;2020-11-25T11:34:47+11:00&quot;,
            ...etc
}
</code></pre>

CC BY-SA 4.0
2020-11-25T00:37:36.447Z
2020-11-25T00:37:36.447Z
Jeremy Daalder
<p>I may be missing something obvious but I'm trying to update a +/- quantity button system for adding products to work on Craft Commerce 3</p>
<p>The desired functionality is that click '+' increases the cart amount for that item by one, clicking '-' decreases the cart amount for that item by one.</p>
<p>The original build was in commerce 1, and the apparent way it was written was just by running an update cart ajax call (at what was then 'commerce/cart/updateCart') and passing through a '1' or '-1' as the quantity value. That doesn't appear to work anymore. The '+' call will add the '1', but passing the '-1' through for the '-' call does nothing. It just returns the same cart as if I passed through a zero.</p>
<p>I tried with 'commerce/cart/remove-line-item' but that removes all quantities of the line item rather than just decrement it by one.</p>
<p>I've tried passing the following into an ajax post request:</p>
<pre><code>var data = {
            ['CRAFT_CSRF_TOKEN']: token,
            action: 'commerce/cart/update-cart',
            lineItems: {[lnid]: {'qty': dec}}
        };
</code></pre>
<p>With lnid being the line item id and dec being the new desired quantity (I also tried -1 there) but that just destroys the line item completely.</p>

<craft3><ajax><plugin-craftcommerce3>
Craft Commerce 3 Decrease line Item qty by one?
# Craft Commerce 3 Decrease line Item qty by one?

(Asked by: username_0 on 2020-11-02)

I may be missing something obvious but I'm trying to update a +/- quantity button system for adding products to work on Craft Commerce 3
The desired functionality is that click '+' increases the cart amount for that item by one, clicking '-' decreases the cart amount for that item by one.
The original build was in commerce 1, and the apparent way it was written was just by running an update cart ajax call (at what was then 'commerce/cart/updateCart') and passing through a '1' or '-1' as the quantity value. That doesn't appear to work anymore. The '+' call will add the '1', but passing the '-1' through for the '-' call does nothing. It just returns the same cart as if I passed through a zero.
I tried with 'commerce/cart/remove-line-item' but that removes all quantities of the line item rather than just decrement it by one.
I've tried passing the following into an ajax post request:
var data = {
            ['CRAFT_CSRF_TOKEN']: token,
            action: 'commerce/cart/update-cart',
            lineItems: {[lnid]: {'qty': dec}}
        };

With lnid being the line item id and dec being the new desired quantity (I also tried -1 there) but that just destroys the line item completely.

**Tags:** craft3, ajax, plugin-craftcommerce3

---

## 1 answers

### Answer by username_1 on 2020-11-25. Score: 3 | Accepted answer

Try just POSTing the new absolute quantity you want to change to - e.g. if you have 5 in your cart and want to decrement by one, you'd POST something along these lines:
{
    "redirect": "6bb2a73aac3479c68e0946e4455624e2c1b840bc2b6356074a51ba01ee1234d/cart",
    "action": "commerce/cart/update-cart",
    "lineItems[82503][qty]": "4",
    "lineItems[82503][options][note]": ""
}

That's what we do, and it works.
Result:
{
    "lineItems": [
        {
            "id": 82503,
            "weight": 0,
            "length": 0,
            "height": 0,
            "width": 0,
            "qty": 4,
            "note": "",
            "privateNote": "",
            "purchasableId": "5115",
            "orderId": 145817,
            "lineItemStatusId": null,
            "taxCategoryId": 1,
            "shippingCategoryId": 1,
            "dateCreated": "2020-10-29T11:55:02+11:00",
            "dateUpdated": "2020-11-25T11:34:47+11:00",
            ...etc
}


---

