[Skip to main content](#vessel-content)

#   Quantity Increase / Decrease upon cart add

##

- **[bassimbg](/forum/user/36592-bassimbg "View bassimbg's Profile")**
- [![bassimbg's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/36592-bassimbg "View bassimbg's Profile") Topic Author
- [ Offline](/forum/user/36592-bassimbg)

Less More

- Posts: 11
- Thank you received: 0
-
-

11 years 7 months ago [\#195995](#195995) by [bassimbg](/forum/user/36592-bassimbg "View bassimbg's Profile")  *[Quantity Increase / Decrease upon cart add](/forum/35-orders-management/875908-quantity-increase-decrease-upon-cart-add#195995 "-- HikaShop version -- : 2.4.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.3.13  How can I deduct from the product quantity immediately when any use add the items to the cart and then add the quantity back in case of empty the cart or cart expiry?")* was created by *[bassimbg](/forum/user/36592-bassimbg "View bassimbg's Profile")*

-- HikaShop version -- : 2.4.0
-- Joomla version -- : 3.4.1
-- PHP version -- : 5.3.13

How can I deduct from the product quantity immediately when any use add the items to the cart and then add the quantity back in case of empty the cart or cart expiry?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50Lzg3NTkwOC1xdWFudGl0eS1pbmNyZWFzZS1kZWNyZWFzZS11cG9uLWNhcnQtYWRkP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Xavier](/forum/user/4105-xavier "View Xavier's Profile")**
- [![Xavier's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar4105.png)](/forum/user/4105-xavier "View Xavier's Profile")
- [ Offline](/forum/user/4105-xavier)

Less More

- Posts: 13201
- Thank you received: 2322
-
-
-
- [](http://www.kidiweb.fr)
-

11 years 7 months ago [\#195999](#195999) by [Xavier](/forum/user/4105-xavier "View Xavier's Profile")  Replied by *[Xavier](/forum/user/4105-xavier "View Xavier's Profile")* on topic *[Quantity Increase / Decrease upon cart add](/forum/35-orders-management/875908-quantity-increase-decrease-upon-cart-add#195999 "-- HikaShop version -- : 2.4.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.3.13  How can I deduct from the product quantity immediately when any use add the items to the cart and then add the quantity back in case of empty the cart or cart expiry?")*

Hi,

This will require custom code, you can potentially create a plugin based on the function "onBeforeCartUpdate()" for that.
In this function, you will have the product ids of the added products and their quantity, so in this function you can change the product stock and save it thanks to the hikashop product class and the save() function.

Then, use the function "onBeforeOrderCreate()" in the same plugin to cancel the HikaShop product stock update, else for one product bought, the stock will be decremented twice.

It require good PHP knowledges, here is the documentation:
[ www.hikashop.com/support/support/documen...r-documentation.html](http://www.hikashop.com/support/support/documentation/62-hikashop-developer-documentation.html)

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50Lzg3NTkwOC1xdWFudGl0eS1pbmNyZWFzZS1kZWNyZWFzZS11cG9uLWNhcnQtYWRkP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[daylily](/forum/user/36343-daylily "View daylily's Profile")**
- [![daylily's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/36343-daylily "View daylily's Profile")
- [ Offline](/forum/user/36343-daylily)

Less More

- Posts: 16
- Thank you received: 1
-
-

11 years 6 months ago [\#196839](#196839) by [daylily](/forum/user/36343-daylily "View daylily's Profile")  Replied by *[daylily](/forum/user/36343-daylily "View daylily's Profile")* on topic *[Quantity Increase / Decrease upon cart add](/forum/35-orders-management/875908-quantity-increase-decrease-upon-cart-add#196839 "-- HikaShop version -- : 2.4.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.3.13  How can I deduct from the product quantity immediately when any use add the items to the cart and then add the quantity back in case of empty the cart or cart expiry?")*

This behavior (not removing the item from stock) seems very strange to me. So strange that I am looking for confirmation that it is correct. Is the model that the item is not removed from stock until after checkout? That would make it possible for two different people to have the same item in their cart if there was only one. What happens at checkout in that scenario? Does the second buyer suddenly see that it is out of stock when they are checking out?

The following user(s) said Thank You: [bassimbg](/forum/user/36592-bassimbg "View bassimbg's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50Lzg3NTkwOC1xdWFudGl0eS1pbmNyZWFzZS1kZWNyZWFzZS11cG9uLWNhcnQtYWRkP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86290
- Thank you received: 14268
-
-

11 years 6 months ago [\#196870](#196870) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Quantity Increase / Decrease upon cart add](/forum/35-orders-management/875908-quantity-increase-decrease-upon-cart-add#196870 "-- HikaShop version -- : 2.4.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.3.13  How can I deduct from the product quantity immediately when any use add the items to the cart and then add the quantity back in case of empty the cart or cart expiry?")*

Hi,

Two people can have the same item in their cart.
However, only the one who will click on the "finish" button first at the end of the checkout, before the payment will have the product. It's at that point that the quantity is deduced from the stock.
The other customer, when displaying a page with his cart, or trying to finish the checkout will get the product automatically removed from his cart along with an error message explaining the situation.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50Lzg3NTkwOC1xdWFudGl0eS1pbmNyZWFzZS1kZWNyZWFzZS11cG9uLWNhcnQtYWRkP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[daylily](/forum/user/36343-daylily "View daylily's Profile")**
- [![daylily's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/36343-daylily "View daylily's Profile")
- [ Offline](/forum/user/36343-daylily)

Less More

- Posts: 16
- Thank you received: 1
-
-

11 years 6 months ago [\#197105](#197105) by [daylily](/forum/user/36343-daylily "View daylily's Profile")  Replied by *[daylily](/forum/user/36343-daylily "View daylily's Profile")* on topic *[Quantity Increase / Decrease upon cart add](/forum/35-orders-management/875908-quantity-increase-decrease-upon-cart-add#197105 "-- HikaShop version -- : 2.4.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.3.13  How can I deduct from the product quantity immediately when any use add the items to the cart and then add the quantity back in case of empty the cart or cart expiry?")*

What happens when the item has multiple variants? Say that I sell t-shirts that come in multiple colors and sizes. I setup characteristics for Color and for Size. How do I setup the quantities for each characteristic? I assume that it is not possible to track small-yellow vs small-red or large-yellow, correct? If I sell a shirt that is size: small and color: yellow, will the system try to subtract from both the yellow variant and the small variant? Or will it not subtract at all, or only subtract from one or the other?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50Lzg3NTkwOC1xdWFudGl0eS1pbmNyZWFzZS1kZWNyZWFzZS11cG9uLWNhcnQtYWRkP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86290
- Thank you received: 14268
-
-

11 years 6 months ago [\#197107](#197107) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Quantity Increase / Decrease upon cart add](/forum/35-orders-management/875908-quantity-increase-decrease-upon-cart-add#197107 "-- HikaShop version -- : 2.4.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.3.13  How can I deduct from the product quantity immediately when any use add the items to the cart and then add the quantity back in case of empty the cart or cart expiry?")*

Both modes are actually possible.
If you enter the stock of all the variants of the product in the product's quantity field, when someone buys one of the variants, the quantity of the main product will be deduced and if it reaches 0, the users with the same or other variants of that product will have their variant removed from their cart.
If you enter the stock of each variant in each variant's quantity field (you can do that by editing each variant via the "manage variants" button of the characteristics area of your product), then each variant will have its own stock. So when someone purchase one variant, the stock of that variant will be decreased but not the stock of the other variants.
Finally, you can also mix both systems and enter the stock in each variant and the total stock in the main product. and the main product quantity will only be updated by HikaShop as a reference for you but won't be taken into account when you purchase a variant as the stock of the variant itself will prevail.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50Lzg3NTkwOC1xdWFudGl0eS1pbmNyZWFzZS1kZWNyZWFzZS11cG9uLWNhcnQtYWRkP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[daylily](/forum/user/36343-daylily "View daylily's Profile")**
- [![daylily's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/36343-daylily "View daylily's Profile")
- [ Offline](/forum/user/36343-daylily)

Less More

- Posts: 16
- Thank you received: 1
-
-

11 years 6 months ago [\#197245](#197245) by [daylily](/forum/user/36343-daylily "View daylily's Profile")  Replied by *[daylily](/forum/user/36343-daylily "View daylily's Profile")* on topic *[Quantity Increase / Decrease upon cart add](/forum/35-orders-management/875908-quantity-increase-decrease-upon-cart-add#197245 "-- HikaShop version -- : 2.4.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.3.13  How can I deduct from the product quantity immediately when any use add the items to the cart and then add the quantity back in case of empty the cart or cart expiry?")*

So I'm writing a plugin to adjust the inventory level when an item is added to the cart . As you suggested in the first response of this thread, I am using the onBeforeCartUpdate() function. I have most everything worked out, with one exception.When an item is deleted from the cart, I need to add it back into stock. Items can be deleted by changing the quantity or deleting the entire line. But in the onBeforeCartUpdate() function, I don't see any way to know what the previous quantity in the cart was. In other words if someone had five(5) of "item A" in their cart and then they edited it to three(3), the only number that I can access in onBeforeCartUpdate() is three(3). Since I don't know how many were in the cart previously, I can't know how many to return to stock. Any Ideas?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50Lzg3NTkwOC1xdWFudGl0eS1pbmNyZWFzZS1kZWNyZWFzZS11cG9uLWNhcnQtYWRkP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Jerome](/forum/user/80-jerome "View Jerome's Profile")**
- [![Jerome's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar80.png)](/forum/user/80-jerome "View Jerome's Profile")
- [ Offline](/forum/user/80-jerome)
- HikaShop core developer

Less More

- Posts: 26394
- Thank you received: 4078
-
- [](http://obsi.dev)
-

11 years 6 months ago [\#197267](#197267) by [Jerome](/forum/user/80-jerome "View Jerome's Profile")  Replied by *[Jerome](/forum/user/80-jerome "View Jerome's Profile")* on topic *[Quantity Increase / Decrease upon cart add](/forum/35-orders-management/875908-quantity-increase-decrease-upon-cart-add#197267 "-- HikaShop version -- : 2.4.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.3.13  How can I deduct from the product quantity immediately when any use add the items to the cart and then add the quantity back in case of empty the cart or cart expiry?")*

Hi,

The trigger is before the cart modification and in the parameters, you have the current cart.
So you can access to the previous value of the product in the cart to know the value that you have to add or remove in the database.
And in all cases you have to do that, because when you change the quantity from 3 to 4 ; you have to change the value in the database by 1 ; not by 4.

Regards,

---

Jerome - Obsidev.com
HikaMarket &amp; HikaSerial developer / HikaShop core dev team.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50Lzg3NTkwOC1xdWFudGl0eS1pbmNyZWFzZS1kZWNyZWFzZS11cG9uLWNhcnQtYWRkP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[bassimbg](/forum/user/36592-bassimbg "View bassimbg's Profile")**
- [![bassimbg's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/36592-bassimbg "View bassimbg's Profile") Topic Author
- [ Offline](/forum/user/36592-bassimbg)

Less More

- Posts: 11
- Thank you received: 0
-
-

11 years 5 months ago -  11 years 5 months ago [\#201841](#201841) by [bassimbg](/forum/user/36592-bassimbg "View bassimbg's Profile")  Replied by *[bassimbg](/forum/user/36592-bassimbg "View bassimbg's Profile")* on topic *[Quantity Increase / Decrease upon cart add](/forum/35-orders-management/875908-quantity-increase-decrease-upon-cart-add#201841 "-- HikaShop version -- : 2.4.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.3.13  How can I deduct from the product quantity immediately when any use add the items to the cart and then add the quantity back in case of empty the cart or cart expiry?")*

Hi, I may buy this plugin if you already did it.
I want to update the quantity on when the use just add the product to cart and keep it for certain time, like 5 minutes before releasing it back to stock.

Thank you.

Last edit: 11 years 5 months ago by [bassimbg](/forum/user/36592-bassimbg "View bassimbg's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50Lzg3NTkwOC1xdWFudGl0eS1pbmNyZWFzZS1kZWNyZWFzZS11cG9uLWNhcnQtYWRkP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[tataye](/forum/user/871-tataye "View tataye's Profile")**
- [![tataye's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/871-tataye "View tataye's Profile")
- [ Offline](/forum/user/871-tataye)

Less More

- Posts: 94
- Thank you received: 3
-
-

9 years 3 weeks ago [\#279710](#279710) by [tataye](/forum/user/871-tataye "View tataye's Profile")  Replied by *[tataye](/forum/user/871-tataye "View tataye's Profile")* on topic *[Quantity Increase / Decrease upon cart add](/forum/35-orders-management/875908-quantity-increase-decrease-upon-cart-add#279710 "-- HikaShop version -- : 2.4.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.3.13  How can I deduct from the product quantity immediately when any use add the items to the cart and then add the quantity back in case of empty the cart or cart expiry?")*

did Bssimbg create the plugin or is this feature available now ?
if not it is a pity because othes market extensions do it

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50Lzg3NTkwOC1xdWFudGl0eS1pbmNyZWFzZS1kZWNyZWFzZS11cG9uLWNhcnQtYWRkP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[bassimbg](/forum/user/36592-bassimbg "View bassimbg's Profile")**
- [![bassimbg's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/36592-bassimbg "View bassimbg's Profile") Topic Author
- [ Offline](/forum/user/36592-bassimbg)

Less More

- Posts: 11
- Thank you received: 0
-
-

9 years 3 weeks ago [\#279740](#279740) by [bassimbg](/forum/user/36592-bassimbg "View bassimbg's Profile")  Replied by *[bassimbg](/forum/user/36592-bassimbg "View bassimbg's Profile")* on topic *[Quantity Increase / Decrease upon cart add](/forum/35-orders-management/875908-quantity-increase-decrease-upon-cart-add#279740 "-- HikaShop version -- : 2.4.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.3.13  How can I deduct from the product quantity immediately when any use add the items to the cart and then add the quantity back in case of empty the cart or cart expiry?")*

No dear, I didn't develop it and since long time I am not following on new features of Hikashop, so I don't know if they implemented it.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50Lzg3NTkwOC1xdWFudGl0eS1pbmNyZWFzZS1kZWNyZWFzZS11cG9uLWNhcnQtYWRkP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop- Install &amp; Update- Product &amp; Category Display- Content Creation- Sales and Orders- - Orders management- - Reports &amp; Statistics- Customers- Checkout- Payment Methods- Shipping Methods- Import &amp; Export (CSV, XLS…)- Specific Features- - Affilation- - Taxes- - Wishlist- - Vote- - Carousel &amp; Slider- - Mass Actions- - Filters &amp; Search- - Discount &amp; Coupon- - Feature Request- Integrations- Showcase- General Talk about HikaShop- Development- - HikaShop 3.0 Beta- Translation- Commercial Jobs HikaShop Components- HikaMarket- - Market: Feature requests- - Market: How to?- - Market: Bug Report- HikaSerial- - General talk about HikaSerial- - Serial: Bug Report- - Serial: How to?- - Support en Français de HikaSerial (French Support)- - HikaSubscription- HikaAuction- - Auction: Feature requests- - Auction: How to?- - Auction: Bug report Hikashop around the world- Support en Français (French Support)- Russian- - FAQ. Курс выживания с Hikashop. Частые вопросы и о- - Расширения Hikashop- - Наши сайты на Hikashop- 日本語版サポート(Japanese Support)- Thai- German Archives- Bug Report- How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.395 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)

[](#top)
