<?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>b.wilhelm &#187; E-Commerce</title>
	<atom:link href="http://www.bwilhelm.com/category/e-commerce/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bwilhelm.com</link>
	<description>E-commerce, Internet Marketing, Design and Everything Else</description>
	<lastBuildDate>Tue, 30 Mar 2010 04:04:22 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Online CPG Sales Heat Up</title>
		<link>http://www.bwilhelm.com/2010/02/20/online-cpg-sales-heat-up/</link>
		<comments>http://www.bwilhelm.com/2010/02/20/online-cpg-sales-heat-up/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 21:33:39 +0000</pubDate>
		<dc:creator>Brian Wilhelm</dc:creator>
				<category><![CDATA[E-Commerce]]></category>
		<category><![CDATA[CPG]]></category>

		<guid isPermaLink="false">http://www.bwilhelm.com/?p=135</guid>
		<description><![CDATA[As retailers like Walmart begin to offer more and more lower priced consumer packaged goods (CPG) for sale online, all signs point to a race to be the leader in sales of everyday household items.
In the world I work in on a daily basis, the CPG world, one thing is for sure: The way consumers [...]]]></description>
			<content:encoded><![CDATA[<p>As retailers like Walmart begin to offer more and more lower priced consumer packaged goods (CPG) for sale online, all signs point to a race to be the leader in sales of everyday household items.<span id="more-135"></span></p>
<p>In the world I work in on a daily basis, the CPG world, one thing is for sure: The way consumers get their CPG items is changing. While a vast majority of consumers still shop for toilet paper and toothpaste at their local Supercenter, more and more shoppers are finding that with a little planning, they can get the same goods without leaving their homes, and various online startups and established retailers and CPG manufacturers want to make it possible.</p>
<p>In the past I have written about <a href="http://www.bwilhelm.com/2009/07/30/e-commerce-comes-to-facebook/">Alice.com</a>, a newer site dedicated to selling CPG directly to consumers. The whole idea behind Alice is to give CPG manufacturers a way to sell directly to consumers, and give consumers a convenient way to purchase those necessities on a regular schedule. Alice.com has enjoyed lots of positive press which has propelled interest, not to mention the company was founded by a <a href="http://flywheelblog.com/">couple of internet veterans</a> with a successful track record.</p>
<p>Big online retailers have begun to transform their own online offerings, typically filled with higher ticket items like electronics, and added lower priced CPG items. Recently, Amazon.com has increased it efforts to bring on board CPG manufacturers to round out their offerings online. Walmart.com, who until very recently didn&#8217;t sell lower priced CPG items online, has begun to sell multi-packs of lower priced items to make them more viable to online shoppers who aren&#8217;t looking to pay $6 shipping for an item priced $2.99. Now you can buy a pack of 3 items, for example, to make your cart-to-shipping-cost ratio more acceptable. Target is in the middle of a <a href="http://www.internetretailer.com/dailyNews.asp?id=33140">major online redesign</a>, so look for them to come at swinging on CPG items too when their new store comes online in 2011.</p>
<p>Sales and Marketing teams at major retailers aren&#8217;t the only one&#8217;s with their eye on the direct-to-consumer CPG sales.  As a not-so-sublte push back on retailers who are exerting more and more control over CPG companies, the largest CPG manufacturer in the world, Proctor &#038; Gamble, is dipping their big toe into the direct-to-consumer waters as well. Recently, <a href="http://online.wsj.com/article/SB10001424052748704363504575003333381682138.html">P&#038;G announced a &#8216;test&#8217;</a> where they would sell direct to consumers to try to learn about consumer buying habits for their brands, and all learnings would be shared with their retailers. Personally, I think what&#8217;s really happening is an experiment to see how viable selling direct to consumers is for them. If it proves successful, look for the &#8216;test&#8217; to continue. The question remains how much P&#038;G want to invest in their fulfillment operations to facilitate these sales, but most likely they will leave that to a third party to figure out if they ever get to the point where it becomes a viable sales channel for them.</p>
<p>Stay tuned as the race heats up to sell everyday items online. It could get interesting.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bwilhelm.com/2010/02/20/online-cpg-sales-heat-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get XML Data into Magento via the Magento API</title>
		<link>http://www.bwilhelm.com/2010/01/05/get-xml-data-into-magento-via-magento-api/</link>
		<comments>http://www.bwilhelm.com/2010/01/05/get-xml-data-into-magento-via-magento-api/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 19:13:59 +0000</pubDate>
		<dc:creator>Brian Wilhelm</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[E-Commerce]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.bwilhelm.com/?p=63</guid>
		<description><![CDATA[Recently I needed to write some code to get a dropshipper&#8217;s xml product data into Magento to update my products price, quantity available, and stock status. This is how I went about it.

NOTE: Before you get started, you need to make sure you have created an API user in Magento. Here is a good step-by-step [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I needed to write some code to get a dropshipper&#8217;s xml product data into Magento to update my products price, quantity available, and stock status. This is how I went about it.<br />
<span id="more-63"></span><br />
NOTE: Before you get started, you need to make sure you have created an API user in Magento. <a href="http://www.yireo.com/tutorials/magebridge/administration/119-step-by-step-create-a-magento-api-user">Here is a good step-by-step tutorial for doing that.</a></p>
<p>I decided that because of the potentially massive amount of data in my dropshipper&#8217;s XML feed file, that I should save the file to my server before attempting to process any data. I set up a cron job to use CURL to fetch the file. First I created a file called &#8216;importproducts.php&#8217; and added the following code:</p>
<p><strong>importproducts.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//my dropshipper's feed URL - replace with your dropshipper's feed</span>
<span style="color: #000088;">$myFeed</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://www.mydropshipperssite.com/feedurl.xml'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// specify the name of the file you want to save</span>
<span style="color: #000088;">$myFilename</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'product_feed.xml'</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$myFeed</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">//  Initialize the cURL session</span>
	<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$myFeed</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//Create a new file</span>
	<span style="color: #000088;">$fp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$myFilename</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// Save to file</span>
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_FILE<span style="color: #339933;">,</span> <span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// Execute the cURL session</span>
	<span style="color: #990000;">curl_exec</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//Close cURL session and file</span>
	<span style="color: #990000;">curl_close</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Feed Imported Successfully!&quot;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
		<span style="color: #666666; font-style: italic;">//check the file size - if its 0 then my dropshipper didn't provide any updates, so don't let me know</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">filesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$myFilename</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">// send email to me when executed</span>
			<span style="color: #000088;">$to</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;youremail@yourdomain.com&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$subject</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Feed Imported&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$body</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Hi,<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>The latest product data for YOURSITE has been downloaded on &quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$body</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'l jS \of F Y h:i:s A'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span> File Size: &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">filesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$myFilename</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; bytes&quot;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #339933;">,</span> <span style="color: #000088;">$subject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$body</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				  <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;p&gt;Message successfully sent!&lt;/p&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					 <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
				 <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;p&gt;Message delivery failed...&lt;/p&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Now that we have this script written, we need to process the data. Before that, let me show you an example of the xml data I am working with in the xml file we just saved with the import script. Here is sample xml:</p>
<p><strong>product_feed.xml</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;products<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;product</span> <span style="color: #000066;">sku</span>=<span style="color: #ff0000;">&quot;15569&quot;</span> <span style="color: #000066;">mfg_part_number</span>=<span style="color: #ff0000;">&quot;405970-1&quot;</span> <span style="color: #000066;">upc</span>=<span style="color: #ff0000;">&quot;082324027055&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;inventory</span> <span style="color: #000066;">quantity</span>=<span style="color: #ff0000;">&quot;13&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;price</span> <span style="color: #000066;">your_price</span>=<span style="color: #ff0000;">&quot;143.18&quot;</span> <span style="color: #000066;">list</span>=<span style="color: #ff0000;">&quot;159.99&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description</span> <span style="color: #000066;">short</span>=<span style="color: #ff0000;">&quot;A product description&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/product<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;product</span> <span style="color: #000066;">sku</span>=<span style="color: #ff0000;">&quot;16128&quot;</span> <span style="color: #000066;">mfg_part_number</span>=<span style="color: #ff0000;">&quot;406350-1&quot;</span> <span style="color: #000066;">upc</span>=<span style="color: #ff0000;">&quot;082324029301&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;inventory</span> <span style="color: #000066;">quantity</span>=<span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;price</span> <span style="color: #000066;">your_price</span>=<span style="color: #ff0000;">&quot;128.18&quot;</span> <span style="color: #000066;">list</span>=<span style="color: #ff0000;">&quot;149.99&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description</span> <span style="color: #000066;">short</span>=<span style="color: #ff0000;">&quot;Another product description&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/product<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/products<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Now we can talk about the next file, the one that takes the XML data and uses it to update products in Magento via the API. We&#8217;ll name this file &#8216;processupdates.php&#8217;.</p>
<p><strong>processupdates.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//include the Magento API file - replace with your server path to the file</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/some/path/to/public_html/app/Mage.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// ***** Configuration ******</span>
<span style="color: #000088;">$myDomain</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://www.yourdomain.com'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$myAPILogin</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'username'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$myAPIKey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'password'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//calculate the price markup - useful if you have a standard markup you apply</span>
<span style="color: #000088;">$myMarkUp</span> <span style="color: #339933;">=</span> <span style="color:#800080;">.30</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$defaultMarkup</span> <span style="color: #339933;">=</span> <span style="color:#800080;">.30</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// get my saved file name</span>
<span style="color: #000088;">$myFilename</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'product_feed.xml'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//load up local xml file for processing</span>
<span style="color: #000088;">$feed_xml</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$myFilename</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Begin SOAP Requests</span>
<span style="color: #000088;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SoapClient<span style="color: #009900;">&#40;</span><span style="color: #000088;">$myDomain</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/api/?wsdl'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$session</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">login</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$myAPILogin</span><span style="color: #339933;">,</span> <span style="color: #000088;">$myAPIKey</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$updatedProducts</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//some counters - counting loops this way lets me see and set where the count increments</span>
<span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//some filter date to pass to the API - add more to filter your results further - see Magento API docs</span>
<span style="color: #000088;">$filterData</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'type'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'simple'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//get all my database products into an array</span>
<span style="color: #000088;">$products</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$session</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'catalog_product.list'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filterData</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">//loop through my product array</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$products</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$product</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Starting product loop...&lt;br/&gt;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">//get my database product sku - for cleaner reference in the code</span>
<span style="color: #000088;">$mysku</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$product</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sku'</span><span style="color: #009900;">&#93;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//search directly in the product sku attribute in the xml for my sku</span>
<span style="color: #000088;">$res</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$feed_xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">xpath</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;//product[@sku='<span style="color: #006699; font-weight: bold;">$mysku</span>']&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// if we find one, lets process it</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$res</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//matched - make updates</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Matched: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$mysku</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//price updates</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$res</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">price</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'list'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$newprice</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$res</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">price</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'your_price'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$res</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">price</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'list'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$res</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">price</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'your_price'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #000088;">$myMarkUp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$newprice</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$res</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">price</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'your_price'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$res</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">price</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'your_price'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span><span style="color: #000088;">$defaultMarkup</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//build my array to pass to the magento API</span>
	<span style="color: #000088;">$fieldPriceData</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cost'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$res</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">price</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'your_price'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'price'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$newprice</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'upc'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$res</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">product</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'upc'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//update magento with price data</span>
	<span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$session</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'catalog_product.update'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$product</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sku'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$fieldPriceData</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;">//qty and stock updates</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$res</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">inventory</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'quantity'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$fieldQtyData</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: #000088;">$res</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">inventory</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'quantity'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">1</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: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;In Stock&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$fieldQtyData</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: #000088;">$res</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">inventory</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'quantity'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'is_in_stock'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Out of Stock&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//update magento with quantity and stock data</span>
	<span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$session</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: #000088;">$product</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sku'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$fieldQtyData</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;">//record the updated product for emailing later</span>
	<span style="color: #000088;">$updatedProducts</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;SKU: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$mysku</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; - &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$res</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">description</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'short'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Price: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$newprice</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Cost: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$res</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">price</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'your_price'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Qty: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$res</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">inventory</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'quantity'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//increment my counter</span>
	<span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;no match&lt;br/&gt;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// send mail to me</span>
<span style="color: #000088;">$to</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;you@yourdomain.com&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$subject</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Feed Processed&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$body</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Hi,<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>The latest data for &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$myDomain</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; has been processed on &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'l jS \of F Y h:i:s A'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$body</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Products Updated: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$x</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$updatedProducts</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #339933;">,</span> <span style="color: #000088;">$subject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$body</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;p&gt;Message successfully sent!&lt;/p&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	 <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;p&gt;Message delivery failed...&lt;/p&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Now all you need to do is set up the cron jobs to call your import file at one interval, and your process file at another interval. Note that this works for me because I have a limited number of database products. If you have thousands of products you might want to have your site updating products by category, for example. If anyone has any better ideas on how to do any of this, please let me know. I always like to learn new stuff!</p>
<p>Download Files: <a href="http://www.bwilhelm.com/downloads/Magento_API_XML_Import.zip" title="Downloaded 191 times">Magento API XML Import</a> - 15.82 KB - 191 Downloads<br />
<br/><br/></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bwilhelm.com/2010/01/05/get-xml-data-into-magento-via-magento-api/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>E-Commerce comes to Facebook; Alice.com opportunity?</title>
		<link>http://www.bwilhelm.com/2009/07/30/e-commerce-comes-to-facebook/</link>
		<comments>http://www.bwilhelm.com/2009/07/30/e-commerce-comes-to-facebook/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 03:37:19 +0000</pubDate>
		<dc:creator>Brian Wilhelm</dc:creator>
				<category><![CDATA[E-Commerce]]></category>
		<category><![CDATA[Alice.com]]></category>
		<category><![CDATA[facebook]]></category>

		<guid isPermaLink="false">http://www.bwilhelm.com/?p=19</guid>
		<description><![CDATA[If you have kept up with any of the tech blogs, you&#8217;ll probably know that Facebook has been working on its own payment system  that facebook app developers can build into their apps to essentially create a micro-economy within the facebook community. This facebook currency could be used for anything from sending e-cards to [...]]]></description>
			<content:encoded><![CDATA[<p>If you have kept up with any of the tech blogs, you&#8217;ll probably know that Facebook has been working on its own <a href="http://www.techcrunch.com/2009/05/29/facebook-revs-up-for-payment-platform-with-updated-terms/">payment system </a> that facebook app developers can build into their apps to essentially create a micro-economy within the facebook community. This facebook currency could be used for anything from sending e-cards to friends to buying weapons in mob wars. No one has really been able to bring the purchase of real world physical goods to facebook users, until now.<br />
<span id="more-19"></span><br />
Enter 1-800-Flowers. <a href="http://www.techcrunch.com/2009/07/29/1-800-flowerscom-sets-up-shop-inside-facebook/">TechCrunch</a> has reported that 1-800-Flowers has <A href="http://www.facebook.com/1800flowers?ref=search#/1800flowers?v=app_89569512162&#038;viewas=653317219&#038;ref=search">set up an e-commerce store</a> on Facebook. Apparently the store has full credit card processing and all. It appears that Facebook is truly becoming its own internet, complete with shopping. Soon users will have no reason to leave facebook if retailers start creating stores on Facebook. Will we soon be exchanging &#8216;internet&#8217; in our vocabulary for the word &#8216;Facebook&#8217;, like &#8216;Google&#8217; has begun to replace the word &#8217;search&#8217;?</p>
<p>I may be getting ahead of myself, but 1-800-Flowers has made a large step forward in world of online retail, and I suspect this will open a floodgate of other retailers setting up boutiques in the &#8216;Facebook Mall&#8217;. Lots of major retailers already have fan pages on Facebook, and I suspect a lot of online decision makers for these companies will be watching this play closely and at least begin cost analysis and research for developing their own stores on Facebook.</p>
<p><img src="http://www.bwilhelm.com/wordpress/wp-content/uploads/2009/07/Picture-7-150x150.png" alt="Alice.com" title="Alice.com" width="150" height="150" class="alignleft size-thumbnail wp-image-27" />To me, this seems like a great opportunity for a company like <a href="http://www.alice.com">Alice.com</a>, whose sole focus is to bring CPG goods direct to customers from manufacturers, to create a version of their site on facebook, allowing Facebookers to order their toothpaste and toiler paper before logging off for the night. Think about it: I&#8217;m on facebook, checking my messages and taking the latest quiz 27 of my other friends have taken, and I get a message in my inbox from AliceBot, who nicely reminds me that based on my purchase history of toothpaste of the last 3 months on Alice.com, that I should re-order toothpaste because I am probably running low. It also suggests 5 other items to add to my order so I can checkout with Free Shipping. But instead of sending me to Alice.com, they direct me to the Facebook Alice Store, where my &#8216;cart&#8217; has already been prepared for me, because I connected my Alice.com account and Facebook accounts previously with Facebook Connect. I&#8217;m ready to checkout, so I whip out the credit card and place my order. I then proceed to look at a few of my friends photos and log off. No need to leave facebook for everything I need to do on the internet.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bwilhelm.com/2009/07/30/e-commerce-comes-to-facebook/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
