<?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>ActiveCodeline &#187; Magento</title>
	<atom:link href="http://activecodeline.com/category/magento-development/feed" rel="self" type="application/rss+xml" />
	<link>http://activecodeline.com</link>
	<description>Blog site of Branko Ajzele, web application developer.</description>
	<lastBuildDate>Sun, 29 Aug 2010 13:18:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Magento SID issue</title>
		<link>http://activecodeline.com/magento-sid-issue</link>
		<comments>http://activecodeline.com/magento-sid-issue#comments</comments>
		<pubDate>Wed, 18 Aug 2010 10:38:43 +0000</pubDate>
		<dc:creator>branko</dc:creator>
				<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://activecodeline.com/?p=1260</guid>
		<description><![CDATA[Sometimes, Magento will add a SID parameter to your url like http://myshop.net/customer/?SID=96408b4e5b7c426e76b6a0e29292dca7. This can break up your code and make certain pages render as non existing depending on how you outputted your form action urls. In case you need a quick fix, all you need is to open the &#8220;app\code\core\Mage\Core\Model\Session\Abstract.php&#8221; file and around line 72 [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes, Magento will add a SID parameter to your url like http://myshop.net/customer/?SID=96408b4e5b7c426e76b6a0e29292dca7. This can break up your code and make certain pages render as non existing depending on how you outputted your form action urls.</p>
<p>In case you need a quick fix, all you need is to open the &#8220;app\code\core\Mage\Core\Model\Session\Abstract.php&#8221; file and around line 72 change &#8220;<strong>protected $_skipSessionIdFlag = true;</strong>&#8221; to &#8220;<strong>protected $_skipSessionIdFlag  = false;</strong>&#8220;. </p>
<p>Surely this is a modified core file so for more general fix you can make yourself an extension that does the same. In such case you would most likely override method &#8220;<strong>setSkipSessionIdFlag($flag)</strong>&#8221; in the same file. </p>
<p>Or you can play with .htaccess file in order to try and solve the issue.</p>
<p>Cheers.</p>
]]></content:encoded>
			<wfw:commentRss>http://activecodeline.com/magento-sid-issue/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to resolve and debug &#8220;Failed to parse response&#8221; errors in Magento API</title>
		<link>http://activecodeline.com/how-to-resolve-and-debug-failed-to-parse-response-errors-in-magento-api</link>
		<comments>http://activecodeline.com/how-to-resolve-and-debug-failed-to-parse-response-errors-in-magento-api#comments</comments>
		<pubDate>Sat, 14 Aug 2010 14:20:13 +0000</pubDate>
		<dc:creator>branko</dc:creator>
				<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://activecodeline.com/?p=1254</guid>
		<description><![CDATA[Today I was working on my Mapy project/extension. In one moment I accidentally pasted my method two times into the same class. In most of the cases, error like this would manifest itself like &#8220;Cannot redeclare&#8230;&#8221; on the output. However, API stuff is abstracted trough several layers/classes. One way of debugging this is to open [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was working on my <a href="http://activecodeline.com/projects/magento/mapy">Mapy project/extension</a>. In one moment I accidentally pasted my method two times into the same class. In most of the cases, error like this would manifest itself like &#8220;Cannot redeclare&#8230;&#8221; on the output. However, API stuff is abstracted trough several layers/classes. One way of debugging this is to open the <strong>app/code/core/Mage/Api/Model/Server/Handler/Abstract.php</strong> file and look for &#8220;<strong>public function call($sessionId, $apiPath, $args = array())</strong>&#8221; method.<span id="more-1254"></span></p>
<p><a href="http://activecodeline.com/wp-content/uploads/2010/08/Magento_Failed_To_Parse_Response.png"><img src="http://activecodeline.com/wp-content/uploads/2010/08/Magento_Failed_To_Parse_Response-300x222.png" alt="" title="Magento_Failed_To_Parse_Response" width="300" height="222" class="alignnone size-medium wp-image-1258" /></a></p>
<p>To see if you are on the right track, first thing you can do is to set something like &#8220;return &#8216;test&#8217;;&#8221; right on top of the method body. From there on you go line by line below until you reach the line that broke the response and caused the &#8220;Failed to parse response&#8221; messages. </p>
<p>In my case this was a completely innocent line of code that broke it, line 277 &#8220;$model = Mage::getModel($modelName);&#8221;. Notice that although inside the try-catch block, it still broke as this error in my class had nothing to do with exception, but standard PHP error.</p>
<p>So in essence I did two things. First I did &#8220;return &#8216;My model name: &#8216;.$modelName;&#8221; just above line 277. After that I tried to do &#8220;$myModel = new My_Model_Name()&#8221; somewhere in my code independent of API call. This is where I spotted the &#8220;Cannot redeclare&#8230;&#8221; error.</p>
<p>I realize these are trivial things, just felt the need to write it down is someone is having hard time debugging it.</p>
<p>Cheers.</p>
]]></content:encoded>
			<wfw:commentRss>http://activecodeline.com/how-to-resolve-and-debug-failed-to-parse-response-errors-in-magento-api/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento, please change the extension directory structure</title>
		<link>http://activecodeline.com/magento-please-change-the-extension-directory-structure</link>
		<comments>http://activecodeline.com/magento-please-change-the-extension-directory-structure#comments</comments>
		<pubDate>Thu, 12 Aug 2010 12:58:01 +0000</pubDate>
		<dc:creator>branko</dc:creator>
				<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://activecodeline.com/?p=1244</guid>
		<description><![CDATA[After over a two years of everyday development with Magento I have developed a strong feelings about the way that Magento directory structure is composed. It might sound strange or silly, but I guaranty you that Magento folder structure adds certain amount of unnecessary time to development process. What bothers me the most is the [...]]]></description>
			<content:encoded><![CDATA[<p>After over a two years of everyday development with Magento I have developed a strong feelings about the way that Magento directory structure is composed. </p>
<p>It might sound strange or silly, but I guaranty you that Magento folder structure adds certain amount of unnecessary time to development process. What bothers me the most is the way you are forced to develop &#8220;by the book&#8221; extensions. Is it the lack of vision of purposely engineered concept that forces you to span your custom modules among tens of sub-folders that in the end do not belong to your extension.<span id="more-1244"></span></p>
<p>What I would like to see is the WordPress or Drupal concept, where each extension with all of its files and logic lives in its one folder. No special view folders in main theme, no special layout folders in custom/default theme etc. Only one place/folder to host your extensions.</p>
<p>Here is my vision of extensions folder layout/structure that I find interesting and appealing.</p>
<p><img src="http://activecodeline.com/wp-content/uploads/2010/08/magento_proposed_directory_structure_for_modules.png" alt="" title="magento_proposed_directory_structure_for_modules" width="329" height="270" class="alignnone size-full wp-image-1245" /></p>
<p>Certanly this raises several questions like:</p>
<ul>
<li>Can we put javascript in this sub-folder, as it is to deep in the modules directory, is this security implication or SEO implication or, etc.</li>
<li>Can we put css in this sub-folder, as it is to deep in the modules directory, is this security implication or SEO implication or, etc.</li>
<li>Can we put style images in this sub-folder, as it is to deep in the modules directory, is this security implication or SEO implication or, etc. </li>
<li>How does this relate to my designer doing the styling, etc.</li>
<li>&#8230;</li>
</ul>
<p>Have you ever had these problems with extensions/modules for WordPress, Drupal, Joomla, etc.? I doubt that. </p>
<p>I would say that easy workaround can be made for each of the above &#8220;implications&#8221;, leaving you with &#8220;one extension &#8211; one folder&#8221; concept. </p>
<p>Concept like that is easy to maintain, plus no robust Magento Connect is needed, etc. Certainly it has its flaws, but surely does the current one.</p>
<p>Enough said, for now <img src='http://activecodeline.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  -Just a little something I have been tinkering around.</p>
]]></content:encoded>
			<wfw:commentRss>http://activecodeline.com/magento-please-change-the-extension-directory-structure/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>The Definitive Guide to Magento by Adam McCombs and Robert Banh</title>
		<link>http://activecodeline.com/the-definitive-guide-to-magento-by-adam-mccombs-and-robert-banh</link>
		<comments>http://activecodeline.com/the-definitive-guide-to-magento-by-adam-mccombs-and-robert-banh#comments</comments>
		<pubDate>Fri, 09 Jul 2010 17:15:28 +0000</pubDate>
		<dc:creator>branko</dc:creator>
				<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://activecodeline.com/?p=1129</guid>
		<description><![CDATA[Yesterday I got my hands on printed edition of &#8220;The Definitive Guide to Magento by Adam McCombs and Robert Banh&#8221; book. Our company purchased it among other few books. When it comes to IT books I am mostly skeptical, cause rarely they manage to fill in even the &#8220;a bit more advanced&#8221; sections. Given the [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I got my hands on printed edition of &#8220;The Definitive Guide to Magento by Adam McCombs and Robert Banh&#8221; book. <a href="http://inchoo.net">Our company</a> purchased it among other few books. When it comes to IT books I am mostly skeptical, cause rarely they manage to fill in even the &#8220;a bit more advanced&#8221; sections. Given the fact that this book is all about Magento my skepticism was even higher. Turned out that this book truly stands out when it comes to the stuff you can learn from it.<span id="more-1129"></span></p>
<p>Before I proceed I would like to emphasize that although the author mentions me personally in the book (on the page 210), my positive review of it is by no means result of that.</p>
<p>I would rate &#8220;Part 2: Advanced Magento development&#8221; as a must read for every Magento developer that has not yet overcome these steps. Additional bonus for the book goes on the &#8220;Apendix: API References&#8221; section that covers the use of Magento API pretty in depth. What impressed me where the &#8220;var_dump&#8221; response examples for each API call.</p>
<p>I have noticed that the book got some negative reviews, something in terms of &#8220;The Definitive Guide To Magento&#8230; really? Unless you&#8217;re the kind of person that in general has a hard time using computers, about 60% of this book is a complete waste of time in my opinion&#8230;&#8221;. Lets say I even agree with comments like these, but then again paying around $40-50 for the book is nothing compared to around $60-200/hour we take in professional Magento development. In such cases I would say this: I personally learned nothing new from this book, but several of my coworkers (junior developers) did and for that book payed off for us.</p>
<p>There is no point of me reviewing individual sections of the book here. If you are in the loop of learning Magento I would strongly recommend you purchase the book. Here are the links <a href="http://www.amazon.com/Definitive-Guide-Magento-Adam-McCombs/dp/1430272295">Amazon</a> or <a href="http://apress.com/book/view/1430272295">Apress.com</a> site.</p>
<p>Cheers.</p>
]]></content:encoded>
			<wfw:commentRss>http://activecodeline.com/the-definitive-guide-to-magento-by-adam-mccombs-and-robert-banh/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Magento vs Zend Server CE (5.0.2) &#8211; Stupid case of ZendEnabler</title>
		<link>http://activecodeline.com/magento-vs-zend-server-ce-5-0-2-stupid-case-of-zendenabler</link>
		<comments>http://activecodeline.com/magento-vs-zend-server-ce-5-0-2-stupid-case-of-zendenabler#comments</comments>
		<pubDate>Mon, 05 Jul 2010 09:55:29 +0000</pubDate>
		<dc:creator>branko</dc:creator>
				<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://activecodeline.com/?p=1121</guid>
		<description><![CDATA[Recently I bought myself a brand new 18.4 Toshiba Satellite laptop. Given the job I work on, one of the first things for me was to setup my self a web server so I can work my magic on Magento related project. At the moment I am running Windows 7 Home Premium on my laptop, [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I bought myself a brand new 18.4 Toshiba Satellite laptop. Given the job I work on, one of the first things for me was to setup my self a web server so I can work my magic on Magento related project. At the moment I am running Windows 7 Home Premium on my laptop, so I figured why not try installing Zend Server CE (5.0.2, latest as of time of this writing) on it. Figured it will be an easy job. FOr a moment I forgot that usually nothing is easy when it comes to Magento <img src='http://activecodeline.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  -I got my Zend Server CE up an running in a matter of minutes. First thing I did after the server installation was to configure all the timeouts, knowing how Magento is resource consuming.<span id="more-1121"></span></p>
<p>After initial configuration I started my Magento installation. And here is where I hit the wall. My installation was OK until it reached the step where it needed to write to database. After some running time browser would give me a &#8220;File Download&#8221; dialog with file whose content says &#8220;<strong>The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.</strong>&#8220;. My first reaction is was that I forgot to boost some timeout in the config. </p>
<p>After several minutes of tracing the issue, I finally figured that it was a &#8220;ZendEnablerApache.dll&#8221; that was causing my &#8220;unable to service your request&#8221; issue. I traced the configuration to &#8220;C:\Program Files\Zend\ZendServer\etc\ZendEnablerConf.xml&#8221; file. There I changed the <strong>connectionTimeout</strong> to 18000 and the <strong>requestTimeout</strong> to 36000. After that I restarted my Apache and was able to install Magento and do other time consuming PHP operations.</p>
<p>Hope this helps some of you who might experience the same issue.</p>
<p>Cheers.</p>
]]></content:encoded>
			<wfw:commentRss>http://activecodeline.com/magento-vs-zend-server-ce-5-0-2-stupid-case-of-zendenabler/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Programatically create attribute in Magento, useful for the &#8220;on the fly&#8221; import system</title>
		<link>http://activecodeline.com/programatically-create-attribute-in-magento-useful-for-the-on-the-fly-import-system</link>
		<comments>http://activecodeline.com/programatically-create-attribute-in-magento-useful-for-the-on-the-fly-import-system#comments</comments>
		<pubDate>Thu, 03 Jun 2010 09:22:42 +0000</pubDate>
		<dc:creator>branko</dc:creator>
				<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://activecodeline.com/?p=1113</guid>
		<description><![CDATA[Sometimes when doing an import in Magento from old shop system you are faced with lot of issues related to attributes. For instance your old shop system might have several product attributes that simply do not fit into the default Magento attributes. In such cases you need to create these attributes manually in the Magento [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes when doing an import in Magento from old shop system you are faced with lot of issues related to attributes. For instance your old shop system might have several product attributes that simply do not fit into the default Magento attributes. In such cases you need to create these attributes manually in the Magento admin, assign them to the appropriate attribute set and then construct a valid CSV file with valid column names for these new attributes.</p>
<p>When you are dealing with large shop systems, with several thousands of products, then actions like these need to be handled programatically. Below is a just a fraction of the code from the full import script I have been working on last few days.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> createAttribute<span style="color: #009900;">&#40;</span><span style="color: #000088;">$code</span><span style="color: #339933;">,</span> <span style="color: #000088;">$label</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attribute_type</span><span style="color: #339933;">,</span> <span style="color: #000088;">$product_type</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>		
	<span style="color: #000088;">$_attribute_data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'attribute_code'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'old_site_attribute_'</span><span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$product_type</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$product_type</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'joint'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'_'</span><span style="color: #339933;">.</span><span style="color: #000088;">$code</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'is_global'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'frontend_input'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$attribute_type</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">//'boolean',</span>
		<span style="color: #0000ff;">'default_value_text'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'default_value_yesno'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'0'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'default_value_date'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'default_value_textarea'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'is_unique'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'0'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'is_required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'0'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'apply_to'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$product_type</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">//array('grouped')</span>
		<span style="color: #0000ff;">'is_configurable'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'0'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'is_searchable'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'0'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'is_visible_in_advanced_search'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'0'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'is_comparable'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'0'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'is_used_for_price_rules'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'0'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'is_wysiwyg_enabled'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'0'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'is_html_allowed_on_front'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'is_visible_on_front'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'0'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'used_in_product_listing'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'0'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'used_for_sort_by'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'0'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'frontend_label'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Old Site Attribute '</span><span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$product_type</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$product_type</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'joint'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">.</span><span style="color: #000088;">$label</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #000088;">$model</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;">'catalog/resource_eav_attribute'</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: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_attribute_data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'is_configurable'</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;">$_attribute_data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'is_configurable'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</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;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_attribute_data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'is_filterable'</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;">$_attribute_data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'is_filterable'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</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;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_attribute_data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'is_filterable_in_search'</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;">$_attribute_data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'is_filterable_in_search'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</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;">is_null</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getIsUserDefined</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;">$model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getIsUserDefined</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;">$_attribute_data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'backend_type'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getBackendTypeByInput</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_attribute_data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'frontend_input'</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: #000088;">$defaultValueField</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDefaultValueByInput</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_attribute_data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'frontend_input'</span><span style="color: #009900;">&#93;</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;">$defaultValueField</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$_attribute_data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'default_value'</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;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParam</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$defaultValueField</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #000088;">$model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addData</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_attribute_data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setEntityTypeId</span><span style="color: #009900;">&#40;</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'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'catalog_product'</span><span style="color: #009900;">&#41;</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;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setIsUserDefined</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	try <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$model</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>
	<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: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;p&gt;Sorry, error occured while trying to save the attribute. Error: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/p&gt;'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The import I was running had to deal with grouped and simple products (that go on that grouped products). Besides special attributes that only grouped products had, and some special attributes that only simple products have, system also had some &#8220;joint&#8221; attributes that both of the product types had. Examples below show how I called the above method to generate such specific or &#8220;joint&#8221; attributes.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//My &quot;grouped product only&quot; attribute</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ShirtType&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;ShirtType&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;select&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;grouped&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">//My &quot;simple product only&quot; attribute</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Swatch&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Swatch&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;text&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;simple&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">//My &quot;joint&quot; attribute, the one that I had both on simple and on grouped products</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;InventoryMsg&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;InventoryMsg&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;text&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Complete&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Complete&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;boolean&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Hope that above example help someone. Cheers.</p>
]]></content:encoded>
			<wfw:commentRss>http://activecodeline.com/programatically-create-attribute-in-magento-useful-for-the-on-the-fly-import-system/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Simple example on how to programatically create two level categories in Magento</title>
		<link>http://activecodeline.com/simple-example-on-how-to-programatically-create-two-level-categories-in-magento</link>
		<comments>http://activecodeline.com/simple-example-on-how-to-programatically-create-two-level-categories-in-magento#comments</comments>
		<pubDate>Thu, 03 Jun 2010 09:07:29 +0000</pubDate>
		<dc:creator>branko</dc:creator>
				<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://activecodeline.com/?p=1108</guid>
		<description><![CDATA[Recently I have been working on a new site that has large number of products and not so little number of categories. As you all know, Magento import system is somewhat obscure, does not seem to allow you a lot in terms of modifications. You are bound to creating a proper CSV file in order [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I have been working on a new site that has large number of products and not so little number of categories. As you all know, Magento import system is somewhat obscure, does not seem to allow you a lot in terms of modifications. You are bound to creating a proper CSV file in order to do a valid import. One of the difficulties with such system often comes down to &#8220;how do I transfer all my categories&#8221; or &#8220;how to I transfer all my images&#8221; from old shop system to Magento. My so far practice has simple answer on that: Sometimes, there just isn&#8217;t any simply solution. Sometimes you will waste hours of coding just to build a proper CSV file that will later be passed to the import system.<span id="more-1108"></span></p>
<p>This shop I was working on was relatively &#8220;flat&#8221; in its architecture. Flat in terms that it had just a few tables, with not so great &#8220;normalization&#8221;. However, this &#8220;flat&#8221; architecture produced a lightning fast web shop with speed of page loading that Magento can most of the time dream of, unless placed on truly quality server.</p>
<p>So, how do we transfer the categories from old shop system to the Magento. We all know that Magento CSV file requires category id&#8217;s to be placed in the appropriate CSV column. That means we need to have our categories created in front. Here is a simple example on how to programatically create two level categories in Magento.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> createCategories<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">//The root category in Magento, the one you get by default install, usually has the id 2</span>
	<span style="color: #000088;">$_rootParentCat</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span> 
&nbsp;
	<span style="color: #666666; font-style: italic;">/* START Create first level categories */</span>
	<span style="color: #000088;">$_rootCats</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_db<span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchCol</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT DISTINCT ProductCategory1 FROM SomeProductCategoryTable&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_rootCats</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$_rootCat</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$_c</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_db<span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchOne</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT ProductCategory1URL FROM SomeProductCategoryTable WHERE ProductCategory1 = ?&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_rootCat</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_c</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$_c</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'na'</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$_cat</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Mage_Catalog_Model_Category<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$_cat</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setName</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_rootCat</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$_cat</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setUrlKey</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$_cat</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setIsActive</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000088;">$parentCategory</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;">'catalog/category'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_rootParentCat</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$_cat</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setPath</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$parentCategory</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>				
&nbsp;
			<span style="color: #000088;">$_cat</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>
			Zend_Debug<span style="color: #339933;">::</span><span style="color: #004000;">dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">/* START Create second level categories */</span>	
			<span style="color: #000088;">$_childCats</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_db<span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchCol</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT DISTINCT ProductCategory2 FROM SomeProductCategoryTable WHERE ProductCategory1 = ?&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_rootCat</span><span style="color: #009900;">&#41;</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;">$_childCats</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$_childCat</span><span style="color: #009900;">&#41;</span> 
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$_cc</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_db<span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchOne</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT ProductCategory2URL FROM SomeProductCategoryTable WHERE ProductCategory2 = ?&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_childCat</span><span style="color: #009900;">&#41;</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;">$_cc</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$_cc</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'na'</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$_catChild</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Mage_Catalog_Model_Category<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$_catChild</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setName</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_childCat</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$_catChild</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setUrlKey</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_cc</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$_catChild</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setIsActive</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
					<span style="color: #000088;">$parentCategory</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;">'catalog/category'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_cat</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;">$_catChild</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setPath</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$parentCategory</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>							
&nbsp;
					<span style="color: #000088;">$_catChild</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>	
					Zend_Debug<span style="color: #339933;">::</span><span style="color: #004000;">dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_cc</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;">$_catChild</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: #666666; font-style: italic;">/* END Create second level categories */</span>
			<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_cat</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #666666; font-style: italic;">/* END Create first level categories */</span>
&nbsp;
&nbsp;
	<span style="color: #009933; font-style: italic;">/** Zend_Debug::dump($c-&gt;debug());
		array(25) {
		  [&quot;entity_id&quot;] =&gt; string(1) &quot;3&quot;
		  [&quot;entity_type_id&quot;] =&gt; string(1) &quot;3&quot;
		  [&quot;attribute_set_id&quot;] =&gt; string(1) &quot;3&quot;
		  [&quot;parent_id&quot;] =&gt; string(1) &quot;2&quot;
		  [&quot;created_at&quot;] =&gt; string(19) &quot;2010-05-24 12:14:56&quot;
		  [&quot;updated_at&quot;] =&gt; string(19) &quot;2010-05-24 17:02:17&quot;
		  [&quot;path&quot;] =&gt; string(5) &quot;1/2/3&quot;
		  [&quot;position&quot;] =&gt; string(1) &quot;1&quot;
		  [&quot;level&quot;] =&gt; string(1) &quot;2&quot;
		  [&quot;children_count&quot;] =&gt; string(1) &quot;0&quot;
		  [&quot;name&quot;] =&gt; string(6) &quot;Sample&quot;
		  [&quot;url_key&quot;] =&gt; string(6) &quot;sample&quot;
		  [&quot;meta_title&quot;] =&gt; string(0) &quot;&quot;
		  [&quot;display_mode&quot;] =&gt; string(8) &quot;PRODUCTS&quot;
		  [&quot;custom_design&quot;] =&gt; string(0) &quot;&quot;
		  [&quot;page_layout&quot;] =&gt; string(0) &quot;&quot;
		  [&quot;url_path&quot;] =&gt; string(6) &quot;sample&quot;
		  [&quot;is_active&quot;] =&gt; string(1) &quot;1&quot;
		  [&quot;is_anchor&quot;] =&gt; string(1) &quot;0&quot;
		  [&quot;custom_design_apply&quot;] =&gt; string(1) &quot;1&quot;
		  [&quot;description&quot;] =&gt; string(21) &quot;Sample category here.&quot;
		  [&quot;meta_keywords&quot;] =&gt; string(0) &quot;&quot;
		  [&quot;meta_description&quot;] =&gt; string(38) &quot;Meta Sample category description here.&quot;
		  [&quot;custom_layout_update&quot;] =&gt; string(0) &quot;&quot;
		  [&quot;available_sort_by&quot;] =&gt; string(0) &quot;&quot;
		}
	 */</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Please not that the example above is not generally applicable. You will notice that I used it to programatically create only the two level category system. Thus, the example is not to be used as simply &#8220;copy-paste&#8221;.</p>
<p>Depending on the size (number) of the categories in the old shop, programatically in place of manually creating categories can save you great deal of time.</p>
<p>Hope that above example helps to some of you (to certain extent).</p>
]]></content:encoded>
			<wfw:commentRss>http://activecodeline.com/simple-example-on-how-to-programatically-create-two-level-categories-in-magento/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to limit the number of allowed images per single product in Magento</title>
		<link>http://activecodeline.com/how-to-limit-the-number-of-allowed-images-per-single-product-in-magento</link>
		<comments>http://activecodeline.com/how-to-limit-the-number-of-allowed-images-per-single-product-in-magento#comments</comments>
		<pubDate>Tue, 18 May 2010 20:02:28 +0000</pubDate>
		<dc:creator>branko</dc:creator>
				<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://activecodeline.com/?p=1102</guid>
		<description><![CDATA[Recently I have been playing around with Magento with the concept of limiting the number of images that admin can upload per single product. There are several reasons why you might need this kind of functionality. I will not go into them. Solution for this request is pretty straightforward and easy. It can be done [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I have been playing around with Magento with the concept of limiting the number of images that admin can upload per single product. There are several reasons why you might need this kind of functionality. I will not go into them. Solution for this request is pretty straightforward and easy. It can be done in just a few lines of code.<span id="more-1102"></span></p>
<p>Here is how.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> saveAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">/* START: Handle the max images per product */</span>
	<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPost</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$images</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;">'core'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">jsonDecode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'product'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'media_gallery'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'images'</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;">$totalImages</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$images</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000088;">$maxPhotoPerProduct</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$totalImages</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$maxPhotoPerProduct</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core/session'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addError</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Max. number of images per product reached, extra images have been removed'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000088;">$_allowedImages</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_slice</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$images</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$maxPhotoPerProduct</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//Return the allowed images back to the $_POST</span>
		<span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'product'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'media_gallery'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'images'</span><span style="color: #009900;">&#93;</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;">'core'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">jsonEncode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_allowedImages</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span>
	<span style="color: #666666; font-style: italic;">/* END: Handle the max images per product */</span>
	<span style="color: #666666; font-style: italic;">//Zend_Debug::dump(Mage::helper('core')-&gt;jsonDecode($_POST['product']['media_gallery']['images'])); exit;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Run standard saveAction()</span>
	parent<span style="color: #339933;">::</span><span style="color: #004000;">saveAction</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Note that code above is from my Mycompany_Mymodule_Adminhtml_Catalog_ProductController class located in the &#8220;app/code/local/Mycompany/Mymodule/controllers/Adminhtml/Catalog/ProductController.php&#8221; file. </p>
<p>Meaning I overwrote the default &#8220;app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php&#8221; controller by using the syntax shown below in Mymodule config.xml file.</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;sintax</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>Mycompany_Mymodule_Adminhtml<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sintax<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>

<p>And thats it.</p>
]]></content:encoded>
			<wfw:commentRss>http://activecodeline.com/how-to-limit-the-number-of-allowed-images-per-single-product-in-magento/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why you need Magento developer if you plan on using Magento API</title>
		<link>http://activecodeline.com/why-you-need-magento-developer-if-you-plan-on-using-magento-api</link>
		<comments>http://activecodeline.com/why-you-need-magento-developer-if-you-plan-on-using-magento-api#comments</comments>
		<pubDate>Sat, 15 May 2010 08:30:59 +0000</pubDate>
		<dc:creator>branko</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[Magento-Android]]></category>

		<guid isPermaLink="false">http://activecodeline.com/?p=1095</guid>
		<description><![CDATA[The full title should probably go something like &#8220;Why you need Magento developer if you plan on using Magento API from a Java or any other non PHP platform&#8221;. For the last few days I have been playing around with my cool new Android phone, HTC Desire. Given the experience I have with everyday Magetno [...]]]></description>
			<content:encoded><![CDATA[<p>The full title should probably go something like &#8220;Why you need Magento developer if you plan on using Magento API from a Java or any other non PHP platform&#8221;.</p>
<p>For the last few days I have been playing around with my cool new Android phone, <a href="http://www.htc.com/www/product/desire/overview.html">HTC Desire</a>. Given the experience I have with everyday Magetno development (for the last 2 years as of this moment), it was natural for me to try poking around the Magento API and do some XMLRPC based apps on Android phone.<span id="more-1095"></span></p>
<p>As most of you know, Android apps are Java based, while Magento is PHP based. Not a problem since we are using an XMLRPC. Right?</p>
<p>Well, it turned out it can be serious problem. Not because of the different technologies, but because of the lacking API documentation. For example, if you go to <a href="http://www.magentocommerce.com/wiki/doc/webservices-api/api/customer#customer.create"><strong>customer.create</strong></a> method definition in Magento API you can see its argument list. It says: &#8220;<strong>Arguments: array customerData &#8211; cutomer data (email, firstname, lastname, etc&#8230;)</strong>&#8220;. </p>
<p>I almost fall off the chair laughing when I saw the &#8220;<strong>etc&#8230;</strong>&#8221; part in the argument list. I mean, what is this, a poetry or technical document? How should a non PHP programmer that did not work with Magento know what this &#8220;etc&#8230;&#8221; stands for, and what is the full list of parameters that one can attach to &#8220;Customer&#8221; object?</p>
<p>I managed to &#8220;pass by&#8221; this kind of things by first doing this XMLRPC stuff from PHP and checking on the the returned parameters. While prior to that I did a loading of objects trough standard Magento model and doing a<br />
$model->debug() to see what kind of &#8220;params/attributes&#8221; I have at my disposal. After that I simply &#8220;copied&#8221; my logic to my Android app. And it works like a charm. But my point is, that if I had no clue on Magento, and was only relying on the API documentation, while doing my Java based app, I would most likely had a rough day handling it.</p>
<p>Anyhow&#8230;. just wanted to share some of my bitterness on this topic. Feel free to comment, dispute me&#8230; Cheers.</p>
]]></content:encoded>
			<wfw:commentRss>http://activecodeline.com/why-you-need-magento-developer-if-you-plan-on-using-magento-api/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to activate/deactivate Magento module per a website level</title>
		<link>http://activecodeline.com/how-to-activate-deactivate-magento-module-per-a-website-level</link>
		<comments>http://activecodeline.com/how-to-activate-deactivate-magento-module-per-a-website-level#comments</comments>
		<pubDate>Sun, 18 Apr 2010 09:21:19 +0000</pubDate>
		<dc:creator>branko</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[module]]></category>

		<guid isPermaLink="false">http://activecodeline.com/?p=1061</guid>
		<description><![CDATA[First off let me just clearly say that I am not talking about just activating/deactivating a module output per a website level. Module output merely disables toHtml() method that certain module block class implements. In this article I am talking about fully deactivating the module like when we open the modules config xml file and [...]]]></description>
			<content:encoded><![CDATA[<p>First off let me just clearly say that I am not talking about just activating/deactivating a module output per a website level. Module output merely <em>disables</em> toHtml() method that certain module block class implements. In this article I am talking about fully deactivating the module like when we open the modules config xml file and place &lt;active&gt;true&lt;/active&gt;.<span id="more-1061"></span></p>
<p>When we place &lt;active&gt;true&lt;/active&gt; it means is that our module is fully turned off. In such case, if some external module calls our models (classes) we will get error or some sort of exception. Reason for this is that class autoloader does not load anything trough &#8220;<em>Mage::getModel(&#8216;something/something&#8217;);</em>&#8221; if this &#8220;something&#8221; is defined as model in config file from module that is turned off by &lt;active&gt;true&lt;/active&gt;.</p>
<p>So, when would we like to turn off a module per a website level?! Imagine you are running a Magento that server as your own personal private hosted shop solution. On website A and C you want to have a cool JavaScript zoom module that shows awesome zoom feature on product photos. On site B you wish to have a different zoomer coded entirely by different JS framework etc. Something like this can easily be done just by modifying the theme files or setting up a partially different theme for this website where only difference would be in one or two layout xml files that would load up different JavaScript etc.</p>
<p>Besides doing a special theme/layout changes would it not be nice if you can simply say: Turn the Zoomer1 on website A and C and Zoomer2 on website B?! Maybe theme changes are not best fit to describe the possible convenience of having ModuleX turned on on websites A and C and ModuleY on website B. However, for those interested in such possibilities (scenario), here is a possible way of doing it.</p>
<p>First thing we need to do is to modify the <em>app\code\core\Mage\Core\Model\Config.php</em> file. Given that we do not modify the core file in order to avoid upgrade overwrite, we will make a copy of this file in <em>app\code\local\Mage\Core\Model\Config.php</em>.</p>
<p>In this file I will add the method with the content of code as show below.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #009933; font-style: italic;">/** Start: Per website module on/off */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> handleModulesPerWebsite<span style="color: #009900;">&#40;</span><span style="color: #000088;">$moduleFiles</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;">$options</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOptions</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>
&nbsp;
        	<span style="color: #000088;">$websiteCode</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'website'</span><span style="color: #339933;">;</span>
&nbsp;
        	<span style="color: #000088;">$mageRunCode</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getData</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mageRunCode'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        	<span style="color: #000088;">$mageRunType</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getData</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mageRunType'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        	<span style="color: #666666; font-style: italic;">//Check if we are running a valid website</span>
        	<span style="color: #666666; font-style: italic;">//if($mageRunType == $websiteCode) {</span>
&nbsp;
        		<span style="color: #000088;">$xml</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_file</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'S:\Server\apps\shop\srv_staging\modules.xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        		<span style="color: #000088;">$modules</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_keys</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#41;</span><span style="color: #000088;">$xml</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        		<span style="color: #000088;">$moduleFilesX</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$moduleFiles</span><span style="color: #339933;">;</span>
	        	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$moduleFilesX</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$k</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$moduleFile</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	        		<span style="color: #000088;">$s</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;">$moduleFile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	        		<span style="color: #000088;">$moduleName</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.xml'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #990000;">end</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #666666; font-style: italic;">//Turn off all the other modules that are not listed in modules.php file	        		</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;">$moduleName</span><span style="color: #339933;">,</span> <span style="color: #000088;">$modules</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;">$moduleFiles</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</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>    
		        <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$moduleFilesX</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
        	<span style="color: #666666; font-style: italic;">//}</span>
        	<span style="color: #666666; font-style: italic;">//Zend_Debug::dump($moduleFiles);</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$moduleFiles</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
    <span style="color: #009933; font-style: italic;">/** End: Per website module on/off */</span></pre></div></div>

<p>Highly important thing to note here. As you can see I have hard-coded the &#8220;S:\Server\apps\shop\srv_staging\modules.xml&#8221; path to one specific website folder. If you choose to play with this code, please modify it to do some current website path check and include only the <em>modules.xml</em> file from the currently viewed website on frontend.</p>
<p>And I will modify the existing &#8220;<em>protected function _getDeclaredModuleFiles()</em>&#8221; method to include a call towards my new method like shown below in code.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/** 
 * Start: Custom addded, calls the new Non-Magento method, 
 coded to do turn-off of modules per website. 
 * Place right below the $collectModuleFiles['custom'] variable definition.
*/</span>
<span style="color: #000088;">$collectModuleFiles</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'custom'</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;">handleModulesPerWebsite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$collectModuleFiles</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'custom'</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;">/** 
 * End: Custom addded, calls the new Non-Magento method, 
 coded to do turn-off of modules per website. 
 * Place right below the $collectModuleFiles['custom'] variable definition.
*/</span></pre></div></div>

<p>Here is the full view of the modified &#8220;<em>protected function _getDeclaredModuleFiles()</em>&#8221; method.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">    protected <span style="color: #000000; font-weight: bold;">function</span> _getDeclaredModuleFiles<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span> 	
        <span style="color: #000088;">$etcDir</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOptions</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getEtcDir</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$moduleFiles</span> <span style="color: #339933;">=</span> <span style="color: #990000;">glob</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$etcDir</span> <span style="color: #339933;">.</span> DS <span style="color: #339933;">.</span> <span style="color: #0000ff;">'modules'</span> <span style="color: #339933;">.</span> DS <span style="color: #339933;">.</span> <span style="color: #0000ff;">'*.xml'</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: #339933;">!</span><span style="color: #000088;">$moduleFiles</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$collectModuleFiles</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'base'</span>   <span style="color: #339933;">=&gt;</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: #0000ff;">'mage'</span>   <span style="color: #339933;">=&gt;</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: #0000ff;">'custom'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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;">$moduleFiles</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">DIRECTORY_SEPARATOR</span><span style="color: #339933;">,</span> <span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#91;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">4</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;">$name</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'Mage_All'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$collectModuleFiles</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'base'</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;">$v</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'Mage_'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$collectModuleFiles</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'mage'</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;">$v</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;">$collectModuleFiles</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'custom'</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;">$v</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #009933; font-style: italic;">/** 
         * Start: Custom addded, calls the new Non-Magento method, 
coded to do turn-off of modules per website. 
         * Place right below the $collectModuleFiles['custom'] variable definition.
		*/</span>
        <span style="color: #000088;">$collectModuleFiles</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'custom'</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;">handleModulesPerWebsite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$collectModuleFiles</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'custom'</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;">/** 
         * End: Custom addded, calls the new Non-Magento method, 
coded to do turn-off of modules per website. 
         * Place right below the $collectModuleFiles['custom'] variable definition.
		*/</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span>
            <span style="color: #000088;">$collectModuleFiles</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'base'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
            <span style="color: #000088;">$collectModuleFiles</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'mage'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
            <span style="color: #000088;">$collectModuleFiles</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'custom'</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></div></div>

<p>With the above changes in place we now have a basic mechanism of removing unwanted custom modules from globally merged config file.</p>
<p>Next, we will create a new website in Magento under the &#8220;System > Manage Stores&#8221; admin section. Lets say we give this site a code name &#8220;staging&#8221; and we create a folder called &#8220;srv_staging&#8221; in our root Magento installation folder. For instance if my Magento is installed under the &#8220;<em>S:\Server\apps\shop\</em>&#8221; then I will place my new website in the &#8220;<em>S:\Server\apps\shop\srv_staging\</em>&#8221; folder. Keep in mind that when you are doing a multiple websites setup in Magento it is not necessary to set your other websites in a subfolder of root Magento. If you are not on top of the &#8220;<a href="http://www.crucialwebhost.com/blog/how-to-setup-multiple-magento-stores/">How To Setup Multiple Magento Stores</a>&#8221; topic then please skip this article.</p>
<p>Moving on, now we have a &#8220;<em>S:\Server\apps\shop\srv_staging\</em>&#8221; folder from which we will run our second website. Reason why I place my second website in the sub-folder of root Magento is simply to avoid playing around with virtual hosts in this example. That way I can do <em>http://shop.local/srv_staging/</em> and go to my &#8220;staging&#8221; website given that <em>http://shop.local/</em> points to my default base website.</p>
<p>In order for our &#8220;Aactivate/Deactivate Magento module per a website level&#8221; mechanism to work we will need a partially different call for &#8220;<em>Mage:.run</em>&#8221; in our &#8220;<em>S:\Server\apps\shop\srv_staging\index.php</em>&#8221; file.</p>
<p>Here is how it should look (at least for my example and the code above):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Mage<span style="color: #339933;">::</span><span style="color: #004000;">run</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mageRunCode</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mageRunType</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mageRunCode'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$mageRunCode</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mageRunType'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$mageRunType</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And for the grand finale, here is the new additional file you can place in the S:\Server\apps\shop\srv_staging\modules.xml file, with a sample content like shown below.</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: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ActiveModules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Ajzele_Resourcer</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Ajzele_Qrcode</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ActiveModules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>All the module names declared within ActiveModules tag in this XML file are the names of the custom (community/local) modules we wish to turn on for this website. In my case I said: Turn on the Ajzele_Resourcer  and Ajzele_Qrcode modules for the &#8220;staging&#8221; website.</p>
<p>That&#8217;s it. These little modifications and additions should enable you to have &#8220;Aactivate/Deactivate Magento module per a website level&#8221; mechanism.</p>
<p>Please note that this code and approach entirely are highly experimental. Thus, try not to use them in any live sites. My intention was merely to give you something to think about in case you need something like this.</p>
<p>Also, additional info, this experiment was done on Magento 1.4.0.1.</p>
<p>Cheers.</p>
]]></content:encoded>
			<wfw:commentRss>http://activecodeline.com/how-to-activate-deactivate-magento-module-per-a-website-level/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
