cancel
Showing results for 
Search instead for 
Did you mean: 

Magento _afterSave function for stock item

Magento _afterSave function for stock item

Hi All,

 

I am trying to change "Stock Availability" tab inside "Inventory" tab for configurable product by calling Magento Rest API with standard url.

 

I see that while calling PUT option to change "Stock Availability", it realized that it calls $stock-save() which in-turn calls _afterSave().

 

When I see inside this _afterSave function, I see that if I run API for simple product, it run through but if it is configurable product, it struck at parent::_afterSave();.

 

Just for test purpose, when I commented "parent::_afterSave();" line, it worked beautifully.

 

Can someone please advise on what am I missing because the same function must be called when we manually save product by going to Magento Dashboard -> Catalog -> Products

 

[EDIT] : I thought to put code available inside _afterSave():

 

protected function _afterSave()
{

parent::_afterSave();

/** @var $indexer Mage_Index_Model_Indexer */
$indexer = Mage::getSingleton('index/indexer');
if ($this->_processIndexEvents) {
$indexer->processEntityAction($this, self::ENTITY, Mage_Index_Model_Event::TYPE_SAVE);
} else {
$indexer->logEvent($this, self::ENTITY, Mage_Index_Model_Event::TYPE_SAVE);
}
return $this;
}

 

Your help is really appreciated.

Ashish

4 REPLIES 4

Re: Magento _afterSave function for stock item

Hi @sales_multimate,

I want to clear first thing that, Configurable product haven't there inventory. 

Configurable product always picks simple product quantity. 

So it may be your API is not working and it is working fine for simple product. 

Let me know if you have any question.  

Re: Magento _afterSave function for stock item

Hi @Vimal Kumar

 

Thanks for your reply.

 

I am only trying to change "Stock Availability" to In Stock or Out of Stock for configurable product. Sometimes it happens that configurable products are Out of Stock but atleast any one associated product is In Stock / Enable. In that case I will make configurable product to In Stock.

 

I hope it is clear now.

Re: Magento _afterSave function for stock item

Check once below magento doc.. .

https://devdocs.magento.com/guides/m1x/api/rest/Resources/inventory.html#RESTAPI-Resource-StockItems...

Yes, you are right. May be it is creating problem with configurable product. When we save from admin then it updates stock after checking all simple product inventory. 

Re: Magento _afterSave function for stock item

Hi @Vimal Kumar 

 

I was earlier using API for products/:id. I just now used stockitems/:id as well.

 

Still no luck if do not comment above shared line. What does that line (parent::_afterSave()Smiley Wink do actually? May be I can go more deep and check if I am missing anything!

 

Ashish