0

When the event sales_order_place_after is triggered the new quantity value is not inserted, what is the problem? How to update quantity or other attributes when this event is triggered? I need to update attribute after a user place an order. The config.xml file is OK. I already checked if the event is triggered.

    public function save_product_frontend($observer = null) { 
       $event = $observer->getEvent();
       $order = $event->getOrder();
       $items = $order->getAllItems();
       foreach ($items as $item) {
          $product = Mage::getModel("catalog/product")->load( $item->getProductId() );
          $stockitem = Mage::getModel('cataloginventory/stock_item')->loadByProduct( $product );
          $stockitem->setQty( 100 );
          $stockitem->save();
      }
  }
0

You can save quantity something like this.

$stockitem->setManageStock(1)
              ->setUseConfigManageStock(1)
              ->setQty(100)
              ->setIsInStock(1);
         Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
         $stockitem->save();

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.