Article

Magento API - Update Product Stock Levels

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.

me.jpeg

I am a web developer specialising in web driven applications using PHP, MySQL, Symfony and Zend and I am currently working for the The Drum in Glasgow, 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!

Want more like this?

Keep up-to-date with latest news from Inside the Agency using any of the following services

Recent articles

The Iron Triangle - How does motivation emphasis create an agency environment?

I remember when I first heard about the Iron Triangle. It sounded sinister, Evil Empire like, and not really something I could embrace in my fluffy idealistic agency brain. Just to be clear in this article I am talking about the Project Management version, not the US political system version… which is sinister and is just like the Evil Empire.

ITA-motivation-illustration-20151120.jpg

Back then I was speaking to my then boss, a man who I credit with opening my eyes to a great deal to how an agency works and, more importantly, how it should work. He was explaining in typically simple eloquence, how he wanted us to set expectation with clients. 

Read more

The Adblock Wars - Stop blaming the victim!

Much to the dismay of the advertising and publishing industry, Adblock is indeed here to stay. But, what is the industry doing about it? For the most part, pointing the finger and accusing the end user of underhanded tactics. To that I say: Pot, meet Kettle.

ad-blocking-article

Over the last few months I have noticed an increasing number of articles surround Adblock usage, most of which are coming from advertisers and publishers perspective.  Within these articles the underlying theme is that Adblock is evil and people using it are:

Read more

Content is a very lonely king (and he needs some pants)

I was once told that If you put a £5 note for sale in the window, you can sell it for £5 or maybe even more, but if you put it way at the back of the shop, hidden away and try to sell it for 50p, it still won't sell.

king_of_no_pants_by_pixiepirate.jpg

Lesson:  No matter how good the product is, if it's not where your customers can see it then it's worthless. 

Read more

Advertisement

Digital Ocean

Chris's Reading List

JAXenter

Self-promotion is a skill, but is that the skill you're looking for? - JAXenter

Do you want to hire somebody that's good at self-promotion, or are you looking for a certain skill-set? Perhaps you need to shape your job spec differently. Read more

TechCrunch

TechCrunch

When Crowdfunding Fails The Backers Are Left With No Way Out

A few years ago an enterprising programmer dug through Kickstarter's data to figure out how many failed projects there really were. Thanks to a trick in the.. Read more

Business Insider

A programmer wrote scripts to secretly automate a lot of his job — and email his wife and make a latte

There's a hilarious project that's gone viral on GitHub that consists of a bunch of software scripts that automate all sorts of crazy things. Read more

The Bests

The Best-Looking Video Game Consoles Of All Time

You silly fanboys. All these years arguing over things you thought were important, like specs, and libraries, and exclusives, and controllers, wasted. Not once have you considered the most crucial thing about a video game console: how good it looks. Read more

The Founder Institute

The Founder Institute

FI.co: How to Build an MVP as a Non-Technical Founder

The Founder Institute hosts webinars every month so that we can help entrepreneurs on any stage succeed. These webinars discuss a wide range of topics, bestowing global entrepreneurs with invaluabl... Read more

TechCrunch

TechCrunch

Google’s New “About Me” Page Lets You Control What Personal Info Others Can See

Worried that Google has too much of your personal data, thanks to the way it has pried into your life over the years as you steadily adopted more of its.. Read more