<?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>Scott Weaver</title>
	<atom:link href="http://scottmw.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://scottmw.com</link>
	<description></description>
	<lastBuildDate>Wed, 25 Apr 2012 07:21:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>magento: adding / deleting attribute options programmatically</title>
		<link>http://scottmw.com/50/magento-adding-deleting-attribute-options-programmatically/</link>
		<comments>http://scottmw.com/50/magento-adding-deleting-attribute-options-programmatically/#comments</comments>
		<pubDate>Wed, 25 Apr 2012 06:00:30 +0000</pubDate>
		<dc:creator>scott</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://scottmw.com/?p=50</guid>
		<description><![CDATA[I spent about a half an hour getting Magento to properly add attribute options programmatically and then a couple more hours trying to get it to properly remove the default set. I&#8217;m in the midst of updating the RMA module for Magento Enterprise 1.11 and one of my tasks is to change the &#8220;Reason for [...]]]></description>
			<content:encoded><![CDATA[<p>I spent about a half an hour getting Magento to properly add attribute options programmatically and then a couple more hours trying to get it to properly remove the default set. I&#8217;m in the midst of updating the RMA module for Magento Enterprise 1.11 and one of my tasks is to change the &#8220;Reason for Return&#8221; options that appear in the dropdown for individual return items.</p>
<p>So in an effort to save myself (and perhaps others) the trouble in the future, I wanted to quickly lay out how I got it working.</p>
<p><strong>Setup</strong></p>
<p>Perhaps one of the most important parts of making this sort of update easy is modifying your migration scripts to use the right model for setup. In this case, I used the setup model included with the RMA module itself &#8212; Enterprise_Rma_Model_Resource_Setup. The following example assumes you have your own RMA module in the &#8220;namespace&#8221; namespace.</p>
<p>config.xml:</p>
<pre class="brush: xml; toolbar: true; tab-size: 4; highlight: [5];">&lt;resources&gt;
    &lt;namespace_rma_setup&gt;
        &lt;setup&gt;
            &lt;module&gt;Namespace_Rma&lt;/module&gt;
            &lt;class&gt;Enterprise_Rma_Model_Resource_Setup&lt;/class&gt;
        &lt;/setup&gt;
        &lt;connection&gt;
            &lt;use&gt;core_setup&lt;/use&gt;
        &lt;/connection&gt;
    &lt;/namespace_rma_setup&gt;
&lt;/resources&gt;</pre>
<p><strong>The Install Script</strong></p>
<p>Now we&#8217;re going to delete the old options and then add the new ones. Note how this process is wrapped in a database transaction, just in case. Moreover, look at the highlighted lines. On line 29, you&#8217;ll notice that the setup model we&#8217;ve chosen allows us to use the addAttributeOption method (as well as various other useful methods), which lets us easily delete the existing options.</p>
<p>Next, on line 43 the setup script also gives us the getDefaultEntities method which returns the array representation of the attribute structure for RMA&#8217;s. From this, we can fill in the blanks that Magento expects to be there for our option array. Then on line 53, we merge our arrays together to feed Magento what it needs to complete the deletion of the previous options and to add the new options in the order we give it.</p>
<pre class="brush: php; toolbar: true; tab-size: 4; highlight: [29, 43, 53];">/** @var $installer Enterprise_Rma_Model_Resource_Setup */
$installer = $this;

/** @var $connection Varien_Db_Adapter_Pdo_Mysql */
$connection = $installer-&gt;getConnection();

$installer-&gt;startSetup();

try {
    $connection-&gt;beginTransaction();

    // Delete existing options

    /** @var $rmaItems Enterprise_Rma_Model_Item_Attribute */
    $rmaItems = Mage::getModel('enterprise_rma/item_attribute');

    $reason = $rmaItems-&gt;loadByCode('rma_item', 'reason');

    $selectOptions = $reason-&gt;getFrontend()-&gt;getSelectOptions();
    $optionsDelete = array();

    foreach($selectOptions as $option) {
        if ($option['value'] != "") {
            $optionsDelete['delete'][$option['value']] = true;
            $optionsDelete['value'][$option['value']] = true;
        }
    }

    $installer-&gt;addAttributeOption($optionsDelete);

    // Add new options

    $optionsArray = array(
        'Wrong size',
        'Wrong item',
        'Does not fit',
        'Wrong SKU',
        'Warranty Claim',
        'Did not order',
        'Exchange',
    );

    $defaultEntities = $installer-&gt;getDefaultEntities();

    $reason = $defaultEntities['rma_item']['attributes']['reason'];
    $reasonOptions = array(
        'option' =&gt; array(
            'values' =&gt; $optionsArray,
            'delete' =&gt; $optionsDelete,
        ),
    );

    $reasonAttribute = array_merge($reason, $reasonOptions);

    $installer-&gt;addAttribute('rma_item', 'reason', $reasonAttribute);

    $connection-&gt;commit();

} catch (Exception $e) {
    $connection-&gt;rollBack();
    Mage::logException($e);
}

$installer-&gt;endSetup();</pre>
]]></content:encoded>
			<wfw:commentRss>http://scottmw.com/50/magento-adding-deleting-attribute-options-programmatically/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>a visual explanation of sql joins</title>
		<link>http://scottmw.com/42/a-visual-explanation-of-sql-joins/</link>
		<comments>http://scottmw.com/42/a-visual-explanation-of-sql-joins/#comments</comments>
		<pubDate>Fri, 23 Dec 2011 15:32:37 +0000</pubDate>
		<dc:creator>scott</dc:creator>
				<category><![CDATA[Bookmarks]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://scottmw.com/?p=42</guid>
		<description><![CDATA[Now here is an excellent way to think of how sql joins work: a visual explanation of sql joins.]]></description>
			<content:encoded><![CDATA[<p>Now here is an excellent way to think of how sql joins work: <a href="http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html">a visual explanation of sql joins</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://scottmw.com/42/a-visual-explanation-of-sql-joins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>trying out foursquare</title>
		<link>http://scottmw.com/30/trying-out-foursquare/</link>
		<comments>http://scottmw.com/30/trying-out-foursquare/#comments</comments>
		<pubDate>Wed, 07 Dec 2011 06:26:28 +0000</pubDate>
		<dc:creator>scott</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://scottmw.com/?p=30</guid>
		<description><![CDATA[foursquare Update: I uninstalled the app as I didn&#8217;t know why I was mindlessly checking into places. Interesting, but a time waster for sure. Trying out path.com instead!]]></description>
			<content:encoded><![CDATA[<p><a title="foursquare" href="https://foursquare.com/turtleofdeath" target="_blank">foursquare</a></p>
<p>Update:</p>
<p>I uninstalled the app as I didn&#8217;t know why I was mindlessly checking into places. Interesting, but a time waster for sure.</p>
<p>Trying out <a title="Path" href="http://path.com">path.com</a> instead!</p>
]]></content:encoded>
			<wfw:commentRss>http://scottmw.com/30/trying-out-foursquare/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>renaming directories with git</title>
		<link>http://scottmw.com/26/renaming-directories-with-git/</link>
		<comments>http://scottmw.com/26/renaming-directories-with-git/#comments</comments>
		<pubDate>Tue, 06 Dec 2011 21:19:13 +0000</pubDate>
		<dc:creator>scott</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Source Control]]></category>

		<guid isPermaLink="false">http://scottmw.com/?p=26</guid>
		<description><![CDATA[Developing today, I ran into an issue of case sensitivity on our QA server that didn&#8217;t exist in dev. Easy, I thought; I&#8217;ll just change the case and commit it up. As it turns out, renaming directories in git isn&#8217;t so easy. So to help other people avoid wasting their time like I did, I [...]]]></description>
			<content:encoded><![CDATA[<p>Developing today, I ran into an issue of case sensitivity on our QA server that didn&#8217;t exist in dev. Easy, I thought; I&#8217;ll just change the case and commit it up.</p>
<p>As it turns out, renaming directories in git isn&#8217;t so easy. So to help other people avoid wasting their time like I did, I thought I&#8217;d post the workaround.</p>
<p>Normally, you&#8217;d think that to rename a directory called &#8216;FooBar&#8217; to &#8216;Foobar&#8217; you&#8217;d just issue commands like so:</p>
<p><code>git mv FooBar Foobar<br />
git add -A Foobar<br />
git commit -am "Your message"</code></p>
<p>But that is not the case. Instead, you would do this:</p>
<p><code> mv FooBar Sometemporaryname<br />
git add -A Sometemporaryname<br />
git commit -am "Your message here"<br />
mv Sometemporaryname Foobar<br />
git add -A Foobar<br />
git commit -am "Second message here"</code></p>
<p>Not very intuitive but it gets the job done. Hope it saves someone some time.</p>
]]></content:encoded>
			<wfw:commentRss>http://scottmw.com/26/renaming-directories-with-git/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>starting over</title>
		<link>http://scottmw.com/22/starting-over/</link>
		<comments>http://scottmw.com/22/starting-over/#comments</comments>
		<pubDate>Sat, 03 Dec 2011 08:46:25 +0000</pubDate>
		<dc:creator>scott</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://scottmw.com/?p=22</guid>
		<description><![CDATA[So tonight I decided to delete the entire contents of the previous blog I had on this domain in favor of a much more minimalist attempt. Something about the automated posts and stagnant content &#8212; it needed to go. So what will I focus on this time around? Minimalism and simplicity More programming / engineering [...]]]></description>
			<content:encoded><![CDATA[<p>So tonight I decided to delete the entire contents of the previous blog I had on this domain in favor of a much more minimalist attempt. Something about the automated posts and stagnant content &#8212; it needed to go.</p>
<p>So what will I focus on this time around?</p>
<ul>
<li>Minimalism and simplicity</li>
<li>More programming / engineering content</li>
<li>This blog as opposed to others (time to delete and forget)</li>
</ul>
<p>Feel free to <a title="About" href="http://scottmw.com/about/">read about me</a> or <a title="Contact" href="http://scottmw.com/contact/">contact me</a>.</p>
<p>That is all.</p>
]]></content:encoded>
			<wfw:commentRss>http://scottmw.com/22/starting-over/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

