Christopher Shennan's Blog

A day in the life of…

Another day… another magento problem!

I was asked to look into a problem with an automated stock level update script not updating the stock levels.  This update script was using the Magento API and on the face of things everything looked ok as the script ran without any errors, the product prices got updated but the stock levels never changed.

After a bit of investigating I found the problem was caused by an incorrect usage of the Magento API and the original update statement was similar to:-

$proxy->call($sessionId, 'product.update',
	array('PRD0001',
		array(
			'price'=>12.50,
			'qty'=>12,
			'is_in_stock'=>1,
			'discontinued'=>0
		)
	)
);

However, the update of the is_in_stock and qty fields is not done against the product (via product.update) but against the product inventory (via product_stock.update) so this code had to be updated to the following:-

// UPDATE THE PRODUCT
$proxy->call($sessionId, 'product.update',
	array('PRD0001',
		array(
			'price'=>12.50,
			'discontinued'=>0
		)
	)
);

// UPDATE THE PRODUCT INVENTORY
$proxy->call($sessionId, 'product_stock.update',
	array('PRD0001',
		array(
			'qty'=>12,
			'is_in_stock'=>1,
		)
	)
);

After the stock level update script had been adapted to this 2 step approach everything seemed to run ok and the stock level figures were then being updated with the appropriate quantities.

About Christopher Shennan

I am a web developer specialising in web driven applications using PHP, MySQL, Symfony and Zend and I am currently working for Line Digital in Edinburgh, Scotland.

Most days I can be found frantically coding away with EuroDance in my ears and consuming what I hope to be a never ending supply of coffee... happy days!

Connect with me via Twitter, Google+ or LinkedIn

  • #1 | Written by Lee about 2 years ago.

    Thats a useful note. We would like to provide a script to *add* product stocks to the inventory not overwrite. The customer receives weekly deliveries but the standard Mage overwrite routine is not appropriate.

    Have you come across this requirement before?

No trackbacks yet.

Leave a Comment

Subscribe to comments

CommentLuv badge