0

Where does magento actually subtract from product stock when purchase is made? (v. 1.9)

After many unreliable attempts to come up with a solution, I think the best option (reluctantly) will be to modify the code where Magento updates the stock qty when a purchase is made.

0

What exactly are you trying to do? It sounds like you want to do something specific, but you are asking too direct of a question. What is your ultimate goal? What have you tried already?

I assume you are using Magento 1.x...

Stock is one of those areas that is affected by caching, and has a lot of side effects. Trying to go around the Magento design can cause a lot of unexpected problems INCLUDING modifying the stock in the database (cataloginventory_stock_item table).

The most straight forward method I have found to modify stock or stock related attributes is via the API:

http://devdocs.magento.com/guides/m1x/api/soap/catalogInventory/cataloginventory_stock_item.update.html

You don't need to use the API. Use the code that is written there as an example on how to implement your functionality in your extension.

NOTE: the stock API is still expensive (average 1 second per product) because it requires a full product save in order to trigger all of the indexes/caches. There is an optimization possible if you only want to adjust the inventory amount but not its stock status (is_salable). For example, if you need to update the inventory from 1500 to 1395, and it doesn't affect the ability to sell that item... you can optimize the code to update the Catalog Stock Item data directly.

0

Magento subtracted qty after checkout_submit_all_after event fire.

Open app/code/core/Mage/CatalogInventory/Model/Observer.php

Check following method

/**
 * Subtract qtys of quote item products after multishipping checkout
 *
 * @param Varien_Event_Observer $observer
 * @return Mage_CatalogInventory_Model_Observer
 */
public function checkoutAllSubmitAfter(Varien_Event_Observer $observer)
{
    $quote = $observer->getEvent()->getQuote();
    if (!$quote->getInventoryProcessed()) {
        $this->subtractQuoteInventory($observer);
        $this->reindexQuoteInventory($observer);
    }
    return $this;
}

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.