<?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>Sycha Web Design &#38; Development &#187; Magento Ecommerce Tips, Tutorials and Extensions</title>
	<atom:link href="http://www.sycha.com/resources/web-development/magento-development/feed" rel="self" type="application/rss+xml" />
	<link>http://www.sycha.com</link>
	<description>Website Design &#38; Development</description>
	<lastBuildDate>Mon, 09 May 2011 09:59:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Magento Performance Boost: Enable Log Cleaning</title>
		<link>http://www.sycha.com/magento-performance-boost-enable-log-cleaning</link>
		<comments>http://www.sycha.com/magento-performance-boost-enable-log-cleaning#comments</comments>
		<pubDate>Mon, 09 May 2011 09:56:22 +0000</pubDate>
		<dc:creator>Charlie Evans</dc:creator>
				<category><![CDATA[Magento Development]]></category>

		<guid isPermaLink="false">http://www.sycha.com/?p=1459</guid>
		<description><![CDATA[Magento has automated log cleaning functionality built in, but it is not enabled by default. Here's how to turn it on.]]></description>
			<content:encoded><![CDATA[<p>Magento stores a lot of logging information in the database tables prefixed with log_<br />
e.g. log_visitor_info, log_url_info, etc. As with <a href="/magento-performance-boost-cleanup-old-session-files">Magento&#8217;s session files</a>, if not handled properly, these tables will grow out of control and hinder performance.</p>
<p>Magento has automated log cleaning functionality built in, but it is not enabled by default. Here&#8217;s how to turn it on.</p>
<ol>
<li>Firstly you need make sure Magento&#8217;s cron system is running.<br />
If you are unsure about this, see this article on <a href="/magento-tip-setting-up-cron-scheduled-tasks">setting up cron (scheduled tasks)</a>.</li>
<li>Once cron is enabled and running, simply enable log cleaning via the admin:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">System <span style="color: #000000; font-weight: bold;">&gt;</span> Configuration <span style="color: #000000; font-weight: bold;">&gt;</span> Advanced <span style="color: #000000; font-weight: bold;">&gt;</span> System <span style="color: #000000; font-weight: bold;">&gt;</span> Log Cleaning</pre></div></div>

</li>
</ol>
<p>As per the screenshot below, I like to save 1 days logs, and perform the cleaning at 4:00am each morning.</p>
<p><img src="http://www.sycha.com/wp-content/uploads/2011/05/log-cleaning.png" alt="" title="Magento Log Cleaning" width="517" height="260" class="aligncenter size-full wp-image-1460" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sycha.com/magento-performance-boost-enable-log-cleaning/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Magento Performance Boost: Cleanup Old Session Files</title>
		<link>http://www.sycha.com/magento-performance-boost-cleanup-old-session-files</link>
		<comments>http://www.sycha.com/magento-performance-boost-cleanup-old-session-files#comments</comments>
		<pubDate>Mon, 09 May 2011 09:51:09 +0000</pubDate>
		<dc:creator>Charlie Evans</dc:creator>
				<category><![CDATA[Magento Development]]></category>

		<guid isPermaLink="false">http://www.sycha.com/?p=1456</guid>
		<description><![CDATA[If left unchecked, Magento session files can grow out of control and have a negative impact on your sites performance (aswell as taking up storage space). This article explains how to make sure old session files are removed automatically.]]></description>
			<content:encoded><![CDATA[<p>If left unchecked, Magento session files can grow out of control and have a negative impact on your sites performance (aswell as taking up storage space). This article explains how to make sure old session files are removed automatically.</p>
<p>Magento stores it&#8217;s session files in var/session and I&#8217;ve seen too many Magento installations where the size of this directory has grown into the gigabytes. A quick browse of this directory should tell you whether you have a problem or not.</p>
<p>PHP has it&#8217;s own &#8216;garbage collection&#8217; process for deleting old session files, but it&#8217;s disabled in Debian &#8220;due to the strict permissions on /var/lib/php5&#8243;<br />
So, if you are using Debian then you&#8217;ll need to setup a simple cron script to do this garbage collection for you.</p>
<p>For this example, let&#8217;s say the path to your Magento installation is <strong>/path/to/magento</strong> and we want to delete session files over a week old.</p>
<ol>
<li>Create a new file /path/to/magento/session_cleanup.sh

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>magento<span style="color: #000000; font-weight: bold;">/</span>session_cleanup.sh</pre></div></div>

</li>
<li>Add the following 2 lines to the file

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>magento<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>session <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'sess_*'</span> <span style="color: #660033;">-type</span> f <span style="color: #660033;">-mtime</span> +<span style="color: #000000;">7</span> <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \;</pre></div></div>

</li>
<li>Make sure the file is executable

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> u+x <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>magento<span style="color: #000000; font-weight: bold;">/</span>session_cleanup.sh</pre></div></div>

</li>
<li>Now add it to your crontab

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">crontab <span style="color: #660033;">-e</span></pre></div></div>

<p>and set it to run every day, let&#8217;s say at 3am</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">0</span> <span style="color: #000000;">3</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span>  <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">sh</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>magento<span style="color: #000000; font-weight: bold;">/</span>session_cleanup.sh</pre></div></div>

</li>
</ol>
<p>And we&#8217;re done.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sycha.com/magento-performance-boost-cleanup-old-session-files/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Magento Tip: Setting Up Cron (Scheduled Tasks)</title>
		<link>http://www.sycha.com/magento-tip-setting-up-cron-scheduled-tasks</link>
		<comments>http://www.sycha.com/magento-tip-setting-up-cron-scheduled-tasks#comments</comments>
		<pubDate>Mon, 09 May 2011 09:33:13 +0000</pubDate>
		<dc:creator>Charlie Evans</dc:creator>
				<category><![CDATA[Magento Development]]></category>

		<guid isPermaLink="false">http://www.sycha.com/?p=1448</guid>
		<description><![CDATA[Magento has it's own cron (scheduled tasks) system which handles such things as newsletter sends, sitemap generation and database log cleaning. To activate this system, you need to set up a cron job on the server to run Magento's cron script at a regular interval.]]></description>
			<content:encoded><![CDATA[<p>Magento has it&#8217;s own cron (scheduled tasks) system which handles such things as newsletter sends, sitemap generation and database log cleaning. To activate this system, you need to set up a cron job on the server to run Magento&#8217;s cron script at a regular interval.</p>
<p>Magento provides a shell script (cron.sh) which calls a PHP script (cron.php)<br />
Both files are in the root directory of the Magento installation.<br />
I like to bypass the shell script and run the PHP script directly, and I set it to run every 5 mins</p>
<p>To do this in Debian, you should open your crontab for editing:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">crontab <span style="color: #660033;">-e</span></pre></div></div>

<p>Then add a crontab entry such as this (replacing with your path):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">*/</span><span style="color: #000000;">5</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> php <span style="color: #660033;">-q</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>magento<span style="color: #000000; font-weight: bold;">/</span>cron.php</pre></div></div>

<p>The default cron scheduling settings work fine for me but you can tweak them if you like to have more control:</p>
<pre>System > Configuration > Advanced > System > Cron (Scheduled Tasks)</pre>
<p><img src="http://www.sycha.com/wp-content/uploads/2011/05/cron1.png" alt="" title="Magento Default Cron Settings" width="521" height="257" class="aligncenter size-full wp-image-1452" /></p>
<p>Note: A quick way to test your setup is to check the database table called <strong>cron_schedule</strong>. If cron is running, this table will have records in it. Remember to wait 5 mins after adding the crontab entry so it has a chance to run <img src='http://www.sycha.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.sycha.com/magento-tip-setting-up-cron-scheduled-tasks/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Magento: Enable Terms &amp; Conditions checkbox at Checkout</title>
		<link>http://www.sycha.com/magento-terms-conditions-checkout</link>
		<comments>http://www.sycha.com/magento-terms-conditions-checkout#comments</comments>
		<pubDate>Tue, 12 Oct 2010 00:01:03 +0000</pubDate>
		<dc:creator>Charlie Evans</dc:creator>
				<category><![CDATA[Magento Development]]></category>

		<guid isPermaLink="false">http://www.sycha.com/?p=1340</guid>
		<description><![CDATA[A very common requirement for online shop owners is to force the customer to accept their terms and conditions before placing an order. When a client requested this recently, I was happy to find that Magento has this functionality built in, meaning time saved and no custom coding. It just requires some setting up in the admin, here's how.]]></description>
			<content:encoded><![CDATA[<p>A very common requirement for online shop owners is to force the customer to accept their terms and conditions before placing an order. When a client requested this recently, I was happy to find that Magento has this functionality built in, meaning time saved and no custom coding. It just requires some setting up in the admin, here&#8217;s how.</p>
<p>In your admin go to:</p>
<pre>Menu > System > Configuration > Sales > Checkout > Checkout Options</pre>
<ol>
<li>Set &#8220;Enable Terms and Conditions&#8221; to &#8220;Yes&#8221;</li>
<li>Click &#8220;Save Config&#8221;</li>
</ol>
<p>Next, go to:</p>
<pre>Menu > Sales > Terms and conditions</pre>
<ol>
<li>Click &#8220;Add New Condition&#8221;</li>
<li>Fill in the required fields
<ul>
<li>&#8220;Condition Name&#8221; is only shown in the admin so can be whatever you want.</li>
<li>Set &#8220;Status&#8221; to &#8220;Enabled&#8221;</li>
<li>Set &#8220;Show content as&#8221; to &#8220;HTML&#8221; if you want to stylize the content or have links</li>
<li>&#8220;Checkbox text&#8221; will be shown next to the checkbox, e.g. &#8220;I accept the terms and conditions&#8221;</li>
<li>&#8220;Content&#8221; will be shown in a scrolling text area above the checkbox. This could be your entire terms and conditions or a link to your terms and conditions page.</li>
</ul>
</li>
<li>Click &#8220;Save Condition&#8221;</li>
</ol>
<p>You&#8217;re all done. The terms and conditions text and checkbox will now show on the final step of the checkout. Customers will be required to check the checkbox before they can place an order. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.sycha.com/magento-terms-conditions-checkout/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Magento: Disable unwanted modules / features via the admin</title>
		<link>http://www.sycha.com/magento-disable-unwanted-modules-via-admin</link>
		<comments>http://www.sycha.com/magento-disable-unwanted-modules-via-admin#comments</comments>
		<pubDate>Wed, 06 Oct 2010 20:06:57 +0000</pubDate>
		<dc:creator>Charlie Evans</dc:creator>
				<category><![CDATA[Magento Development]]></category>

		<guid isPermaLink="false">http://www.sycha.com/?p=1265</guid>
		<description><![CDATA[You may want to "turn off" certain modules in Magento because you don't use them in your store. Examples of unwanted modules could be Customer Wishlist, Product Tags, Reviews, etc etc
]]></description>
			<content:encoded><![CDATA[<p>You may want to &#8220;turn off&#8221; certain modules in Magento because you don&#8217;t use them in your store. Examples of unwanted modules could be Customer Wishlist, Product Tags, Reviews, etc etc</p>
<p>A recent client of ours didn&#8217;t want the Wishlist feature to show up anywhere.. This includes the customer account sidebar, the product view and the category listing pages.</p>
<p>Rather than hunting through and editing templates, there&#8217;s a simple way to disable modules so they don&#8217;t display on your site.</p>
<p>In your admin, go to:</p>
<pre>Menu > System > Configuration > Advanced > Advanced</pre>
<p>Here you will see a list of all your installed modules:</p>
<ol>
<li>Find the one you are after, e.g. Mage_Wishlist</li>
<li>Change the drop box to &#8220;Disable&#8221;</li>
<li>Click &#8220;Save Config&#8221;</li>
</ol>
<p>And you&#8217;re all done. Too easy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sycha.com/magento-disable-unwanted-modules-via-admin/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento Tip: Debugging and development using log files</title>
		<link>http://www.sycha.com/magento-tip-debugging-development-log-files</link>
		<comments>http://www.sycha.com/magento-tip-debugging-development-log-files#comments</comments>
		<pubDate>Sat, 11 Sep 2010 01:44:07 +0000</pubDate>
		<dc:creator>Charlie Evans</dc:creator>
				<category><![CDATA[Magento Development]]></category>

		<guid isPermaLink="false">http://www.sycha.com/?p=1336</guid>
		<description><![CDATA[Just a short sweet tip that will be essential as soon as you dive into any sort of debugging or development with Magento. Enable logging in the admin then use the static method log() to record information.]]></description>
			<content:encoded><![CDATA[<p>Just a short sweet tip that will be essential as soon as you dive into any sort of debugging or development with Magento. Enable logging in the admin then use the static method log() to record information.</p>
<p>Enable logging in the admin:</p>
<pre>Menu > System > Configuration > Advanced > Developer > Log Settings</pre>
<p>Set &#8220;Enabled&#8221; to &#8220;Yes&#8221; and set the filename to whatever you want.<br />
The log file will be written to the var/log/ directory.</p>
<p>Use Magento&#8217;s static method log() in your code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Mage<span style="color: #339933;">::</span><span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'hello'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Watch the logs:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-f</span> var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>system.log</pre></div></div>

<p>Note: remember to disable loggging when you&#8217;re done so the log files don&#8217;t grow out of control.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sycha.com/magento-tip-debugging-development-log-files/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add Google Analytics to your Magento Store</title>
		<link>http://www.sycha.com/google-analytics-magento</link>
		<comments>http://www.sycha.com/google-analytics-magento#comments</comments>
		<pubDate>Fri, 12 Mar 2010 04:21:01 +0000</pubDate>
		<dc:creator>Charlie Evans</dc:creator>
				<category><![CDATA[Magento Development]]></category>

		<guid isPermaLink="false">http://www.sycha.com/?p=897</guid>
		<description><![CDATA[If you want to add Google Analytics to your Magento store, don't go diving into templates or setting fancy layout updates.. The good folks at Magento have made it nice and easy; simply enable Google Analytics in your Magento admin.]]></description>
			<content:encoded><![CDATA[<p>If you want to add Google Analytics to your Magento store, don&#8217;t go diving into templates or setting fancy layout updates.. The good folks at Magento have made it nice and easy; simply enable Google Analytics in your Magento admin.</p>
<ol>
<li>Sign up for your Google Analytics account here:<br />
<a href="http://www.google.com/analytics/sign_up.html" target="_blank">http://www.google.com/analytics/sign_up.html</a></li>
<li>Make note of your Google Analytics account number,<br />
e.g. UA-xxxxxx-x</li>
<li>Go to your Magento admin and visit the following screen:<br />
<em>System &gt; Configuration &gt; Sales &gt; Google API</em></li>
<li>Expand the Google Analytics block, Enable and enter your Account Number</li>
</ol>
<p><img class="alignnone size-full wp-image-905" title="Magento Google Analytics" src="http://www.sycha.com/wp-content/uploads/2010/03/magento-google-analytics.png" alt="" width="600" height="296" /></p>
<p>Sit back and watch those stats start rolling in..<br />
Doesn&#8217;t get much simpler than that &#8211; cheers Mage and Goog <img src='http://www.sycha.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="notice">
<p>There&#8217;s a known javascript bug with the Google Analytics  implementation in Magento version 1.4.0.1<br />
<a href="http://www.magentocommerce.com/bug-tracking/issue?issue=8658" target="_blank">http://www.magentocommerce.com/bug-tracking/issue?issue=8658</a></p>
<p>As mentioned in the bug report, this will be fixed in the next  stable release, so until then the fix is simple:</p>
<p>Edit the following core file:<br />
<em>magento/app/code/core/Mage/GoogleAnalytics/Block/Ga.php</em></p>
<p>Add the following line at line at around line 180 just above _gaq.push</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> _gaq <span style="color: #339933;">=</span> _gaq  <span style="color: #339933;">||</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

</div>
]]></content:encoded>
			<wfw:commentRss>http://www.sycha.com/google-analytics-magento/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento: Add a custom field to the Contact Us Form</title>
		<link>http://www.sycha.com/magento-add-a-custom-field-to-the-contact-us-form</link>
		<comments>http://www.sycha.com/magento-add-a-custom-field-to-the-contact-us-form#comments</comments>
		<pubDate>Fri, 05 Feb 2010 05:22:19 +0000</pubDate>
		<dc:creator>Charlie Evans</dc:creator>
				<category><![CDATA[Magento Development]]></category>

		<guid isPermaLink="false">http://www.sycha.com/?p=925</guid>
		<description><![CDATA[Magento's default contact form asks the user for the essential contact info, e.g. name, email etc.. But you may need to ask for some additional info by adding some custom fields. Here's how to do it.]]></description>
			<content:encoded><![CDATA[<p>Magento&#8217;s default contact form asks the user for the essential contact info, e.g. name, email etc.. But you may need to ask for some additional info by adding some custom fields. Here&#8217;s how to do it.</p>
<p>Let&#8217;s use the following example scenario:<br />
You want to add a drop box select element to ask the user &#8216;Where did you hear about us?&#8217;. The options will be: Google, Magazine, Word of Mouth, Other.</p>
<h2>Update the Contact Us form template</h2>
<p>Firstly you need to edit the contact form template.<br />
If using the default theme, this code will be located in<br />
<em>/magento/app/design/frontend/base/default/template/contacts/form.phtml</em></p>
<p>Add the following markup to the template in the desired position:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div class=&quot;input-box&quot;&gt;
    &lt;label for=&quot;where-hear&quot;&gt;&lt;?php echo Mage::helper('contacts')-&gt;__('Where did you hear about us?') ?&gt; &lt;span class=&quot;required&quot;&gt;*&lt;/span&gt;&lt;/label&gt;&lt;br /&gt;
    &lt;select name=&quot;where-hear&quot; id=&quot;where-hear&quot; style=&quot;width:300px&quot; class=&quot;required-entry&quot;&gt;
        &lt;option value=&quot;&quot; selected&gt;Please select...&lt;/option&gt;
        &lt;option value=&quot;Google&quot;&gt;Google&lt;/option&gt;
        &lt;option value=&quot;Magazine&quot;&gt;Magazine&lt;/option&gt;
        &lt;option value=&quot;Word of Mouth&quot;&gt;Word of Mouth&lt;/option&gt;
        &lt;option value=&quot;Other&quot;&gt;Other&lt;/option&gt;
    &lt;/select&gt;
&lt;/div&gt;</pre></div></div>

<p>Note the use of <strong>class=&#8221;required-entry&#8221;</strong> on the select element.. This tells the default javascript validation that this field is required. If the user tries to submit the form without choosing an option, then it will throw an error and highlight the field.</p>
<p>So that takes care of the form, now you need to set up a custom email template that includes the new field.</p>
<h2>Create a custom transactional email template</h2>
<p>Navigate to the following screen in your Magento admin:<br />
<em>System > Transactional Emails</em></p>
<ol>
<li>Click <strong>Add New Template</strong></li>
<li>In the top block (Load default template), select &#8220;Contact Form&#8221; from the drop box and click <strong>Load Template</strong></li>
<li>In the Template Information block, set the Template Name to &#8220;Custom Contact Form&#8221;</li>
<li>In the Template Content field, add the following line where you want it to appear in the email:

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Where did you hear about us?: {{var data.where-hear}}</pre></div></div>

</li>
</ol>
<p><img src="http://www.sycha.com/wp-content/uploads/2010/02/custom-contact-form-email-template.png" alt="" title="Custom Contact Form Email Template" width="598" height="483" class="border-999 alignnone size-full wp-image-943" /></p>
<h2>Assign the custom email template</h2>
<p>Navigate to the following screen in your Magento admin:<br />
<em>System > Configuration > General > Contacts</em></p>
<p>In the Email Options block, set the Email Template to &#8220;Custom Contact Form&#8221;.</p>
<p><img src="http://www.sycha.com/wp-content/uploads/2010/02/assign-custom-email-template.png" alt="" title="Assign Custom Email Template" width="598" height="293" class="border-999 alignnone size-full wp-image-942" /></p>
<p>Click <strong>Save Config</strong> and you&#8217;re all done.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sycha.com/magento-add-a-custom-field-to-the-contact-us-form/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Magento: Add a custom State / Province / Region to a Country</title>
		<link>http://www.sycha.com/magento-add-custom-state-province-region-country</link>
		<comments>http://www.sycha.com/magento-add-custom-state-province-region-country#comments</comments>
		<pubDate>Sat, 30 Jan 2010 04:36:52 +0000</pubDate>
		<dc:creator>Charlie Evans</dc:creator>
				<category><![CDATA[Magento Development]]></category>

		<guid isPermaLink="false">http://www.sycha.com/?p=788</guid>
		<description><![CDATA[If you need to add a custom State / Province / Region to a Country in Magento, you’ll need to modify the database manually as there currently isn’t a means to do this from within the Magento admin. Fortunately it’s pretty simple.]]></description>
			<content:encoded><![CDATA[<p>If you need to add a custom State / Province / Region to a Country in Magento, you&#8217;ll need to modify the database manually as there currently isn&#8217;t a means to do this from within the Magento admin. Fortunately it&#8217;s pretty simple &#8211; there are 2 tables involved: <strong>directory_country_region</strong> and <strong>directory_country_region_name</strong>. </p>
<p>Adding a record to <strong>directory_country_region</strong> for a specified country_id will make that new entry show up in the State/Province drop box on the address forms. It will also make that a required field, so you need to make sure you add all the possible options.</p>
<p>You then need to add a corresponding record to <strong>directory_country_region_name</strong>, using the region_id generated when you inserted into directory_country_region. This entry will make the new region show up when a whole address is displayed on the screen or email, e.g. in an order summary.</p>
<h2>Example: Add North and South Island to New Zealand</h2>
<p>So let&#8217;s say that like me, you live in New Zealand and want to add 2 regions: North Island and South Island. The country id for New Zealand is <strong>NZ</strong>, the region code is a unique identifier so I&#8217;m going with <strong>NORTH</strong> and at the moment I&#8217;m only interested in the <strong>en_US</strong> locale. </p>
<p>First I will insert North Island into directory_country_region as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">`directory_country_region`</span> 
<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`region_id`</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">`country_id`</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">`code`</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">`default_name`</span><span style="color: #66cc66;">&#41;</span> 
<span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'NZ'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'NORTH'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'North Island'</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Note the NULL entry for the region_id field which will auto_increment.  I need to find out this new region_id for my next insert so I can either browse the table manually, or this query will do the trick:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #ff0000;">`directory_country_region`</span> 
<span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #ff0000;">`country_id`</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'NZ'</span> <span style="color: #993333; font-weight: bold;">AND</span><span style="color: #ff0000;">`code`</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'NORTH'</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #ff0000;">`default_name`</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'North Island'</span>;</pre></div></div>

<p>In my case, the new region_id is 320, so with that I&#8217;ll now insert into directory_country_region_name as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">`directory_country_region_name`</span> 
<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`locale`</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">`region_id`</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">`name`</span><span style="color: #66cc66;">&#41;</span> 
<span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'en_US'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'320'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'North Island'</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Now I just repeat those steps for South Island and I&#8217;m all set.</p>
<p>I&#8217;ve created some code below which automates this process, you just need to make sure <a href="/stand-alone-magento-scripts">Magento is properly initialised in your script</a> and modify the variables at the top as necessary.. Enjoy!</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// set up array containing regions to be added (region_code =&gt; region_name)</span>
<span style="color: #000088;">$new_regions</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'NORTH'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;North Island&quot;</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'SOUTH'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;South Island&quot;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// specify country code for new regions</span>
<span style="color: #000088;">$country_code</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'NZ'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// specify locale</span>
<span style="color: #000088;">$locale</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'en_US'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// create our core_write conection object</span>
<span style="color: #000088;">$connection</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core/resource'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core_write'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// iterate our new regions</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$new_regions</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$region_code</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$region_name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// insert region </span>
	<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INSERT INTO `directory_country_region` (`region_id`,`country_id`,`code`,`default_name`) VALUES (NULL,?,?,?)&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$connection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$country_code</span><span style="color: #339933;">,</span><span style="color: #000088;">$region_code</span><span style="color: #339933;">,</span><span style="color: #000088;">$region_name</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// get new region id for next query</span>
	<span style="color: #000088;">$region_id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$connection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">lastInsertId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// insert region name</span>
	<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INSERT INTO `directory_country_region_name` (`locale`,`region_id`,`name`) VALUES (?,?,?)&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$connection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$locale</span><span style="color: #339933;">,</span><span style="color: #000088;">$region_id</span><span style="color: #339933;">,</span><span style="color: #000088;">$region_name</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.sycha.com/magento-add-custom-state-province-region-country/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Magento Database Models, Helpers and Raw SQL Queries</title>
		<link>http://www.sycha.com/magento-database-models-helpers-raw-sql-queries</link>
		<comments>http://www.sycha.com/magento-database-models-helpers-raw-sql-queries#comments</comments>
		<pubDate>Fri, 15 Jan 2010 00:44:20 +0000</pubDate>
		<dc:creator>Charlie Evans</dc:creator>
				<category><![CDATA[Magento Development]]></category>

		<guid isPermaLink="false">http://www.sycha.com/?p=768</guid>
		<description><![CDATA[The best way to access and manipulate data in Magento is by using the provided objects and their associated functionality. If you really need to deal with raw queries you can do that too.]]></description>
			<content:encoded><![CDATA[<div class="notice">
<p>Before running any the snippets in this article,<br />
you&#8217;ll need to make sure <a href="/stand-alone-magento-scripts">Magento is initialised in your script</a>
</div>
<h2>Magento Database Models</h2>
<p>The best way to access and manipulate data in Magento is by using the provided objects and their associated functionality..<br />
For example, you can get a Magento category model like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$model_category</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;">;</span></pre></div></div>

<p>With your category model you now retrieve data<br />
e.g. get all child categories of category ID 2 and echo the name</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$model_category</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;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$model_category</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCategories</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$category</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$category</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</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>

<h2>Magento Helper Classes</h2>
<p>Magento has helper classes which are pretty handy also.<br />
For example, you can get a Magento category helper like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$helper</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'catalog/category'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Your helper will have a bunch of methods defined for performing common tasks.<br />
For example, you can get all your stores top level categories as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$helper</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'catalog/category'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$helper</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getStoreCategories</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$category</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$category</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</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>Check this file to see what methods are available in the catalog category helper:<br />
magento/app/code/core/Mage/Catalog/Helper/Category.php</p>
<h2>Raw SQL Queries in Magento</h2>
<p>That&#8217;s a VERY brief intro into using Magento&#8217;s models and helpers. They should serve your needs most of the time, but if you really need to deal with raw queries here&#8217;s how to do it.</p>
<p>Depending on what sort of operation you wish to perform (read or write) you will use one of the following to get a database connection object:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$connection</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core/resource'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core_read'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$connection</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core/resource'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core_write'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>These connections are essentially Zend database objects so you can run any of the <a href="http://framework.zend.com/apidoc/core/Zend_Db/Adapter/Zend_Db_Adapter_Abstract.html" target="_blank" rel="nofollow">methods defined here</a>. Probably of most interest will be query(), fetchAll(), and fetchOne().</p>
<h2>Write directly to a Magento database table</h2>
<p>This example creates a core_write connection object, then directly inserts a row with raw SQL via the query() method.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// insert a new US State into the region table</span>
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INSERT INTO `directory_country_region` (`region_id`,`country_id`,`code`,`default_name`) VALUES (NULL,'US','XX','New US State')&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$connection</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core/resource'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core_write'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$connection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Read directly from a Magento database table</h2>
<p>This example creates a core_read connection object, then uses the fetchAll() method to retrieve and iterate all the rows returned by a raw sql query.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// display all regions defined for the United States</span>
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM directory_country_region WHERE country_id='US'&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$connection</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core/resource'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core_read'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$connection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchAll</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$arr_row</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$arr_row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'default_name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.sycha.com/magento-database-models-helpers-raw-sql-queries/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Database Caching 1/49 queries in 0.015 seconds using disk: basic
Object Caching 472/572 objects using disk: basic

Served from: www.sycha.com @ 2012-02-04 18:14:41 -->
