<?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; Magento</title>
	<atom:link href="http://devzone.pratthost.com/category/magento/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: SQL to Find Missing Images</title>
		<link>http://devzone.pratthost.com/2010/06/29/magento-sql-to-find-missing-images/</link>
		<comments>http://devzone.pratthost.com/2010/06/29/magento-sql-to-find-missing-images/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 18:47:11 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://devzone.pratthost.com/?p=449</guid>
		<description><![CDATA[I just imported a ton of products for new website that I&#8217;m working on, and it turns out that the client misnamed a bunch of images, causing Magento to ignore the image import for those ones. I don&#8217;t want to scour through the website and the CSV (and the client wouldn&#8217;t want to pay us [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-60" title="Magento Icon" src="http://devzone.pratthost.com/wp-content/uploads/2008/09/magento_icon.jpg" alt="Magento Icon" width="67" height="67" /></p>
<p>I just imported a ton of products for new website that I&#8217;m working on, and it turns out that the client misnamed a bunch of images, causing Magento to ignore the image import for those ones.  I don&#8217;t want to scour through the website and the CSV (and the client wouldn&#8217;t want to pay us to do that either), so I figured if I could just come up with a list of SKUs for products missing an image, I could hand it off to them so they could correct everything.</p>
<p>This isn&#8217;t foolproof, but it does the job.  This query will give you a list of SKUs where there is no record in the database for that product&#8217;s &#8216;image&#8217; attribute (the main large product image).</p>
<p><code>SELECT `sku` FROM `catalog_product_entity` AS a LEFT JOIN `catalog_product_entity_varchar` AS b ON a.entity_id = b.entity_id AND b.attribute_id = 74 WHERE b.entity_id IS NULL</code></p>
]]></content:encoded>
			<wfw:commentRss>http://devzone.pratthost.com/2010/06/29/magento-sql-to-find-missing-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento: Overriding Core Files (Blocks, Models, Resources, Controllers)</title>
		<link>http://devzone.pratthost.com/2010/06/24/magento-overriding-core-files-blocks-models-resources-controllers/</link>
		<comments>http://devzone.pratthost.com/2010/06/24/magento-overriding-core-files-blocks-models-resources-controllers/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 13:43:39 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://devzone.pratthost.com/?p=439</guid>
		<description><![CDATA[When building custom modules for Magento, one of the most common needs is to override Magento&#8217;s core files, most commonly Blocks, Models, Resources, and Controllers. And, by the way, when I say &#8220;override&#8221;, that is also synonymous with &#8220;rewrite&#8221; or &#8220;extend&#8221;. I wanted to write this up for my own reference, but I hope this [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-60" title="Magento Icon" src="http://devzone.pratthost.com/wp-content/uploads/2008/09/magento_icon.jpg" alt="Magento Icon" width="67" height="67" /></p>
<p>When building custom modules for Magento, one of the most common needs is to override Magento&#8217;s core files, most commonly Blocks, Models, Resources, and Controllers.  And, by the way, when I say &#8220;override&#8221;, that is also synonymous with &#8220;rewrite&#8221; or &#8220;extend&#8221;.</p>
<p>I wanted to write this up for my own reference, but I hope this ends up helping you to.  At the time of writing this, all of these methods have been tested on 1.4.0.  This post assumes you to have familiarity with writing Magento modules.  And remember, you only need to include functions in your file that you are modifying.  Leave all untouched functions out of your file.</p>
<p>Also, the reason I haven&#8217;t included much for examples of the actual block/model code is that 90% of getting a rewrite to work correctly is just getting your config.xml correct.  It matters way less of where you put your files in your module (though it&#8217;s good to keep it organized and clean).</p>
<h3>Overriding Core Blocks</h3>
<p>One of the more simple and straight-forward things to override in Magento.  Let&#8217;s say that you want to override the following class:  Mage_Catalog_Block_Product_View.</p>
<p>The first step is to copy the file into your own module&#8217;s Block folder.  It can be anywhere you want within that folder, it really doesn&#8217;t matter.  But, for organizational purposes, it&#8217;s always best, in my opinion, to keep a similar folder/file structure as Magento does.  In this case, I would put this file in My/Module/Block/Catalog/Product/View.php.  Of course, you&#8217;ll need to rename the class, and have it extend Mage_Catalog_Block_Product_View.</p>
<p>Here is how the &#8216;blocks&#8217; tag in your config.xml should look:</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;blocks<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;my_module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>My_Module_Block<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/my_module<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: #009900;"><span style="color: #000000; font-weight: bold;">&lt;product_view<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>My_Module_Block_Catalog_Product_View<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/product_view<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;/blocks<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>As you can see, we&#8217;ve got the rewrite xml inside of the &#8216;catalog&#8217; tag.  This refers to app/code/core/Mage/Catalog/.  Then the &#8216;rewrite&#8217; tag tells Magento that we are going to override a block (since we are within the &#8216;blocks&#8217; tag) under Mage/Catalog/.  The &#8216;product_view&#8217; tag points to Mage/Catalog/Block/Product/View.php, and within that tag is the name of the class that we are using to override the core block.</p>
<p>As another example, if you wanted to override Mage/Catalog/Block/Product/View/Type/Simple.php, the tag under &#8216;rewrite&#8217; would be &#8216;product_view_type_simple&#8217;.</p>
<h3>Overriding Core Models</h3>
<p>Overriding models (but not resource models, which are anything declared in config.xml as &#8216;resourceModel&#8217;, which are typically files within a Mysql4 directory) is basically the same as blocks (above).  So, I will give an example, but leave out much of the explanation.</p>
<p>Lets say that I want to modify the model for the items on an order invoice (Mage_Sales_Model_Order_Invoice_Item).  I will copy that file to My/Module/Model/Sales/Order/Invoice/Item.php, rename the class, and extend Mage_Sales_Model_Order_Invoice_Item.</p>
<p>The config.xml &#8216;models&#8217; will look something like this:</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;models<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;my_module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>My_Module_Model<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/my_module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sales<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;order_invoice_item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>My_Module_Block_Sales_Order_Invoice_Item<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/order_invoice_item<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;/sales<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></pre></div></div>

<h3>Overriding Core Resource Models</h3>
<p>I found out the hard way once, and wasted a couple hours, that resource models have a different way of overriding them.  All of the concepts are the same, with the exception of the syntax in your config.xml file.  A resource model is typically going to be models that reside within a &#8216;Mysql4&#8242; folder.  The resource model folder is typically defined in the config.xml file using the tag &#8216;resourceModel&#8217;.</p>
<p>I was putting together a dependent filter module, and I needed to override this class:  Mage_Catalog_Model_Resource_Eav_Mysql4_Attribute.  Just as the above examples, I created this file:  My/Module/Model/Catalog/Resource/Eav/Mysql4/Attribute.php, renamed the class, and extended Mage_Catalog_Model_Resource_Eav_Mysql4_Attribute.</p>
<p>As I said above, the xml syntax changes for resource models.  Instead of defining just the &#8216;catalog&#8217; tag right before the &#8216;rewrite&#8217;, you actually have to define all the way down to the mysql4 folder. Here is an example for the above model:</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;models<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;my_module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>My_Module_Model<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/my_module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;catalog_resource_eav_mysql4<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;attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>My_Module_Model_Catalog_Resource_Eav_Mysql4_Attribute<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/attribute<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_resource_eav_mysql4<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></pre></div></div>

<h3>Overriding Core Controllers</h3>
<p>I have seen numerous methods on how to do this, but the method I will describe seems to be the current &#8216;standard&#8217;.</p>
<p>Lets say that I need to override the adminhtml attribute controller:  Mage_Adminhtml_Catalog_Product_AttributeController.  First thing is to create the controller in your module.  I would put mine in My/Module/controllers/Catalog/Product/AtttributeController.php.  An important key to note here is that with controllers, Magento does not autoload them like it does with blocks and models.  So, we&#8217;ll need to include the file of the controller that we want to override.  Here is an example of how my controller would look:</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;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">class</span> My_Module_Catalog_Product_AttributeController <span style="color: #000000; font-weight: bold;">extends</span> Mage_Adminhtml_Catalog_Product_AttributeController
<span style="color: #009900;">&#123;</span>
<span style="color: #339933;">...</span></pre></div></div>

<p>The config.xml file is key now.  Unlike models and blocks, you don&#8217;t need to define exactly which/where controller you are needing to override.  You just need to define whether it is an &#8216;admin&#8217; or &#8216;frontend&#8217; controller, which module has the controller(s) you are overriding, and which module you are overriding it with (your own, obviously).</p>
<p>Here is the example for the above controller:</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;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;admin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;routers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;adminhtml<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;args<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;My_Module</span> <span style="color: #000066;">before</span>=<span style="color: #ff0000;">&quot;Mage_Adminhtml&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>My_Module<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/My_Module<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;/args<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/adminhtml<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/routers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/admin<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>

<hr />
<p>Please feel free to ask questions or provide feedback on this post.  If there are any errors or better ways to do any of this, please let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://devzone.pratthost.com/2010/06/24/magento-overriding-core-files-blocks-models-resources-controllers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Magento:  Need a Custom Module?</title>
		<link>http://devzone.pratthost.com/2010/06/10/magento-need-a-custom-module/</link>
		<comments>http://devzone.pratthost.com/2010/06/10/magento-need-a-custom-module/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 13:19:59 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://devzone.pratthost.com/?p=424</guid>
		<description><![CDATA[I am open and looking for a few freelance projects, developing Magento modules. If you are in need for a module to be custom-built, or for an existing module to be modified, hire me! I have had direct experience in order exporting, custom attributes for almost anything, custom database tables/models, custom sort orders, custom order [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-60" title="Magento Icon" src="http://devzone.pratthost.com/wp-content/uploads/2008/09/magento_icon.jpg" alt="Magento Icon" width="67" height="67" /></p>
<p>I am open and looking for a few freelance projects, developing Magento modules.  If you are in need for a module to be custom-built, or for an existing module to be modified, hire me!</p>
<p>I have had direct experience in order exporting, custom attributes for almost anything, custom database tables/models, custom sort orders, custom order status functionality, and authorize.net payment gateway modification.  I am not interested in building new payment gateway modules, or heavy integration with external software.</p>
<p>Please fill out the form below with your inquiry if you are interested in getting a quote or in exploring the idea of hiring me for a freelance project.</p>
<div style="width: 315px; padding: 10px; border: 1px solid #999"; margin-left: 100px">
[contact-form]
</div>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://devzone.pratthost.com/2010/06/10/magento-need-a-custom-module/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento:  Best Way to Learn the Best Way to Build a Module</title>
		<link>http://devzone.pratthost.com/2010/06/02/magento-best-way-to-learn-the-best-way-to-build-a-module/</link>
		<comments>http://devzone.pratthost.com/2010/06/02/magento-best-way-to-learn-the-best-way-to-build-a-module/#comments</comments>
		<pubDate>Wed, 02 Jun 2010 19:03:39 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://devzone.pratthost.com/?p=421</guid>
		<description><![CDATA[One of the most valuable tools that I have found in Magento module development is to actually just look at Magento&#8217;s code. It seems obvious, but at least for me (for a while), it wasn&#8217;t. Every directory that you see inside of app/code/core/Mage/ is just a Magento module built in the same format that you [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-60" title="Magento Icon" src="http://devzone.pratthost.com/wp-content/uploads/2008/09/magento_icon.jpg" alt="Magento Icon" width="67" height="67" /></p>
<p>One of the most valuable tools that I have found in Magento module development is to actually just look at Magento&#8217;s code.  It seems obvious, but at least for me (for a while), it wasn&#8217;t.  Every directory that you see inside of app/code/core/Mage/ is just a Magento module built in the same format that you would build your own in app/code/local/yourstuff/.</p>
<p>I look at core code constantly.  If I need to figure out how to do a certain type of configuration option in my module, I just look at the etc/system.xml files.  If I need to add a new order attribute, I check out Sales/Model/Mysql4/Setup.php and emulate the file structure and method needed in that file to setup my own custom order attribute (making sure to properly configure config.xml as well).  The list goes on and on.</p>
<p>Just by having an installation and access to all the core files, you really have most of the examples that you would need to help you in writing your own module.  Just follow what they do, their same folder structures and everything, and you&#8217;ll be well on your way to writing a better quality module.</p>
]]></content:encoded>
			<wfw:commentRss>http://devzone.pratthost.com/2010/06/02/magento-best-way-to-learn-the-best-way-to-build-a-module/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Magento:  Order State and Order Status</title>
		<link>http://devzone.pratthost.com/2010/05/25/magento-order-state-and-order-status/</link>
		<comments>http://devzone.pratthost.com/2010/05/25/magento-order-state-and-order-status/#comments</comments>
		<pubDate>Tue, 25 May 2010 16:56:47 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://devzone.pratthost.com/?p=411</guid>
		<description><![CDATA[I built a module a couple of weeks ago for a client who needed to be able to change the status of orders at any time, as well as having a couple of custom order statuses. It appeared that the best way to change the status or state was by using the setState() method on [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-60" title="Magento Icon" src="http://devzone.pratthost.com/wp-content/uploads/2008/09/magento_icon.jpg" alt="Magento Icon" width="67" height="67" /></p>
<p>I built a module a couple of weeks ago for a client who needed to be able to change the status of orders at any time, as well as having a couple of custom order statuses.  It appeared that the best way to change the status or state was by using the setState() method on the order object.  Before we get into that, let&#8217;s take a look at how Magento sets up the default states and statuses:</p>
<p>Magento sets them up in this file in the Sales model config file: app/code/core/Mage/Sales/etc/config.xml under global > sales > order.  There in the &#8216;statuses&#8217; tag, you&#8217;ll see the 8 default statuses (some of which you probably didn&#8217;t know existed).  In the &#8216;states&#8217; tag, you&#8217;ll see that Magento is setting up 7 different order states.  There is also a &#8216;statuses&#8217; tag as a child of the states.  Here is where which statuses are able to be a part of each state.  For example, under the &#8216;processing&#8217; state, the only available status is &#8216;processing&#8217; (as you can see, you can set the default status for any particular state by adding default=&#8221;1&#8243; to the status).</p>
<p>Knowing which statuses are a part of which states is very important.  When using the setState() method, you need to make sure that the status/state you are trying to change the order to.  Another important thing to take note of is that the &#8216;complete&#8217; and &#8216;closed&#8217; states are protected, and you cannot use setState() to change an order to either of those states without overriding the order model to allow the passing of false (setState() passes your parameters to a protected function _setState() which hard-codes true into the &#8216;shouldProtectState&#8217; parameter).</p>
<p>Ok, now on to the setState() method.  This method not only allows you to change the state and status, it also adds the change to the order&#8217;s Comments History and allows you to notify the customer. This method can take up to 4 parameters, which I&#8217;ll list in order:</p>
<ul>
<li>$state (string):  This is the state you would like to change the order to.  Must match the xml tag in config.xml</li>
<li>$status (string or true):  This is the status you would like to change the order to.  Since by default Magento only has one status per state it either has to be the correct status name, or if you pass true it will just get the default status for the state you are passing.</li>
<li>$comment (string):  If you want to pass in a string to add to the comments, you can do so.  By default it just passes a blank string</li>
<li>$isCustomerNotified (bool):  Leave this parameter off if you do not want the customer to be notified, otherwise pass in true</li>
</ul>
<p>So, if I wanted to change the order status to &#8220;Cancelled&#8221;, and I don&#8217;t want the customer notified, this is how I would do it:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setState</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cancelled'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Cancelled order due to bad credit card'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Other statuses and states can be added by creating your own module and adding them via your config.xml.  You can also add statuses to the other states.  This would allow you to change the statuses of your orders right from the order view in the admin.</p>
]]></content:encoded>
			<wfw:commentRss>http://devzone.pratthost.com/2010/05/25/magento-order-state-and-order-status/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Magento: getCollection() Method Discovery</title>
		<link>http://devzone.pratthost.com/2010/05/25/magento-getcollection-method-discovery/</link>
		<comments>http://devzone.pratthost.com/2010/05/25/magento-getcollection-method-discovery/#comments</comments>
		<pubDate>Tue, 25 May 2010 15:25:09 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://devzone.pratthost.com/?p=408</guid>
		<description><![CDATA[I was writing an order export module the other day, and I was needing to get some data from orders and found myself unable to get any customer information such as ->getCustomerEmail(). I was getting the order model collection with the following code: $orders = Mage::getModel&#40;'sales/order'&#41;-&#62;getCollection&#40;&#41;; I could have sworn that in some other context, [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-60" title="Magento Icon" src="http://devzone.pratthost.com/wp-content/uploads/2008/09/magento_icon.jpg" alt="Magento Icon" width="67" height="67" /></p>
<p>I was writing an order export module the other day, and I was needing to get some data from orders and found myself unable to get any customer information such as ->getCustomerEmail().  I was getting the order model collection with the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$orders</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getModel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sales/order'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCollection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I could have sworn that in some other context, I was able to get a bunch more information from the order model than what I was able to get from this.  Then, with some help from the #magento channel on IRC, I realized that the getCollection() method seems to only return data from itself, and no other related models.  It&#8217;s limited.  If you just add a &#8216;*&#8217; to the call, you&#8217;ll end up getting a lot more data, and I was able to then use getCustomerEmail().</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$orders</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getModel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sales/order'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCollection</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'*'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://devzone.pratthost.com/2010/05/25/magento-getcollection-method-discovery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento: Change Default Sort Order to &#8220;Position&#8221; (1.3.x)</title>
		<link>http://devzone.pratthost.com/2010/03/25/magento-change-default-sort-order-to-position-1-3-x/</link>
		<comments>http://devzone.pratthost.com/2010/03/25/magento-change-default-sort-order-to-position-1-3-x/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 15:17:51 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://devzone.pratthost.com/?p=404</guid>
		<description><![CDATA[Currently running 1.3.2.4 for a client, I was needing to change the default sort order on the product list to &#8220;Position&#8221; instead of &#8220;Name&#8221;. Heading into the configuration on the backend, there were only three options, none of which were &#8220;Position&#8221;. There was &#8220;Name&#8221;, &#8220;Price&#8221;, and &#8220;Best Value&#8221;. To hopefully save some headaches of a [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-60" title="Magento Icon" src="http://devzone.pratthost.com/wp-content/uploads/2008/09/magento_icon.jpg" alt="Magento Icon" width="67" height="67" /></p>
<p>Currently running 1.3.2.4 for a client, I was needing to change the default sort order on the product list to &#8220;Position&#8221; instead of &#8220;Name&#8221;.  Heading into the configuration on the backend, there were only three options, none of which were &#8220;Position&#8221;.  There was &#8220;Name&#8221;, &#8220;Price&#8221;, and &#8220;Best Value&#8221;.</p>
<p>To hopefully save some headaches of a few of you out there, turns out that &#8220;Best Value&#8221; actually is the value for &#8220;Position&#8221;.  Not sure why, as it doesn&#8217;t really seem to make sense, but that&#8217;s all you have to do!</p>
<p>And, if you don&#8217;t know, the &#8220;Position&#8221; is set by editing a category, going to the &#8220;Category Products&#8221; tab, and putting in numeric values in the &#8220;Position&#8221; column for each product.  This allows you to order the products any way you want for any category.</p>
]]></content:encoded>
			<wfw:commentRss>http://devzone.pratthost.com/2010/03/25/magento-change-default-sort-order-to-position-1-3-x/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Magento:  Table Rate Shipping &amp; Shopping Cart Price Rules with Free Shipping</title>
		<link>http://devzone.pratthost.com/2010/03/15/magento-table-rate-shipping-shopping-cart-price-rules-with-free-shipping/</link>
		<comments>http://devzone.pratthost.com/2010/03/15/magento-table-rate-shipping-shopping-cart-price-rules-with-free-shipping/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 21:32:41 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://devzone.pratthost.com/?p=390</guid>
		<description><![CDATA[I am working with a possible client about a new website, and one of the features that they have requested is to have table rate shipping based upon order total, and to have free shipping for $100 or more. This is normally easy and setup directly in the table rates. But there&#8217;s a catch. There [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-60" title="Magento Icon" src="http://devzone.pratthost.com/wp-content/uploads/2008/09/magento_icon.jpg" alt="Magento Icon" width="67" height="67" /></p>
<p>I am working with a possible client about a new website, and one of the features that they have requested is to have table rate shipping based upon order total, and to have free shipping for $100 or more.  This is normally easy and setup directly in the table rates.  But there&#8217;s a catch.</p>
<p>There are a number of products that need to negate the free shipping if any of them are in the cart.  Fortunately, this is doable using Shopping Cart Price rules.  Here is how to do it:</p>
<p><strong>Step 1:</strong><br />
Enable your table rates, download the CSV (making sure you are viewing the config on the website level), modify it and then upload your rates.  Do not offer any free shipping in your CSV.  Keep the Free Shipping method disabled.</p>
<p><strong>Step 2:</strong><br />
Create your Shopping Cart Price rule.  I&#8217;ve included images below to help explain it.  Essentially, you need to set it up to look for a cart subtotal that is equal or greater than $100, and to make sure that there are no excluded products in the cart.  You do this under the conditions tab.  (Just change the &#8220;sku1, sku2, sku3&#8243; etc. to the SKU&#8217;s of the products you want to exclude)</p>
<div style="width: 300px; height: 78px; border: 1px solid #999; margin: 0 auto"><a href="http://devzone.pratthost.com/wp-content/uploads/2010/03/price-rule1.png" rel="lightbox[390]"><img src="http://devzone.pratthost.com/wp-content/uploads/2010/03/price-rule1-300x68.png" alt="" title="price-rule1" width="300" height="68" class="alignleft size-medium wp-image-391" /></a></div>
<p><br style="clear: both" /></p>
<div style="width: 300px; height: 160px; border: 1px solid #999; margin: 0 auto"><a href="http://devzone.pratthost.com/wp-content/uploads/2010/03/price-rule2.png" rel="lightbox[390]"><img src="http://devzone.pratthost.com/wp-content/uploads/2010/03/price-rule2-300x152.png" alt="" title="price-rule2" width="300" height="152" class="alignleft size-medium wp-image-392" /></a></div>
<p><br style="clear: both" /></p>
<p>What this does is offers the free shipping method (even though it is disabled) if the shopping cart total is $100 or more and does not include any excluded products.  If there are any excluded products in the cart, the free shipping method will never be offered.</p>
]]></content:encoded>
			<wfw:commentRss>http://devzone.pratthost.com/2010/03/15/magento-table-rate-shipping-shopping-cart-price-rules-with-free-shipping/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Magento: Add Manufacturer Column to Admin Product Grid</title>
		<link>http://devzone.pratthost.com/2010/03/11/magento-add-manufacturer-column-to-admin-product-grid/</link>
		<comments>http://devzone.pratthost.com/2010/03/11/magento-add-manufacturer-column-to-admin-product-grid/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 20:43:46 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://devzone.pratthost.com/?p=386</guid>
		<description><![CDATA[A client requested to add a column to the product grid in the admin so that they could filter by manufacturer. It would be great if Magento made this more simple to do, but it&#8217;s not that bad to just do it manually. Instead of creating a whole module to do this, I&#8217;m just overriding [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-60" title="Magento Icon" src="http://devzone.pratthost.com/wp-content/uploads/2008/09/magento_icon.jpg" alt="Magento Icon" width="67" height="67" /></p>
<p>A client requested to add a column to the product grid in the admin so that they could filter by manufacturer.  It would be great if Magento made this more simple to do, but it&#8217;s not that bad to just do it manually.  Instead of creating a whole module to do this, I&#8217;m just overriding one file.  You can make a module with it quite easily if you want.</p>
<p><em>The following was used and tested with Magento 1.3.2.4</em></p>
<p><strong>Step 1:</strong><br />
Copy this file:  /app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php and paste it here:  /app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php.  This will override the core file with your own without actually modifying core code.</p>
<p><strong>Step 2:</strong><br />
By looking at this file, you will clearly see how Magento is setting up the columns.  Find where you want to put the Manufacturer column, and paste the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$manufacturer_items</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getModel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'eav/entity_attribute_option'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCollection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setStoreFilter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">join</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'attribute'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'attribute.attribute_id=main_table.attribute_id'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'attribute_code'</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;">$manufacturer_items</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$manufacturer_item</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: #000088;">$manufacturer_item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAttributeCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'manufacturer'</span><span style="color: #009900;">&#41;</span> 
                <span style="color: #000088;">$manufacturer_options</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$manufacturer_item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOptionId</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: #000088;">$manufacturer_item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">endforeach</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'manufacturer'</span><span style="color: #339933;">,</span>
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">'header'</span><span style="color: #339933;">=&gt;</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;">'Manufacturer'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'width'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'100px'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'type'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'options'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'index'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'manufacturer'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'options'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$manufacturer_options</span>
        <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>Step 3:</strong><br />
Enjoy your new column.  Props to <a href="http://www.magentocommerce.com/boards/member/56783/">wolfdog85</a> for helping me figure out the code.  The original forum post can be found <a href="http://www.magentocommerce.com/boards/viewthread/20877/P0/">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://devzone.pratthost.com/2010/03/11/magento-add-manufacturer-column-to-admin-product-grid/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<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>
	</channel>
</rss>
