<?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>Pratthost Developer Zone &#187; PHP</title>
	<atom:link href="http://devzone.pratthost.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://devzone.pratthost.com</link>
	<description>A resource for web developers</description>
	<lastBuildDate>Tue, 29 Jun 2010 18:47:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Magento: How To Remove The &#8220;Position&#8221; Sort Option</title>
		<link>http://devzone.pratthost.com/2009/11/30/magento-how-to-remove-the-position-sort-option/</link>
		<comments>http://devzone.pratthost.com/2009/11/30/magento-how-to-remove-the-position-sort-option/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 00:03:47 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://devzone.pratthost.com/?p=359</guid>
		<description><![CDATA[I had a client ask me today to remove the &#8220;Position&#8221; option from the toolbar on the category product listing. I realized that there are probably a lot of people that don&#8217;t ever utilize position, and therefore it is basically useless and should be removed so it doesn&#8217;t cause any confusion for the people browsing [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://devzone.pratthost.com/wp-content/uploads/2008/09/magento_icon.jpg" alt="Magento Icon" title="Magento Icon" width="67" height="67" class="alignleft size-full wp-image-60" /></p>
<p>I had a client ask me today to remove the &#8220;Position&#8221; option from the toolbar on the category product listing.  I realized that there are probably a lot of people that don&#8217;t ever utilize position, and therefore it is basically useless and should be removed so it doesn&#8217;t cause any confusion for the people browsing the store.</p>
<p>Unfortunately, this is not a listed attribute that you can easily turn on or off as far as sorting goes.  So, we have to do it the harder way and dive into the code.</p>
<p>There may be a &#8220;better&#8221; way to do this, I&#8217;m not sure, but this is super easy and it works.  All you have to do is edit the file /app/design/frontend/yourpackage/yourtheme/template/catalog/product/list/toolbar.phtml.  Towards the bottom, you&#8217;ll find the sort by code that outputs a select element.  It looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Sort by'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> &lt;select onchange=&quot;setLocation(this.value)&quot;&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAvailableOrders</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$_key</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$_order</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    &lt;option value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOrderUrl</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_key</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'asc'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isOrderCurrent</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_key</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> selected=&quot;selected&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&gt;
        <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_order</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    &lt;/option&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endforeach</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/select&gt;</pre></div></div>

<p>Change that to this (just adds an if statement):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Sort by'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> &lt;select onchange=&quot;setLocation(this.value)&quot;&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAvailableOrders</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$_key</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$_order</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_order</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'Position'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">// Remove &quot;Position&quot; from the sort option list ?&gt;</span>
        &lt;option value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOrderUrl</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_key</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'asc'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isOrderCurrent</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_key</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> selected=&quot;selected&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&gt;
            <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_order</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
        &lt;/option&gt;
    <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// End for removing &quot;Position&quot; sort option ?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endforeach</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/select&gt;</pre></div></div>

<p>And that all it takes.  If anyone knows of a better/easier way to do it, please let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://devzone.pratthost.com/2009/11/30/magento-how-to-remove-the-position-sort-option/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Magento: Import Multiple Images for Products Module</title>
		<link>http://devzone.pratthost.com/2009/10/09/magento-import-multiple-images-for-products-module/</link>
		<comments>http://devzone.pratthost.com/2009/10/09/magento-import-multiple-images-for-products-module/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 13:01:23 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://devzone.pratthost.com/?p=344</guid>
		<description><![CDATA[I still am confused as to why Magento hasn&#8217;t built-in the ability to upload multiple images for each product. After scoping it out, finally, I discovered that the modification was quite simple. I haven&#8217;t put the module up on Magento Connect yet (not sure if I will), but here I will lay out how to [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://devzone.pratthost.com/wp-content/uploads/2008/09/magento_icon.jpg" alt="Magento Icon" title="Magento Icon" width="67" height="67" class="alignleft size-full wp-image-60" /></p>
<p>I still am confused as to why Magento hasn&#8217;t built-in the ability to upload multiple images for each product.  After scoping it out, finally, I discovered that the modification was quite simple.  I haven&#8217;t put the module up on Magento Connect yet (not sure if I will), but here I will lay out how to do it, which for some of you may help you understand how modules work, if you don&#8217;t know already.</p>
<p>I&#8217;ve seen some solutions out there that modify core code, some that just take a file and move it to your /app/code/local/ retaining the same directory structure, so as to just override the file.  I don&#8217;t recommend either of these methods (especially the first), as with a true module you are setting up a much better environment over time for this to last.  And a module allows you to ONLY override the methods you need to modify, instead of entire classes.  Plus, you can easily disable the module right in the admin (Admin >> System >> Configuration >> Advanced).</p>
<p>Be sure you replace all of the &#8220;YOURSTUFF&#8221; with your name or company name.</p>
<p><em>I have only tested this with 1.3.2.4</em></p>
<h4>Step 1:</h4>
<p>Create the file:  /app/etc/modules/YOURSTUFF_ImportMultipleImages.xml.  This file tells Magento that you have this module and where it is located.</p>

<div class="wp_syntax"><div 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;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;YOURSTUFF_ImportMultipleImages<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;active<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/active<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;codePool<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>local<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/codePool<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/YOURSTUFF_ImportMultipleImages<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h4>Step 2:</h4>
<p>Create the file:  /app/code/local/YOURSTUFF/ImportMultipleImages/etc/config.xml.  This file is the configuration file for your module.  It tells Magento which class we are going to override.</p>

<div class="wp_syntax"><div 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;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;YOURSTUFF_ImportMultipleImages<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0.1.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/YOURSTUFF_ImportMultipleImages<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;global<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;models<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;catalog<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rewrite<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #808080; font-style: italic;">&lt;!-- Override Mage_Catalog_Model_Convert_Adapter_Product --&gt;</span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;convert_adapter_product<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>YOURSTUFF_ImportMultipleImages_Model_Convert_Adapter_Product<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/convert_adapter_product<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rewrite<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/catalog<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/models<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/global<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h4>Step 3:</h3>
<p>Create the file:  /app/code/local/YOURSTUFF/ImportMultipleImages/Model/Convert/Adapter/Product.php.  Important note:  When creating a module, you only want to include the methods that you are actually modifying.  As you can see, we are extending the original class, so we&#8217;ll have all of the methods from the original, but since we have the saveRow() method in our class, ours will take precedence.  We do it this way because when you upgrade Magento, you&#8217;ll only need to make sure you check the one method for changes, instead of the entire class.</p>
<p><strong>Again, be sure to replace the &#8220;YOURSTUFF&#8221; in the class name to your name or company name.</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * Import Multiple Images during Product Import
 *
 */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> YOURSTUFF_ImportMultipleImages_Model_Convert_Adapter_Product <span style="color: #000000; font-weight: bold;">extends</span> Mage_Catalog_Model_Convert_Adapter_Product
<span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/**
     * Save product (import)
     *
     * @param array $importData
     * @throws Mage_Core_Exception
     * @return bool
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> saveRow<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span> <span style="color: #000088;">$importData</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$product</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getProductModel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #339933;">-&gt;</span><span style="color: #004000;">reset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'store'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_null</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getBatchParams</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'store'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$store</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getStoreById</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getBatchParams</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'store'</span><span style="color: #009900;">&#41;</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;">$message</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'catalog'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Skip import row, required field &quot;%s&quot; not defined'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'store'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                Mage<span style="color: #339933;">::</span><span style="color: #004000;">throwException</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$store</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getStoreByCode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'store'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$store</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'catalog'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Skip import row, store &quot;%s&quot; field not exists'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'store'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            Mage<span style="color: #339933;">::</span><span style="color: #004000;">throwException</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sku'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'catalog'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Skip import row, required field &quot;%s&quot; not defined'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'sku'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            Mage<span style="color: #339933;">::</span><span style="color: #004000;">throwException</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$product</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setStoreId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$store</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$productId</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$product</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getIdBySku</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sku'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$productId</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$product</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$productId</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;">$productTypes</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getProductTypes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$productAttributeSets</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getProductAttributeSets</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #009933; font-style: italic;">/**
             * Check product define type
             */</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$productTypes</span><span style="color: #009900;">&#91;</span><span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'catalog'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Skip import row, is not valid value &quot;%s&quot; for field &quot;%s&quot;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                Mage<span style="color: #339933;">::</span><span style="color: #004000;">throwException</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000088;">$product</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setTypeId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$productTypes</span><span style="color: #009900;">&#91;</span><span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009933; font-style: italic;">/**
             * Check product define attribute set
             */</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'attribute_set'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$productAttributeSets</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'attribute_set'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'attribute_set'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'attribute_set'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'catalog'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Skip import row, is not valid value &quot;%s&quot; for field &quot;%s&quot;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'attribute_set'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                Mage<span style="color: #339933;">::</span><span style="color: #004000;">throwException</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000088;">$product</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAttributeSetId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$productAttributeSets</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'attribute_set'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_requiredFields <span style="color: #b1b100;">as</span> <span style="color: #000088;">$field</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$attribute</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$attribute</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$attribute</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getIsRequired</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'catalog'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Skip import row, required field &quot;%s&quot; for new products not defined'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$field</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    Mage<span style="color: #339933;">::</span><span style="color: #004000;">throwException</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setProductTypeInstance</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$product</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'category_ids'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$product</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCategoryIds</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'category_ids'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_ignoreFields <span style="color: #b1b100;">as</span> <span style="color: #000088;">$field</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$store</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getId</span><span style="color: #009900;">&#40;</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;">$websiteIds</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$product</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getWebsiteIds</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$websiteIds</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$websiteIds</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$store</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getWebsiteId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$websiteIds</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$websiteIds</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$store</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getWebsiteId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000088;">$product</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setWebsiteIds</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$websiteIds</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'websites'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$websiteIds</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$product</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getWebsiteIds</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$websiteIds</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$websiteIds</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000088;">$websiteCodes</span> <span style="color: #339933;">=</span> <span style="color: #990000;">split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'websites'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$websiteCodes</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$websiteCode</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                try <span style="color: #009900;">&#123;</span>
                    <span style="color: #000088;">$website</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">app</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getWebsite</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$websiteCode</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$website</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$websiteIds</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #000088;">$websiteIds</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$website</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span>
                catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000088;">$product</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setWebsiteIds</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$websiteIds</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$websiteIds</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$importData</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$field</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$field</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_inventoryFields<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$field</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_imageFields<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #000088;">$attribute</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$attribute</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #000088;">$isArray</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$setValue</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$attribute</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getFrontendInput</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'multiselect'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #990000;">split</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">MULTI_DELIMITER</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$isArray</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$setValue</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$attribute</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getBackendType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'decimal'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$setValue</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNumber</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$attribute</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">usesSource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$attribute</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAllOptions</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$isArray</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'label'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                            <span style="color: #000088;">$setValue</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #000088;">$setValue</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'label'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                            <span style="color: #000088;">$setValue</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #000088;">$product</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setData</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$field</span><span style="color: #339933;">,</span> <span style="color: #000088;">$setValue</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$product</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getVisibility</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$product</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setVisibility</span><span style="color: #009900;">&#40;</span>Mage_Catalog_Model_Product_Visibility<span style="color: #339933;">::</span><span style="color: #004000;">VISIBILITY_NOT_VISIBLE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$stockData</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$inventoryFields</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_inventoryFieldsProductTypes<span style="color: #009900;">&#91;</span><span style="color: #000088;">$product</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTypeId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
            ? <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_inventoryFieldsProductTypes<span style="color: #009900;">&#91;</span><span style="color: #000088;">$product</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTypeId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span>
            <span style="color: #339933;">:</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$inventoryFields</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$field</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$field</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_toNumber<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #000088;">$stockData</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNumber</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#93;</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;">$stockData</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$product</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setStockData</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$stockData</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$imageData</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_imageFields <span style="color: #b1b100;">as</span> <span style="color: #000088;">$field</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</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;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'no_selection'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$imageData</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #000088;">$imageData</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000088;">$imageData</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$field</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$imageData</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$file</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$fields</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            try <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$product</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addImageToMediaGallery</span><span style="color: #009900;">&#40;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">getBaseDir</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'media'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> DS <span style="color: #339933;">.</span> <span style="color: #0000ff;">'import'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$fields</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #009933; font-style: italic;">/**
		 * Allows you to import multiple images for each product.
		 * Simply add a 'gallery' column to the import file, and separate
		 * each image with a semi-colon.
		 */</span>
	        try <span style="color: #009900;">&#123;</span>
	                <span style="color: #000088;">$galleryData</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">';'</span><span style="color: #339933;">,</span><span style="color: #000088;">$importData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;gallery&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	                <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$galleryData</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$gallery_img</span><span style="color: #009900;">&#41;</span>
					<span style="color: #009933; font-style: italic;">/**
					 * @param directory where import image resides
					 * @param leave 'null' so that it isn't imported as thumbnail, base, or small
					 * @param false = the image is copied, not moved from the import directory to it's new location
					 * @param false = not excluded from the front end gallery
					 */</span>
	                <span style="color: #009900;">&#123;</span>
	                        <span style="color: #000088;">$product</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addImageToMediaGallery</span><span style="color: #009900;">&#40;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">getBaseDir</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'media'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> DS <span style="color: #339933;">.</span> <span style="color: #0000ff;">'import'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$gallery_img</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	                <span style="color: #009900;">&#125;</span>
	            <span style="color: #009900;">&#125;</span>
	        catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>        
		<span style="color: #666666; font-style: italic;">/* End Modification */</span>
&nbsp;
        <span style="color: #000088;">$product</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setIsMassupdate</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$product</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setExcludeUrlRewrite</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$product</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h4>Step 4:</h4>
<p>Test it out!  This is how it works:  Use the Magento product import functionality (Admin >> System >> Import/Export >> Profiles >> Import All Products).  Add a column to your CSV called &#8216;gallery&#8217;.  In that column, simply put all the images you&#8217;d like that product to have, separated by semi-colons.  The same exact rules apply for these images as do the &#8216;image&#8217;, &#8216;small_image&#8217;, and &#8216;thumbnail&#8217; columns, in that if you are putting all your images in the /media/import/ directory, you&#8217;ll have to include the forward-slash in the image names.  Here&#8217;s an example (be sure to leave out any spaces):</p>
<p>Your gallery column could look like:  /image1.jpg;/image2.jpg;/image3.jpg</p>
<p>These images will all show up just as if you were to go into the product edit in the admin and upload them.  They&#8217;ll be copied from the /media/import/ directory into the proper media directory structure, and they&#8217;ll show up as thumbnails below your main product image on the product view page.</p>
<p>Comment if you have any questions.  Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://devzone.pratthost.com/2009/10/09/magento-import-multiple-images-for-products-module/feed/</wfw:commentRss>
		<slash:comments>75</slash:comments>
		</item>
		<item>
		<title>Basecamp API: PHP Class &#8211; Version 1.1 Released</title>
		<link>http://devzone.pratthost.com/2008/12/04/basecamp-api-php-class-version-11-released/</link>
		<comments>http://devzone.pratthost.com/2008/12/04/basecamp-api-php-class-version-11-released/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 04:45:00 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[Basecamp]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Apps]]></category>

		<guid isPermaLink="false">http://devzone.pratthost.com/?p=299</guid>
		<description><![CDATA[Version 1.1 is now released. Please check out the Basecamp PHP Class page for new documentation and download information. There were a lot of changes, new methods (including file attachments), and bug fixes in 1.1. There&#8217;s still a lot of work to do, but I like to get it out into the user&#8217;s hands for [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://devzone.pratthost.com/wp-content/uploads/2008/10/icon_basecamp.jpg" alt="" title="Basecamp Icon" width="68" height="68" class="alignleft size-medium wp-image-181" /></p>
<p>Version 1.1 is now released. Please check out the <a href="http://devzone.pratthost.com/basecamp-php-class/">Basecamp PHP Class page</a> for new documentation and download information.</p>
<p>There were a lot of changes, new methods (including file attachments), and bug fixes in 1.1.  There&#8217;s still a lot of work to do, but I like to get it out into the user&#8217;s hands for feedback and bug-tracking.  If you are noticing something that isn&#8217;t working, or is glitchy, first check the method documentation within the class itself to make sure you are using it correction, then if it still isn&#8217;t working right &#8211; please let me know! (Post a comment here).</p>
<p>I may have easily incorrectly documented something, or forgot to make changes.  I ran out of time this evening and had to rush through it.  So, please keep that in mind!</p>
<p>I am very open to making quick changes/fixes and releases.  One of the best ways to contact me is through AIM (&#8220;creativearcjosh&#8221;).  Feel free to hop on and ask questions or make suggestions if I&#8217;m online.</p>
<p>I want to make this PHP class good, and solid.  So &#8211; I love the feedback and suggestions.  Keep them coming!</p>
]]></content:encoded>
			<wfw:commentRss>http://devzone.pratthost.com/2008/12/04/basecamp-api-php-class-version-11-released/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP: Enable SOAP with PHP5 on Media Temple&#8217;s DV 3.5</title>
		<link>http://devzone.pratthost.com/2008/11/24/php-enable-soap-with-php5-on-media-temples-dv-35/</link>
		<comments>http://devzone.pratthost.com/2008/11/24/php-enable-soap-with-php5-on-media-temples-dv-35/#comments</comments>
		<pubDate>Tue, 25 Nov 2008 00:22:28 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://devzone.pratthost.com/?p=273</guid>
		<description><![CDATA[I started trying to learn Magento&#8217;s API today, which requires the use of SOAP. I know that SOAP is a part of PHP5, however, I guess it doesn&#8217;t often come enabled on a lot of servers. I have a DV with Media Temple, and after running phpinfo(), I saw that SOAP definitely wasn&#8217;t configured. The [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://devzone.pratthost.com/wp-content/uploads/2008/09/php_icon.jpg" alt="" title="PHP Icon" width="82" height="82" class="alignleft size-medium wp-image-65" /></p>
<p>I started trying to learn Magento&#8217;s API today, which requires the use of SOAP.  I know that SOAP is a part of PHP5, however, I guess it doesn&#8217;t often come enabled on a lot of servers.  I have a DV with Media Temple, and after running phpinfo(), I saw that SOAP definitely wasn&#8217;t configured.</p>
<p>The following instructions will guide you through adding the SOAP to your previous installation of PHP.  In my case, I had PHP 5.2.6 installed, so &#8211; note that when you are downloading the PHP source files &#8211; you should probably try and stick with the version you currently have.</p>
<h4>Install Media Temple&#8217;s Developer Tools</h4>
<p>You will need the developer tools installed to compile PHP.  So, login to your Media Temple account center, select your primary domain, find the &#8220;Root Access &#038; Developer Tools&#8221;.  Install the developer tools if you haven&#8217;t already.  It may take up to 5-10 minutes, so be patient.</p>
<p>Make sure you have enabled root access as well, as you will need this to be able to compile the PHP</p>
<h4>Download &#038; Compile PHP</h4>
<p>Open your terminal, and ssh into your server using root.</p>
<ol>
<li>Navigate to a relatively unimportant directory.  I chose /home/<br /><code>cd /home/</code></li>
<li>Download PHP<br /><code>wget http://www.php.net/get/php-5.2.6.tar.gz/from/us.php.net/mirror</code></li>
<li>Unpack the PHP file<br /><code>tar -zxf php-5.2.6.tar.gz</code></li>
<li>Configure the new PHP to enable SOAP (will take a few minutes) (before enable is two dashes)<br /><code>cd php-5.2.6 <br /> ./configure --enable-soap=shared</code></li>
<li>Rebuild PHP (this will also take a while)<br /><code>make</code></li>
<li>Copy just the SOAP module into your existing installation of PHP<br /><code>cp modules/soap.so /usr/lib/php/modules/</code></li>
<li>Add the new SOAP configuration to your existing configuration<br /><code>echo "extension=soap.so" > /etc/php.d/soap.ini</code></li>
<li>Restart Apache<br /><code>/etc/init.d/httpd restart</code></li>
<li>Optional: You can now delete /home/php-5.2.6/ if you&#8217;d like, as you won&#8217;t need it any longer.<br /><code>rm -rf /home/php-5.2.6/</code></li>
<li>Check phpinfo() to confirm that SOAP is now enabled.</li>
<p>&nbsp;</p>
<p>This should not effect Media Temple&#8217;s update option program, in the case where you would like to up update your server later on.</p>
<p>Special thanks to <a href="http://dotjay.co.uk/">dotjay</a> for initially pointing this all out.
</ol>
]]></content:encoded>
			<wfw:commentRss>http://devzone.pratthost.com/2008/11/24/php-enable-soap-with-php5-on-media-temples-dv-35/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Basecamp API: PHP Class &#8211; Version 1.0 Launched</title>
		<link>http://devzone.pratthost.com/2008/11/21/basecamp-api-php-class-version-10-launched/</link>
		<comments>http://devzone.pratthost.com/2008/11/21/basecamp-api-php-class-version-10-launched/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 05:12:28 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[Basecamp]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Apps]]></category>

		<guid isPermaLink="false">http://devzone.pratthost.com/?p=268</guid>
		<description><![CDATA[The time has come to launch version 1.0 of my Basecamp PHP Class. It&#8217;s by no means complete, but it does a majority of the main core features. So, instead of sitting on it for a while, I figured that it was best to launch it early and keep building upon it (hoping too that [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://devzone.pratthost.com/wp-content/uploads/2008/10/icon_basecamp.jpg" alt="" title="Basecamp Icon" width="68" height="68" class="alignleft size-medium wp-image-181"  /></p>
<p>The time has come to launch version 1.0 of my Basecamp PHP Class.  It&#8217;s by no means complete, but it does a majority of the main core features.  So, instead of sitting on it for a while, I figured that it was best to launch it early and keep building upon it (hoping too that I will receive more feedback on it).</p>
<p>So, please check it out on the <a href="http://devzone.pratthost.com/basecamp-php-class/">Basecamp API PHP Class page</a>.  I whipped together a quick documentation page as well listing how to use the core methods, as well as a bunch of the simple set and get public methods.</p>
]]></content:encoded>
			<wfw:commentRss>http://devzone.pratthost.com/2008/11/21/basecamp-api-php-class-version-10-launched/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Basecamp: PHP Class In Progress &#8211; Feedback Needed</title>
		<link>http://devzone.pratthost.com/2008/11/15/basecamp-php-class-in-progress-feedback-needed/</link>
		<comments>http://devzone.pratthost.com/2008/11/15/basecamp-php-class-in-progress-feedback-needed/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 20:39:25 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Apps]]></category>

		<guid isPermaLink="false">http://devzone.pratthost.com/?p=227</guid>
		<description><![CDATA[I have begun working on a Basecamp PHP class (using cURL). I can certainly add in many of the basics, but I would love some feedback as to what YOU would like it to do. So, please write comments with ideas/wishlist of features that you would like to see in a Basecamp PHP class. At [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://devzone.pratthost.com/wp-content/uploads/2008/10/icon_basecamp.jpg" alt="" title="Basecamp Icon" width="68" height="68" class="alignleft size-medium wp-image-181" /></p>
<p>I have begun working on a Basecamp PHP class (using cURL).  I can certainly add in many of the basics, but I would love some feedback as to what YOU would like it to do.  So, please write comments with ideas/wishlist of features that you would like to see in a Basecamp PHP class.</p>
<p>At this point (not *quite* ready for a release), you pass the object your url and login credentials to create the object.  From that point, you can get information very easily on people, projects, messages, todos, etc. (returned as an xml object) from which you can sort through to find the data you need.</p>
<p>I haven&#8217;t yet created the functionality to post data &#8211; but that won&#8217;t be difficult, as I already know how to do it.</p>
<p>I&#8217;ll hope to have a release within the next couple weeks (hopefully).  I&#8217;ll create a static page for it similar to my Magento Product Import Script.</p>
<p><strong style="color: red">Update (11.16.08 &#8211; 9pm): </strong>  I have the class successfully posting comments (to any resource), and posting new messages is in the works.  Notifications and file attachments are also on the works.</p>
<p><strong style="color: red">Update (11.16.08 &#8211; 11:20pm): </strong>  Successfully posting messages to any given project id, category id, and you can easily set if a message is private or not.</p>
]]></content:encoded>
			<wfw:commentRss>http://devzone.pratthost.com/2008/11/15/basecamp-php-class-in-progress-feedback-needed/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>MySQL &amp; PHP: Convert Strings From All Uppercase to Uppercase Only First Letter of Each Word</title>
		<link>http://devzone.pratthost.com/2008/11/04/php-convert-strings-from-all-uppercase-to-uppercase-only-first-letter-of-each-word/</link>
		<comments>http://devzone.pratthost.com/2008/11/04/php-convert-strings-from-all-uppercase-to-uppercase-only-first-letter-of-each-word/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 21:00:22 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://devzone.pratthost.com/?p=215</guid>
		<description><![CDATA[I&#8217;m not sure if it is possible to make that title much shorter than that&#8230; Anyway, I had some old data that I imported to an installation of Magento. All of the product titles were all uppercase, which was quite ugly. I needed a way to convert all of those values to only have uppercase [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://devzone.pratthost.com/wp-content/uploads/2008/09/php_icon.jpg" alt="" title="PHP Icon" width="82" height="82" class="alignleft size-medium wp-image-65" /></p>
<p>I&#8217;m not sure if it is possible to make that title much shorter than that&#8230;  Anyway, I had some old data that I imported to an installation of Magento.  All of the product titles were all uppercase, which was quite ugly.  I needed a way to convert all of those values to only have uppercase first letter of each word.</p>
<p>Programming that was quite easy, but I noticed that there were also some parts of the string which were not converted like &#8220;On/off&#8221;, &#8220;D.e.&#8221;, &#8220;Quick-connect&#8221;, etc.  The <a href="http://us.php.net/ucfirst">ucwords()</a> function doesn&#8217;t recognize that kind of stuff.  So, I had to find a way around those.  I created an array that houses whatever characters you&#8217;d like to capitalize after (as long as there is a letter immediately after it).  So, those three examples become &#8220;On/Off&#8221;, &#8220;D.E.&#8221;, and &#8220;Quick-Connect&#8221;.</p>
<p>Here&#8217;s what I came up with.  Feel free to use it if you wish &#8211; you&#8217;ll just have to change the database credentials, change the SELECT and UPDATE queries to suit your needs, and edit the $also_after array to uppercase after any characters you want:</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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// Database Connection</span>
<span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> mysqli<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'password'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'database'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// What Ever Query You Want</span>
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT value_id, value FROM catalog_product_entity_varchar WHERE attribute_id = 45&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Run For Each Result</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$line</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch_object</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$value_id</span> 	<span style="color: #339933;">=</span> <span style="color: #000088;">$line</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">value_id</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$value</span>		<span style="color: #339933;">=</span> <span style="color: #000088;">$line</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">value</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Populate this array with characters that you want this script to capitalize after.</span>
	<span style="color: #666666; font-style: italic;">// If in the string there is &quot;onn/off&quot;, put the &quot;/&quot; character in the array to make &quot;On/Off&quot;</span>
	<span style="color: #666666; font-style: italic;">// otherwise, it would only do &quot;On/off&quot;.</span>
	<span style="color: #000088;">$also_after</span>	<span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'-'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'('</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Run this function for each value. Returns new string.</span>
	<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> convert_to_uc<span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #339933;">,</span> <span style="color: #000088;">$also_after</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Escape characters for database entry</span>
	<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$new_string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Update the database with your new string</span>
	<span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE catalog_product_entity_varchar SET value = '<span style="color: #006699; font-weight: bold;">$string</span>' WHERE value_id = '<span style="color: #006699; font-weight: bold;">$value_id</span>'&quot;</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;">// Convert To Uppercase function</span>
<span style="color: #000000; font-weight: bold;">function</span> convert_to_uc<span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #339933;">,</span> <span style="color: #000088;">$also_after</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$string</span> 	<span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Convert thet string to all lowercase, then uppercase the first letter of every word.</span>
	<span style="color: #000088;">$string</span> 	<span style="color: #339933;">=</span> <span style="color: #990000;">ucwords</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</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;">// For each $also_after character, run the uc_match function</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$also_after</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$char</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace_callback</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/(\\'</span><span style="color: #339933;">.</span><span style="color: #000088;">$char</span><span style="color: #339933;">.</span><span style="color: #0000ff;">')(\w)/'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;uc_match&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$string</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;">// Returns new formatted string</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$string</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Uppercase Match function - used by preg_replace_callback above</span>
<span style="color: #000000; font-weight: bold;">function</span> uc_match<span style="color: #009900;">&#40;</span><span style="color: #000088;">$match</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$match</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #990000;">strtoupper</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$match</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://devzone.pratthost.com/2008/11/04/php-convert-strings-from-all-uppercase-to-uppercase-only-first-letter-of-each-word/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Basecamp:  API Examples using PHP and cURL (GET)</title>
		<link>http://devzone.pratthost.com/2008/10/22/basecamp-api-examples-using-php-and-curl-get/</link>
		<comments>http://devzone.pratthost.com/2008/10/22/basecamp-api-examples-using-php-and-curl-get/#comments</comments>
		<pubDate>Thu, 23 Oct 2008 01:29:00 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Apps]]></category>

		<guid isPermaLink="false">http://devzone.pratthost.com/?p=180</guid>
		<description><![CDATA[I began working on a project today creating a type of work-request form. We use Basecamp for all of our project management, but since it&#8217;s a paid subscription and not something that we have control over, any extra functionality must be done elsewhere using Basecamp&#8217;s API. The Project: I work for a web development company, [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://devzone.pratthost.com/wp-content/uploads/2008/10/icon_basecamp.jpg" alt="" title="Basecamp Icon" width="68" height="68" class="alignleft size-medium wp-image-181" /></p>
<p>I began working on a project today creating a type of work-request form.  We use Basecamp for all of our project management, but since it&#8217;s a paid subscription and not something that we have control over, any extra functionality must be done elsewhere using Basecamp&#8217;s API.</p>
<p>The Project:  I work for a web development company, and we have a good number of clients who request little updates/projects/additions on a fairly regular basis.  We started running into the occasion more and more that a client would send us an email labeled &#8220;URGENT&#8221; and expect us to get something done for them within the hour.  When you are busy with other things, that is an unreasonable expectation.  So, we have since applied &#8220;Rush Jobs&#8221;.  The standard turn-around guarantee is 10 business days.  If they want it done in 5 days, or 2 days, they pay more (just like FedEx).</p>
<p>We sent out letters at the beginning of 2008 informing all of our clients of the new policy, however, it didn&#8217;t really sink in.  So, our next thought (which is what I&#8217;m working on now) is to create a work-request form, forcing them to have to manually select the turn-around time, having the prices right there in front of their eyes, every time.</p>
<p>I won&#8217;t go into detail about how we&#8217;ve decided to architect the interface, and how it all works &#8211; but I will say that we are keeping the system up-do-date at all times with company, project, and person data from Basecamp using the available API.  I had an very difficult time finding good examples of how to both gather, and post information to and from Basecamp.  But, I managed to successfully do both, and I thought I&#8217;d share the wealth!</p>
<h4>Getting All Projects</h4>

<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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$session</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>
&nbsp;
<span style="color: #000088;">$basecamp_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'https://YOUR-BASECAMP-URL/'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'YOUR-BASECAMP-USERNAME'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'YOUR-BASECAMP-PASSWORD'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$session</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$basecamp_url</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'projects.xml'</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;">$session</span><span style="color: #339933;">,</span> CURLOPT_HTTPAUTH<span style="color: #339933;">,</span> CURLAUTH_BASIC<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;">$session</span><span style="color: #339933;">,</span> CURLOPT_HTTPGET<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: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$session</span><span style="color: #339933;">,</span> CURLOPT_HEADER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</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;">$session</span><span style="color: #339933;">,</span> CURLOPT_HTTPHEADER<span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Accept: application/xml'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Content-Type: application/xml'</span><span style="color: #009900;">&#41;</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;">$session</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$session</span><span style="color: #339933;">,</span>CURLOPT_USERPWD<span style="color: #339933;">,</span><span style="color: #000088;">$username</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;:&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">ereg</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;^(https)&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$session</span><span style="color: #339933;">,</span>CURLOPT_SSL_VERIFYPEER<span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$session</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$session</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h4>Getting People By Company ID</h4>
<p>You only need to change line 7 of the code above to:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$session</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$basecamp_url</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'contacts/people/COMPANY-ID'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h4>Getting A Single Project</h4>
<p>Again, you only need to change line 7 to:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$session</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$basecamp_url</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'projects/PROJECT-ID.xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>As you can see, there&#8217;s not much to change to get different results of information.  Though <a href="http://developer.37signals.com/basecamp/">Basecamp&#8217;s API</a> doesn&#8217;t really tell you how to set everything up in PHP very well, it does give you enough, once you&#8217;ve got it all setup, to figure out what you need to change line 7 to to give you the results you want.</p>
<p>The results that are returned are pure XML.  You can choose to do whatever you want with that information.  I personally have been using PHP&#8217;s <a href="http://us.php.net/simplexml">Simple XML</a>.  If you echo out the results, you&#8217;ll see the XML and see all the available children, otherwise, you can also check out <a href="http://developer.37signals.com/basecamp/reference.shtml">this page</a> on Basecamp&#8217;s API for a quick-reference of everything.  </p>
<p>Let&#8217;s say we used the API to return all of the people from a specific company id (2nd example above) to the variable $response.  Here is an example of how to display some of the XML results that we specify using Simple XML:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000088;">$people_xml</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimpleXMLElement<span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$people_xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">person</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$person</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;strong&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$person</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">'first-name'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$person</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">'last-name'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/strong&gt;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Email: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$person</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">'email-address'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;ID: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$person</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;br /&gt;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>And that&#8217;s all there is to it.  It&#8217;s pretty straight-forward.  I&#8217;m currently working on a Basecamp PHP class that will at least handle all the functions that we&#8217;ll be using.  Maybe once it&#8217;s done, I&#8217;ll post it for download.  If you have any interest in a Basecamp PHP class, please post a comment and let me know &#8211; the more interest I get, the more motivated I&#8217;ll be to post it when I&#8217;m done.</p>
<p>I will be posting another article very soon about how to post information (messages, to-dos, file attachments) to Basecamp using the API.  Look for that fairly soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://devzone.pratthost.com/2008/10/22/basecamp-api-examples-using-php-and-curl-get/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>PHP: Learning OOP Is Challenging</title>
		<link>http://devzone.pratthost.com/2008/10/15/php-learning-oop-is-challenging/</link>
		<comments>http://devzone.pratthost.com/2008/10/15/php-learning-oop-is-challenging/#comments</comments>
		<pubDate>Wed, 15 Oct 2008 15:17:29 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://devzone.pratthost.com/?p=174</guid>
		<description><![CDATA[I haven&#8217;t been posting much lately because most of my free time is being poured into trying to learn Object-Oriented PHP. With the development of the Magento Product Import Script, I figured it was time to &#8220;bite the bullet&#8221; and start developing the script with classes instead of the initial procedural style that I used. [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://devzone.pratthost.com/wp-content/uploads/2008/09/php_icon.jpg" alt="" title="PHP Icon" width="82" height="82" class="alignleft size-medium wp-image-65" /></p>
<p>I haven&#8217;t been posting much lately because most of my free time is being poured into trying to learn Object-Oriented PHP.  With the development of the <a href="http://devzone.pratthost.com/magento-product-import-script/">Magento Product Import Script</a>, I figured it was time to &#8220;bite the bullet&#8221; and start developing the script with classes instead of the initial procedural style that I used.</p>
<p>It has bee good so far.  Most of the existing script has been fully converted to classes and functions.  However, the most frustrating part is that &#8211; I always feel like there&#8217;s an even better way to do what I&#8217;m doing.  So, I get hung up on the little details and often don&#8217;t make much progress.</p>
<p>I guess you have to start somewhere though.  I can always keep re-writing the script to make it better, and using it as my own learning project.</p>
<p>If any of you have any advice (that you wish you would have known earlier in your OOP learning days), please post a comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://devzone.pratthost.com/2008/10/15/php-learning-oop-is-challenging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP: Explode and Implode</title>
		<link>http://devzone.pratthost.com/2008/10/01/php-explode-and-implode/</link>
		<comments>http://devzone.pratthost.com/2008/10/01/php-explode-and-implode/#comments</comments>
		<pubDate>Wed, 01 Oct 2008 12:43:55 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://devzone.pratthost.com/?p=89</guid>
		<description><![CDATA[I was a really late in discovering the explode and implode functions of PHP. Explode and Implode offer an extremely easy way to convert a delimited string into an array, and the exact reverse of that. Often times you will run into the situation where, in order to work with some specific data properly, or [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://devzone.pratthost.com/wp-content/uploads/2008/09/php_icon.jpg" alt="" title="PHP Icon" width="82" height="82" class="alignleft size-medium wp-image-65" /></p>
<p>I was a really late in discovering the explode and implode functions of PHP.  Explode and Implode offer an extremely easy way to convert a delimited string into an array, and the exact reverse of that.  Often times you will run into the situation where, in order to work with some specific data properly, or display it properly, you will need to convert it into a more usable format.  I&#8217;ll give you a real-world example of each.</p>
<h3>Example</h3>
<p>In <a href="http://www.magentocommerce.com/">Magento</a> (ecommerce platform), you can assign a product to any number of categories.  In the database, these category IDs are stored in one column, separated by &#8220;/&#8221; and in order from smallest to largest (i.e. 6/13/38/50/81).</p>
<p>Let&#8217;s say that I need to write a script to put some specific products into a new category.  We&#8217;ll say that new category has an ID of 20.  If we need add category ID of 20 to this &#8220;6/13/38/50/81&#8243;, then we&#8217;ve got to be able to manipulate that string.  So, in this example, we&#8217;ll be using explode() to get the data into a more usable format for inserting the new ID, and then using implode() to wrap it all up in the end.</p>
<p>Explode() will take string and convert it into an array, separating by whatever delimiter you give it.  Implode() will take an array and convert it into a string, separated by any delimiter you want.</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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$category_ids</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;6/13/38/50/81&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$new_category</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;20&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Convert $category_ids into array
</span><span style="color: #000088;">$ids</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$category_ids</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Insert new category id into array
</span><span style="color: #990000;">array_push</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ids</span><span style="color: #339933;">,</span> <span style="color: #000088;">$new_category</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Sort array in numerical order
</span><span style="color: #990000;">sort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ids</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Convert array back to delimited string
</span><span style="color: #000088;">$new_cat_string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ids</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$new_cat_string</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// &quot;6/13/20/38/50/81&quot;</span></pre></td></tr></table></div>

<p>So, as you can see, we broke up the original category string into an array using <a href="http://us.php.net/explode">explode()</a>.  With an array, it is very easy to put new values into it with the function <a href="http://us2.php.net/array_push">array_push()</a>.  Then, we were easily able to sort it numerically with <a href="http://us2.php.net/sort">sort()</a>.  And finally, we can assemble the data back to it&#8217;s original form using <a href="http://us2.php.net/implode">implode()</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://devzone.pratthost.com/2008/10/01/php-explode-and-implode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
