1

I am having a right ball game with a issue. I have written a AJAX cart system for a wholesale website we are developing. There is one long list of products and you can just enter your quantity in each of the boxes, click add to cart and it will run through adding these all to your cart. HOWEVER, I am having major issues. If a product has 10 in stock and I add 10 to my cart I want it to display 0 to the rest of the world because otherwise I get an error as the "live" stock level is not 10, it is 0 because the user has technically reserved the item according to Magento.

Does anyone have any idea how I can pull more of a live stock level rather than this which shows the inventory:

(int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_item)->getQty()

Thank you in advance.

1

You can create you custom module that observes the event add_to_cart_after.
In your observer you should decrease the qty of the product added to the cart.
I think you can take a look at this Mage_CatalogInventory_Model_Observer::subtractQuoteInventory() to see how the qty is decreased when saving an order

Originally this is used on the event sales_model_service_quote_submit_before. So when the order is placed.
In your case this shouldn't happen so you need to disable this.

You can try to create a module and in it's config.xml just add this inside the <global> tag.

<events>
   <sales_model_service_quote_submit_before>
       <observers>
           <inventory>
               <type>disabled</type> <!-- this will disable the original event -->
           <inventory>
       </observers>
   </sales_model_service_quote_submit_before>
   <add_to_cart_after>
       <observers>
           <inventory>
               <class>[module]/observer</class>
               <method>subtractQuoteInventory</method> <!-- you need to implement this method to make it work with only a product -->
           <inventory>
       </observers>
   </add_to_cart_after>
</events>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.