1

I am having trouble in finding ways of making other products quantity decrease, when a person buys a different item. This is because the item they buy will use quantities of other items listed.

3
  • If you are using for example a configurable product that will happen immediately – mbalparda Sep 2 '14 at 22:24
  • 1
    please elaborate your question by putting an example or demo in your question. This way you can improve your question and thus will get help from community – Rajeev K Tomy Sep 3 '14 at 3:20
  • Also have a look at bundle or grouped products. – Simon Sep 3 '14 at 6:23
1

You can use the event checkout_submit_all_after. That is dispatched when the order is placed.
Check all the products that are bought and decrease the qty for matching products.

public function checkoutSubmitAllAfter($observer) {
    $items = $observer->getQuote()->getAllItems();
    foreach ($items as $item) {
        $product = $item->getProduct();  
        $matching = ...insert your logic here for finding the products that need qty decresing...
        foreach ($matching as $match) {
            $stockItem = $match->getStockItem(); 
            $stockItem->setQty($stockItem()->getQty() - $item->getQty());
            $stockItem->save();
        }
    }
}

I know that using save in a loop is not the best idea. But it's better than nothing. You can make it work first and work on performance after that.

0

Checkout the methods in this observer: Mage_CatalogInventory_Model_Observer

You should be able to use some of the events that this observer hooks into to accomplish what you want to with updating quantity of other products.

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.