News:

Looking for documentation? Take a look on our wiki

Main Menu

Update stock level immediately after 'add to cart' pressed

Started by hayleyv, August 21, 2012, 11:55:20 AM

Previous topic - Next topic

hayleyv

I have unusual requirements for VM and understand how the stock control works. 

- How I can set the stock to '0' (or even better the booked, ordered products to 0) as soon as the ADD TO CART IS PRESSED.
- If the product is then REMOVED from the cart then I want the stock to go back up.

I have the SQL for it to make the change, but can't find where I can add it as a hack.  I am unsure what page/functions get called when add to cart is pressed.

Thanks in advance

ivus

Hi hayleyv,

Sounds like such an odd request, but each to their own.

/components/com_virtuemart/controller/cart.php

public function add() {}

it's nicely commented too

Quote
   /**
    * Add the product to the cart
    *
    * @author RolandD
    * @author Max Milbers
    * @access public
    */

Nice work Milbo ;D

John2400

I think you will find that the issue or danger of over ordering is solved in 2.0.9 b.

If you have a product set say at 1 and it is in the cart - then the system will not allow you to add another and infact it tells you this.

Also as soon as the order is confirmed then the product will - place the word notify in front of the product.

So you cannot get caught with over ordering - without the hack.

I tested this a few times on the newer versions - very neat,   so - use Ivus's suggestion but you might not need it.

* then later in the back end when you update to shipped the stock will fix itself. -

hayleyv

Thanks everyone.  My requirements are unusual, because I am writing a theatre seat reservation template.  Each seat is a product and the show is a category.  The template lays out the seating plan which is a VERY simply grid of product links and when someone clicks on a product (seat) they are taken to the product page to 'add to cart'.  Once added that product MUST have it's quantity (ideally 'booked, ordered products') field set so that the product (thus seat) can be shown a different colour and unavailable for booking by someone else.  This temporarily holds the product out of stock which is a perfect solution.  Upon checkout and the order being confirmed, the stock level should then go to 0 claiming the product (thus seat) officially sold!

Thanks


bytelord

Hello,
i am thinking you need a reservation/booking engine ... not a cart engine...
But you can do it with VM also i suppose, don't forget to show us your results when is finished.
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

hayleyv

Yes, I have checked most of the reservation components, but belive it or not, none allow to book specific seats (and show them as taken etc).  Virtuemart products templating system allows a bulk CSV upload of all the seats in one go and creates an instant seating plan which is perfect!  The only thing stopping it from working is the products stock being updated instantly.  I still can't do it ;-(  Tried the new version as discussed in this thread and it does exactly the same (ie only updates when checkout is complete).

bytelord

Yes, i see your points.
You could use the public functions getStockIndicator and updateStockInDB inside the product model from your cart tmpl & module tmpl by calling the product model [ $productModel = VmModel::getModel('product') ].

But if you do that, then i think you will not be able to checkout (on checkout there is also stock control i think, because if is you have successful checkout the stock must updated), except if you create a cookie at that time and when you checkout you will update the stock again.

Another thing you could is to create a plugin that will handle a second table on your db with the stock information of the products and you update each time the add-to-cart button pressed and you will use your own values for product_in_stock in your custom template...

Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

ivus

hayleyv,

I'm not sure how much development knowledge you have (please vote in my poll too), but I was thinking about your problem when bytelord beat me to it.... well done bytelord.

QuoteAnother thing you could is to create a plugin that will handle a second table on your db with the stock information of the products and you update each time the add-to-cart button pressed and you will use your own values for product_in_stock in your custom template...

So I came up with another solution.

You could create a plugin that would test if the locked_by value was set to either X:0. The #__virtuemart_products table contains 2 columns "locked_on (date)" and "locked_by (int)". When someone adds a seat to their order, you can simply update the locked_by field with that user_id, and locked_on field with the current time stamp. If anyone else adds the same seat and the lock_by is NOT 0, then they can't obviously add it. The locked_on field comes in to play in case the user didn't finish their order. You can test that 15 minutes (or however long you want to make it locked for) has lapsed, then it becomes re-orderable again. This solution may work better as it does not take into account stock count.

From what I can see, neither one of those 2 fields are used in the general operations of the site.

bytelord

I have to agree with ivus suggested solution, looks better :). A small plugin could handle that easy.

The only thing i will change on ivus suggestion is instead of user_id only should also save the IP/hostname and  session_id on a different new table that controlled by own plugin because user_id cannot handle guests that haven't registered yet and have add the product in the cart.
Then easy you will use locked_by that will chain (relation) with the plugin database table (an integer to an integer - AUTO_INCREMENT [id]).
You can also use locked_on as ivus suggest and after a period of time to "release" the product [but that needs cron services if is the only checked], but you can check the session_id before add_to_cart for a product released. if the session expires, release the product and also you can place 15 minutes limit for the expiration of the session, so may be you will use only locked_by.

*I think locked_by i have seen it somewhere and i am not sure if is not used - may be is a upcoming multivendor field...
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

John2400

hayleyv/bytelord/ivus,


I love the concert ticket selling idea, I know as stated earlier that joomla has reservation pluging and modules for reserving places. But I think this needs to become bigger - third party - extension - selling one off for 1000s should be easier.

We have all see ticketek ( the entertainment company) - or similar in the world do the same thing.

I won't expand on ideas - but I can think of many ideas around this concept. If its ok With everyone here may I push a little in a few forums. Unless you send me a public or private post - I would like to see the end result online if possible too.

sorema

sorry, has this come to any solution? is there available a plugin to update stock as soon as add to cart is triggered? thank you!

wumen

Hi, we have developed a plugin that locks the product after is added for the first time, see:
http://forum.virtuemart.net/index.php?topic=115980.0

If you decrement the stock when the product is added to the cart the customer may not complete checkout because the stock is not sufficient!

Best,
WuMen
----------------
Check out our custom VM plugin: Locking
http://www.wumen.biz/software/virtuemart-plugin-locking-products/