<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Christopher Shennan's Blog &#187; Magento</title>
	<atom:link href="http://www.chrisshennan.com/category/magento/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chrisshennan.com</link>
	<description>A day in the life of...</description>
	<lastBuildDate>Thu, 09 Sep 2010 19:33:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Magento API &#8211; Update Product Stock Levels</title>
		<link>http://www.chrisshennan.com/2009/11/15/magento-api-update-product-stock-levels/</link>
		<comments>http://www.chrisshennan.com/2009/11/15/magento-api-update-product-stock-levels/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 18:23:00 +0000</pubDate>
		<dc:creator>Christopher Shennan</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[magento api]]></category>
		<category><![CDATA[magento stock levels]]></category>
		<category><![CDATA[product.update]]></category>
		<category><![CDATA[product_stock.update]]></category>

		<guid isPermaLink="false">http://www.chrisshennan.com/?p=162</guid>
		<description><![CDATA[Another day&#8230; 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 [...]]]></description>
			<content:encoded><![CDATA[<p>Another day&#8230; another magento problem!</p>
<p>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.</p>
<p>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:-</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$proxy</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sessionId</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'product.update'</span><span style="color: #339933;">,</span>
	<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'PRD0001'</span><span style="color: #339933;">,</span> 
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'price'</span><span style="color: #339933;">=&gt;</span><span style="color:#800080;">12.50</span><span style="color: #339933;">,</span> 
			<span style="color: #0000ff;">'qty'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">12</span><span style="color: #339933;">,</span> 
			<span style="color: #0000ff;">'is_in_stock'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> 
			<span style="color: #0000ff;">'discontinued'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">0</span>
		<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>However, the update of the is_in_stock and qty fields is not done against the product (via <a href="http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_product" target="_blank">product.update</a>) but against the product inventory (via <a href="http://www.magentocommerce.com/wiki/doc/webservices-api/api/cataloginventory_stock_item" target="_blank">product_stock.update</a>) so this code had to be updated to the following:-<br />
<span id="more-162"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// UPDATE THE PRODUCT</span>
<span style="color: #000088;">$proxy</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sessionId</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'product.update'</span><span style="color: #339933;">,</span>
	<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'PRD0001'</span><span style="color: #339933;">,</span> 
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'price'</span><span style="color: #339933;">=&gt;</span><span style="color:#800080;">12.50</span><span style="color: #339933;">,</span> 
			<span style="color: #0000ff;">'discontinued'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">0</span>
		<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// UPDATE THE PRODUCT INVENTORY</span>
<span style="color: #000088;">$proxy</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sessionId</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'product_stock.update'</span><span style="color: #339933;">,</span>
	<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'PRD0001'</span><span style="color: #339933;">,</span> 
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'qty'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">12</span><span style="color: #339933;">,</span> 
			<span style="color: #0000ff;">'is_in_stock'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> 
		<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>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.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisshennan.com/2009/11/15/magento-api-update-product-stock-levels/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
