Quantity Increase / Decrease upon cart add

  • Posts: 11
  • Thank you received: 0
9 years 8 months ago #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?

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
9 years 8 months ago #195999

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

Please Log in or Create an account to join the conversation.

  • Posts: 16
  • Thank you received: 1
9 years 7 months ago #196839

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

Please Log in or Create an account to join the conversation.

  • Posts: 82906
  • Thank you received: 13378
  • MODERATOR
9 years 7 months ago #196870

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 or Create an account to join the conversation.

  • Posts: 16
  • Thank you received: 1
9 years 7 months ago #197105

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 or Create an account to join the conversation.

  • Posts: 82906
  • Thank you received: 13378
  • MODERATOR
9 years 7 months ago #197107

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 or Create an account to join the conversation.

  • Posts: 16
  • Thank you received: 1
9 years 7 months ago #197245

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 or Create an account to join the conversation.

  • Posts: 26159
  • Thank you received: 4028
  • MODERATOR
9 years 7 months ago #197267

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 & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 11
  • Thank you received: 0
9 years 6 months ago #201841

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: 9 years 6 months ago by bassimbg.

Please Log in or Create an account to join the conversation.

  • Posts: 82
  • Thank you received: 2
7 years 1 month ago #279710

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 or Create an account to join the conversation.

  • Posts: 11
  • Thank you received: 0
7 years 1 month ago #279740

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 or Create an account to join the conversation.

Time to create page: 0.114 seconds
Powered by Kunena Forum