<?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>NY INTERACTIVE AGENCY « iFUEL INTERACTIVE / AGENCY212 &#187; Magento</title>
	<atom:link href="http://blogs.ifuelinteractive.com/category/development/magento/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.ifuelinteractive.com</link>
	<description>A NY INTERACTIVE AGENCY</description>
	<lastBuildDate>Fri, 02 Jul 2010 15:38:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>FIX Google Analytics _gaq is not defined In Magento 1.4.0.1</title>
		<link>http://blogs.ifuelinteractive.com/2010/07/02/fix-google-analytics-_gaq-is-not-defined-in-magento-1-4-0-1/</link>
		<comments>http://blogs.ifuelinteractive.com/2010/07/02/fix-google-analytics-_gaq-is-not-defined-in-magento-1-4-0-1/#comments</comments>
		<pubDate>Fri, 02 Jul 2010 15:33:18 +0000</pubDate>
		<dc:creator>Robert Nicklin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://blogs.ifuelinteractive.com/?p=259</guid>
		<description><![CDATA[Locate: /app/design/frontend/base/default/layout/googleanalytics.xml
Replace With:


&#60;default&#62;
&#60;!-- Mage_GoogleAnalytics --&#62;
&#60;reference name=&#34;before_body_end&#34;&#62;
&#60;block type=&#34;googleanalytics/ga&#34; name=&#34;google_analytics&#34; as=&#34;google_analytics&#34; /&#62;
&#60;/reference&#62;
&#60;/default&#62;
&#60;/layout&#62;


^ This will move the Google Analytics code to before the closing of the HTML &#60;/body&#62; tag (for faster page load times)
Locate: /app/code/core/Mage/GoogleAnalytics/Block/ga.php
Replace at around LINE 171: 


&#60;!-- BEGIN GOOGLE ANALYTICS CODE --&#62;
&#60;script type=&#34;text/javascript&#34;&#62;
//&#60;![CDATA[
var _gaq = _gaq &#124;&#124; [];
_gaq.push([&#34;_setAccount&#34;, &#34;&#039; . $this-&#62;getAccount() . &#039;&#34;]);
_gaq.push([&#34;_trackPageview&#34;, &#34;&#039;.$this-&#62;getPageName().&#039;&#34;]);
(function() {
var [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Locate: /app/design/frontend/base/default/layout/googleanalytics.xml</strong></p>
<p>Replace With:</p>
<pre>
<pre class="brush: php">
&lt;default&gt;
&lt;!-- Mage_GoogleAnalytics --&gt;
&lt;reference name=&quot;before_body_end&quot;&gt;
&lt;block type=&quot;googleanalytics/ga&quot; name=&quot;google_analytics&quot; as=&quot;google_analytics&quot; /&gt;
&lt;/reference&gt;
&lt;/default&gt;
&lt;/layout&gt;
</pre>
</pre>
<p>^ This will move the Google Analytics code to before the closing of the HTML &lt;/body&gt; tag (for faster page load times)</p>
<p><strong>Locate: /app/code/core/Mage/GoogleAnalytics/Block/ga.php</strong></p>
<p>Replace at around LINE 171: </p>
<pre>
<pre class="brush: php">
&lt;!-- BEGIN GOOGLE ANALYTICS CODE --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
//&lt;![CDATA[
var _gaq = _gaq || [];
_gaq.push([&quot;_setAccount&quot;, &quot;&#039; . $this-&gt;getAccount() . &#039;&quot;]);
_gaq.push([&quot;_trackPageview&quot;, &quot;&#039;.$this-&gt;getPageName().&#039;&quot;]);
(function() {
var ga = document.createElement(\&#039;script\&#039;); ga.type = \&#039;text/javascript\&#039;; ga.async = true;
ga.src = (\&#039;https:\&#039; == document.location.protocol ? \&#039;https://ssl\&#039; : \&#039;http://www\&#039;) + \&#039;.google-analytics.com/ga.js\&#039;;
(document.getElementsByTagName(\&#039;head\&#039;)[0] || document.getElementsByTagName(\&#039;body\&#039;)[0]).appendChild(ga);
})();

//]]&gt;
&lt;/script&gt;
&lt;!-- END GOOGLE ANALYTICS CODE --&gt;
</pre>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blogs.ifuelinteractive.com/2010/07/02/fix-google-analytics-_gaq-is-not-defined-in-magento-1-4-0-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tips and Tricks: Developing with Magento</title>
		<link>http://blogs.ifuelinteractive.com/2010/04/05/tips-and-tricks-developing-with-magento/</link>
		<comments>http://blogs.ifuelinteractive.com/2010/04/05/tips-and-tricks-developing-with-magento/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 20:54:05 +0000</pubDate>
		<dc:creator>Robert Nicklin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[file structure]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[Magento Guide]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blogs.ifuelinteractive.com/?p=227</guid>
		<description><![CDATA[Things you Should Know Before Developing With Magento
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-
Now being more experienced with Magento we definitely feel the need to share our findings with the masses. We only wish we knew these things prior to trying to the hack the crap out of magento to make it do what we want.
Turning on Template Path Hints
If you&#8217;re [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-weight:bold;color:#3a3a3a;">Things you Should Know Before Developing With Magento</span></p>
<p><span style="color:DarkGray;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</span></p>
<p>Now being more experienced with Magento we definitely feel the need to share our findings with the masses. We only wish we knew these things prior to trying to the hack the crap out of magento to make it do what we want.</p>
<p><span style="font-weight:bold;">Turning on Template Path Hints</span><br />
If you&#8217;re new to Magento you will realize that it is quite a hassle to understand the logic behind the file structure and block structure of a magento layout when trying to customize your storefront. There is a very under-publicized built-in magento feature that we&#8217;d like to share with you that should help you on your journey. Magento actually has the ability to display hints showing where the different files of your layout is contained so that you can edit it. </p>
<p><a href="http://blogs.ifuelinteractive.com/wp-content/uploads/2010/04/template-path-hints.jpg"><img src="http://blogs.ifuelinteractive.com/wp-content/uploads/2010/04/template-path-hints.jpg" alt="Magento&#039;s Built-In Template Path Hints" title="template-path-hints" width="600" height="178" /></a></p>
<p>To achieve this, Follow these simple steps&#8230;</p>
<ul>
<li>Log in to your administration panel. Go to Sytem > Configuration.</li>
<li>From the left navigation column on top there will be &#8220;Current Configuration Scope&#8221;. In the drop down menu select &#8220;Main Website&#8221;</li>
<li>Then navigate to Developer > Advance, also in the left navigation column.</li>
<li>Under &#8220;Debug&#8221; you&#8217;ll see Template Path Hints. Select Yes and click the Save Config button.</li>
</ul>
<p>Now when you navigate to your storefront you&#8217;ll see a bunch of red boxes displaying the underlying structure of the pages regarding templates and blocks. </p>
<p><span style="font-style: italic;font-size:11px;color:#707070;">Note: This should only be used in a development environment, considering this will make your storefront look hideous with big red blocks everywhere.</span></p>
<p><span style="color:DarkGray;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</span></p>
<p><span style="font-weight:bold;">Never edit core files</span><br />
Problem: When developing with Magento you will find it necesary to edit core files to achieve certain functionality. However, By editting a core file you are basically blocking yourself into a corner. DON&#8217;T DO IT! If you ever wish to upgrade at any point in the future you will not be able to because any changes that you have made in the core files will be overwritten. Never fear, there is a way around this. </p>
<p>Solution: The &#8220;local&#8221; folder (\app\code\local\) is your saviour. Say you need to edit the &#8220;Shipping.php&#8221; file located at &#8220;\app\code\core\Mage\Shipping\Model\Shipping.php&#8221; you can create the same basic directory structure in the local folder and copy and paste the Shipping.php file into the new directory. So, your new &#8220;local&#8221; Shipping.php file will be located at \app\code\local\Mage\Shipping\Model\Shipping.php. You will be able to safely edit anything and everything within that local file and never have to worry about it being overwritten during an upgrade. This trick works because Magento will look for files in a local directory before looking for a file in the core directory. </p>
<p><span style="font-style: italic;font-size:11px;color:#707070;">Note: The above solution will only overpower files that exist within the \app\code\core\ or \app\code\community\ directories. Also note that any files within your magento theme (\app\design\frontend\default\YOURTHEME\) or (\skin\frontend\default\YOURTHEME\) are not considered core files and you are free to edit them as you please. </span></p>
<p>These are just to name a few&#8230; <a href="http://blogs.ifuelinteractive.com/feed/rss/">Follow our blog to read more!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.ifuelinteractive.com/2010/04/05/tips-and-tricks-developing-with-magento/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enabling Compression on a Magento Site on OpenSuse</title>
		<link>http://blogs.ifuelinteractive.com/2010/01/26/enabling-compression-on-a-magento-site-on-opensuse/</link>
		<comments>http://blogs.ifuelinteractive.com/2010/01/26/enabling-compression-on-a-magento-site-on-opensuse/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 16:18:39 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Compression]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[OpenSuse]]></category>

		<guid isPermaLink="false">http://blogs.ifuelinteractive.com/?p=174</guid>
		<description><![CDATA[If you&#8217;re running Magento on OpenSuse (or any platform for that matter), you can really benefit from turning on http compression, especially to remote areas or from hosts that have limited bandwidth.
There are a lot of references out there on this, but you have to sort of pull it all together on your own for [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re running Magento on OpenSuse (or any platform for that matter), you can really benefit from turning on http compression, especially to remote areas or from hosts that have limited bandwidth.</p>
<p>There are a lot of references out there on this, but you have to sort of pull it all together on your own for this particular combination.</p>
<p><strong>Verify that mod_deflate has been installed in Apache:<br />
</strong><br />
1. Open /etc/sysconfig/apache2.</p>
<p>2. Find the line that starts:</p>
<p>APACHE_MODULES=&#8230;</p>
<p>3. Verify that &#8220;deflate&#8221; is one of the modules listed (may not be in alphabetical order).</p>
<p><strong>Now, enable compression in the virtual host file for your site:</strong></p>
<p>1. Open /etc/apache2/vhosts.d/.conf.</p>
<p>2. Add the following lines inside the  tag:</p>
<pre>
<pre class="brush: php">

    &lt;IfModule mod_deflate.c&gt;
	DeflateBufferSize 32768
	DeflateCompressionLevel 5

	&lt;Location /&gt;
		SetOutputFilter DEFLATE
		BrowserMatch ^Mozilla/4 gzip-only-text/html
		BrowserMatch ^Mozilla/4\.0[678] no-gzip
		BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
		SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|tiff)$ no-gzip dont-vary
		# Header append Vary User-Agent env=!dont-vary
	&lt;/Location&gt;
    &lt;/IfModule&gt;
</pre>
</pre>
<p><strong>Now restart Apache using:</strong></p>
<p>sudo /etc/init.d/apache2 restart</p>
<p>and you should be in business!</p>
<p><strong>Validate that compression is working</strong></p>
<p>A great, handy online site that you can use to validate that compression is working is <a href="http://www.gidnetwork.com/tools/gzip-test.php" target="_blank">http://www.gidnetwork.com/tools/gzip-test.php</a>.</p>
<p>=============================<em><br />
“e-commerce done right</em>”<br />
<a href="http://www.ifuelinteractive.com/" target="_blank">http://www.ifuelinteractive.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.ifuelinteractive.com/2010/01/26/enabling-compression-on-a-magento-site-on-opensuse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clearing Test Data From Magento</title>
		<link>http://blogs.ifuelinteractive.com/2009/11/02/clearing-test-data-from-magento/</link>
		<comments>http://blogs.ifuelinteractive.com/2009/11/02/clearing-test-data-from-magento/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 19:46:45 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[reset database]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://blogs.ifuelinteractive.com/?p=134</guid>
		<description><![CDATA[On many occasions we&#8217;ve needed to clear out the test data from a Magento site in preparation for going live.  It&#8217;s not as trivial as you&#8217;d think, but I found a nice sql script thanks to Elias Interactive that was just what I needed.  I&#8217;ve removed a bit as I didn&#8217;t need to reset all [...]]]></description>
			<content:encoded><![CDATA[<p>On many occasions we&#8217;ve needed to clear out the test data from a Magento site in preparation for going live.  It&#8217;s not as trivial as you&#8217;d think, but I found a nice sql script thanks to <a href="http://eliasinteractive.com/blog/magento-ecommerce-how-to-reset-all-test-order-information-and-set-unique-prefix-for-orders-invoices-shipments-and-credit-memos/" target="_blank">Elias Interactive </a>that was just what I needed.  I&#8217;ve removed a bit as I didn&#8217;t need to reset all the order numbers, etc.</p>
<p><em>updated 6/30/2010 for Magento 1.4<br />
</em></p>
<pre>
<pre class="brush: sql">
-- Reset Magento TEST Data

SET FOREIGN_KEY_CHECKS=0;

-- reset dashboard search queries
TRUNCATE `catalogsearch_query`;
ALTER TABLE `catalogsearch_query` AUTO_INCREMENT=1;

-- reset sales order info
TRUNCATE `sales_order`;
TRUNCATE `sales_order_datetime`;
TRUNCATE `sales_order_decimal`;
TRUNCATE `sales_order_entity`;
TRUNCATE `sales_order_entity_datetime`;
TRUNCATE `sales_order_entity_decimal`;
TRUNCATE `sales_order_entity_int`;
TRUNCATE `sales_order_entity_text`;
TRUNCATE `sales_order_entity_varchar`;
TRUNCATE `sales_order_int`;
TRUNCATE `sales_order_text`;
TRUNCATE `sales_order_varchar`;
TRUNCATE `sales_flat_quote`;
TRUNCATE `sales_flat_quote_address`;
TRUNCATE `sales_flat_quote_address_item`;
TRUNCATE `sales_flat_quote_item`;
TRUNCATE `sales_flat_quote_item_option`;
TRUNCATE `sales_flat_order_item`;
TRUNCATE `sendfriend_log`;
TRUNCATE `tag`;
TRUNCATE `tag_relation`;
TRUNCATE `tag_summary`;
TRUNCATE `wishlist`;
TRUNCATE `log_quote`;
TRUNCATE `report_event`;
TRUNCATE `sales_flat_quote_payment`;
TRUNCATE `sales_flat_quote_shipping_rate`;
TRUNCATE `log_url`;
TRUNCATE `log_url_info`;
TRUNCATE `log_visitor`;
TRUNCATE `log_visitor_info`;

ALTER TABLE `sales_order` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_datetime` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_decimal` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_int` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_text` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_varchar` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item_option` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=1;
ALTER TABLE `sendfriend_log` AUTO_INCREMENT=1;
ALTER TABLE `tag` AUTO_INCREMENT=1;
ALTER TABLE `tag_relation` AUTO_INCREMENT=1;
ALTER TABLE `tag_summary` AUTO_INCREMENT=1;
ALTER TABLE `wishlist` AUTO_INCREMENT=1;
ALTER TABLE `log_quote` AUTO_INCREMENT=1;
ALTER TABLE `report_event` AUTO_INCREMENT=1;
</pre>
</pre>
<p>Just run this script against the Magento database (make a backup first!).</p>
<p>=============================<em><br />
“e-commerce done right</em>”<br />
<a href="http://www.ifuelinteractive.com/" target="_blank">http://www.ifuelinteractive.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.ifuelinteractive.com/2009/11/02/clearing-test-data-from-magento/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Logging all SQL in Magento</title>
		<link>http://blogs.ifuelinteractive.com/2009/10/18/logging-all-sql-in-magento/</link>
		<comments>http://blogs.ifuelinteractive.com/2009/10/18/logging-all-sql-in-magento/#comments</comments>
		<pubDate>Sun, 18 Oct 2009 13:24:21 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://blogs.ifuelinteractive.com/?p=106</guid>
		<description><![CDATA[I&#8217;ve been looking for a way to log all the sql that Magento is running for debugging purposes.  There are a number of logging mechanisms built in to Magento, but none that would allow you to log all the sql that&#8217;s being run.  Finally, I&#8217;ve found a simple change that can be made [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been looking for a way to log all the sql that Magento is running for debugging purposes.  There are a number of logging mechanisms built in to Magento, but none that would allow you to log all the sql that&#8217;s being run.  Finally, I&#8217;ve found a simple change that can be made to a core file (I know, not ideal because it will get overwritten when you upgrade Magento &#8211; but it&#8217;s only a few lines in one file).</p>
<h3>The Change</h3>
<p>1. Open the file &lt;magentoroot&gt;/lib/Varien/Db/Adapter/Pdo/Mysql.php.</p>
<p>2. Add the following lines:</p>
<pre>
<pre class="brush: php">
$code = &#039;SQL: &#039; . $sql . &quot;\r\n&quot;;
if ($bind) {
     $code .= &#039;BIND: &#039; . print_r($bind, true) . &quot;\r\n&quot;;
}
$this-&gt;_debugWriteToFile(&quot;[&quot;.date(&#039;Y-m-d H:i:s&#039;).&quot;] &quot;.$code);
</pre>
</pre>
<p>Add it to the &#8220;query&#8221; function as shown below:</p>
<pre>
<pre class="brush: php">
public function query($sql, $bind = array())
{
     $this-&gt;_debugTimer();

     try {
          $sql = (string)$sql;
          if (strpos($sql, &#039;:&#039;) !== false || strpos($sql, &#039;?&#039;) !== false) {
               $this-&gt;_bindParams = $bind;
               $sql = preg_replace_callback(&#039;#(([\&#039;&quot;])((\\2)|((.*?[^\\\\])\\2)))#&#039;, array($this, &#039;proccessBindCallback&#039;), $sql);
               $bind = $this-&gt;_bindParams;
          }

          $code = &#039;SQL: &#039; . $sql . &quot;\r\n&quot;;
          if ($bind) {
               $code .= &#039;BIND: &#039; . print_r($bind, true) . &quot;\r\n&quot;;
          }
          $this-&gt;_debugWriteToFile(&quot;[&quot;.date(&#039;Y-m-d H:i:s&#039;).&quot;] &quot;.$code);

          $result = parent::query($sql, $bind);
     }
     catch (Exception $e) {
          $this-&gt;_debugStat(self::DEBUG_QUERY, $sql, $bind);
          $this-&gt;_debugException($e);
     }
     $this-&gt;_debugStat(self::DEBUG_QUERY, $sql, $bind, $result);
     return $result;
 }
</pre>
<p><span id="more-106"></span></pre>
<h3>The Log</h3>
<p>By default your sql will be logged to:</p>
<p>&lt;magentoroot&gt;/var/debug/sql.txt</p>
<h3>Limitations</h3>
<p>1. As mentioned above, the file will likely be overwritten during a Magento upgrade.</p>
<p>2. There&#8217;s nothing that will turn logging off (except a Magento upgrade).  So you need to be careful that this is a temporary setting for debugging only.</p>
<p>=============================<em><br />
“e-commerce done right</em>”<br />
<a href="http://www.ifuelinteractive.com/" target="_blank">http://www.ifuelinteractive.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.ifuelinteractive.com/2009/10/18/logging-all-sql-in-magento/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>jQuery, Magento and Ajax Add to Cart Redux</title>
		<link>http://blogs.ifuelinteractive.com/2009/10/15/jquery-magento-and-ajax-add-to-cart-redux/</link>
		<comments>http://blogs.ifuelinteractive.com/2009/10/15/jquery-magento-and-ajax-add-to-cart-redux/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 14:49:16 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[Add to Cart]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://blogs.ifuelinteractive.com/?p=81</guid>
		<description><![CDATA[My previous post on adding to the cart with ajax in Magento has generated enough interest &#8211; and pointed out enough flaws in my overly complex code &#8211; that I&#8217;ve decided to put together a simplified version, so here goes:
ajaxAddToCart.zip
Step 1: Create the server side script. 
My sample script is called &#8220;addToCartTest.php&#8221; and I put [...]]]></description>
			<content:encoded><![CDATA[<p>My previous post on adding to the cart with ajax in Magento has generated enough interest &#8211; and pointed out enough flaws in my overly complex code &#8211; that I&#8217;ve decided to put together a simplified version, so here goes:</p>
<p><a href="http://blogs.ifuelinteractive.com/wp-content/uploads/2009/10/ajaxAddToCart.zip">ajaxAddToCart.zip</a></p>
<p><strong>Step 1: Create the server side script. </strong><br />
My sample script is called &#8220;addToCartTest.php&#8221; and I put it in a /scripts folder in the root of my Magento installation.</p>
<pre>
<pre class="brush: php">

&lt;?php
include_once &#039;../app/Mage.php&#039;;
Mage::app();

try{
     // usage /scripts/addToCartTest.php?product_id=838&amp;amp;amp;amp;amp;amp;qty=1
     $product_id = &#039;&#039;;

     // get query string
     if (!isset($_GET[&#039;product_id&#039;])) { $product_id = &#039;&#039;; } else { $product_id = $_GET[&#039;product_id&#039;]; }
     if (!isset($_GET[&#039;qty&#039;])) { $qty = &#039;1&#039;; } else { $qty = $_GET[&#039;qty&#039;]; }

     $product = Mage::getModel(&#039;catalog/product&#039;)-&gt;load($product_id);

     $session = Mage::getSingleton(&#039;core/session&#039;, array(&#039;name&#039;=&gt;&#039;frontend&#039;));
     $cart = Mage::helper(&#039;checkout/cart&#039;)-&gt;getCart();

     $cart-&gt;addProduct($product, $qty);

     $session-&gt;setLastAddedProductId($product-&gt;getId());
     $session-&gt;setCartWasUpdated(true);

     $cart-&gt;save();

     $result = &quot;{&#039;result&#039;:&#039;success&#039;}&quot;;
     echo $result;

} catch (Exception $e) {
     $result = &quot;{&#039;result&#039;:&#039;error&#039;&quot;;
     $result .= &quot;, &#039;message&#039;: &#039;&quot;.$e-&gt;getMessage().&quot;&#039;}&quot;;
     echo $result;
}
</pre>
</pre>
<p><span id="more-81"></span><br />
<strong>Step 2: Create the &#8216;html&#8217; page<br />
</strong>Obviously, you&#8217;d be putting this code into your product detail page or wherever you&#8217;re trying to add the item to the cart from.</p>
<pre>
<pre class="brush: html">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot;&gt;
&lt;title&gt;Ajax add to cart sample&lt;/title&gt;
&lt;script src=&quot;/scripts/jquery-1.3.2.min-noconflict.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
jQuery(document).ready(function($) {
     $(&quot;#buyNowButton&quot;).click(function(){
          var qty = $(&quot;#qty&quot;).val();
          var product_id = $(&quot;#buyNowButton&quot;).attr(&quot;product_id&quot;);

          var params = &quot;product_id=&quot; + product_id + &quot;&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;qty=&quot; + qty;        

          var result = $.getJSON(&quot;/scripts/addToCartTest.php&quot;, params, function(data, textStatus){
               if (textStatus == &quot;error&quot;){
                    alert(&quot;There was an error adding this item to your cart.  Please call customer service for assistance.&quot;, &quot;Error&quot;);
                    return;
               }

               if (data.result == &quot;error&quot;){
                    alert(&quot;Sorry, an error occurred while adding the item to your cart.  The error was: &#039;&quot; + data.message + &quot;&#039;&quot;);
                    return;
               }

               alert(&quot;Thanks!  The item has been added to your cart!&quot;)
          });
     });
});
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
     &lt;input type=&quot;text&quot; id=&quot;qty&quot; value=&quot;1&quot; /&gt;
     &lt;a id=&quot;buyNowButton&quot; product_id=&quot;972&quot; href=&quot;#&quot;&gt;Buy Now&lt;/a&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
</pre>
<p>That&#8217;s it!  </p>
<p>Prerequisites:<br />
1. jQuery (Because Magento uses prototype and scriptaculous, you have to use jQuery in &#8220;no conflict&#8221; mode);<br />
I&#8217;ve included the source code, along with the no-conflict version of jQuery in the zip file attached.</p>
<p>Let me know if you&#8217;re using this code (helps my ego)!</p>
<p>=============================<em><br />
 “e-commerce done right</em>”<br />
 <a href="http://www.ifuelinteractive.com/" target="_blank">http://www.ifuelinteractive.com</a></pre>
]]></content:encoded>
			<wfw:commentRss>http://blogs.ifuelinteractive.com/2009/10/15/jquery-magento-and-ajax-add-to-cart-redux/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Creating a new Product Attribute and then using it on a page in Magento</title>
		<link>http://blogs.ifuelinteractive.com/2009/09/29/create-a-new-product-attribute-and-then-using-it-on-a-page-in-magento/</link>
		<comments>http://blogs.ifuelinteractive.com/2009/09/29/create-a-new-product-attribute-and-then-using-it-on-a-page-in-magento/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 18:53:45 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[Product Attributes]]></category>

		<guid isPermaLink="false">http://blogs.ifuelinteractive.com/?p=51</guid>
		<description><![CDATA[
Creating a new product attribute and using it when you&#8217;re displaying a product turns out to be fairly simple &#8211; but I know for us at iFuel &#8211; and I think for lots of others based on the posts you see around the net, it ends up not being as simple as it seems.
For this [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>Creating a new product attribute and using it when you&#8217;re displaying a product turns out to be fairly simple &#8211; but I know for us at iFuel &#8211; and I think for lots of others based on the posts you see around the net, it ends up not being as simple as it seems.</p>
<p>For this example, we&#8217;ll create a new attribute called &#8220;ingredients&#8221;.  We need this to be a text field (text area to be exact) that Magento admins can enter the product ingredients.  Then we&#8217;ll need to be able to access this text when we display the product.</p>
<h3>Attributes</h3>
<p>Attributes are single pieces of information that can be assigned to any of the entities (models) in the Magento system.  There is an extensive user interface for creating and maintaining attributes and attribute sets for products.  But you can actually create attributes for other entity types, like categories, too.  (Creating an attribute for a category has to be done right in the database &#8211; I&#8217;ll try to cover that in a future post).</p>
<p>To create an attribute:</p>
<p><span id="more-51"></span></p>
<p>1. Select &#8220;Attributes&#8221; -&gt; &#8220;Manage Attributes&#8221; from the &#8220;Catalog&#8221; menu in the Magento admin panel.</p>
<p>2. Click &#8220;Add New Attribute&#8221;.</p>
<p><img src="file:///C:/Users/Andy/AppData/Local/Temp/moz-screenshot-1.png" alt="" /></div>
<div id="attachment_60" class="wp-caption alignnone" style="width: 671px"><img class="size-full wp-image-60" title="Adding an Attribute" src="http://blogs.ifuelinteractive.com/wp-content/uploads/2009/09/add-attribute1.jpg" alt="Adding an Attribute" width="661" height="737" /><p class="wp-caption-text">Adding an Attribute</p></div>
<p>3. Enter an attribute code &#8211; we&#8217;ve used &#8220;ingredients&#8221; here.</p>
<p>4. Select the scope &#8211; we&#8217;ve selected &#8220;global&#8221; but you could select store as well.</p>
<p>5. Select the attribute type &#8211; we&#8217;ve selected text area because we want the user to be able to enter free-form text (we&#8217;re using the wysiwig editor for Magento so they&#8217;re actually entering html).</p>
<p>6. Go to the &#8220;Manage Label/Options&#8221; tab and enter a label to be used for the new attribute.</p>
<p>7. Save the new attribute.</p>
<h3>Attribute Sets</h3>
<p>Once you&#8217;ve added the new attribute, you have to add it to the attribute set that you use for your products.  (If you have more than one attribute set for your products, you&#8217;ll have to add it to all of the sets you want it to appear in).</p>
<p>1. Select &#8220;Attributes&#8221; -&gt; &#8220;Manage Attribute Sets&#8221;</p>
<p>2. Select your attribute set (if you haven&#8217;t created new attribute sets, it&#8217;ll be called &#8220;Default&#8221;)</p>
<p>3. Drag your new attribute from the list of &#8220;unassigned attributes&#8221; on the right into the list on the left (where you drop it will be where the admin will see it)</p>
<div id="attachment_61" class="wp-caption alignnone" style="width: 596px"><img class="size-full wp-image-61" title="Adding and attribute to an attribute set in Magento" src="http://blogs.ifuelinteractive.com/wp-content/uploads/2009/09/add-attribute-to-set1.jpg" alt="Adding and attribute to an attribute set in Magento" width="586" height="581" /><p class="wp-caption-text">Adding and attribute to an attribute set in Magento</p></div>
<p>4. Save the attribute set.</p>
<h3>Using the new attribute in the page</h3>
<p>So, that&#8217;s the easy part.  Actually, using the attribute in the page is pretty easy, once you&#8217;ve got the right syntax!  Assuming the id of the product you are using is in $productid then:</p>
<pre class="brush: php">

&lt;?php

$productModel = Mage::getModel(&#039;catalog/product&#039;)-&gt;load($productid);

$ingredients = $productModel-&gt;getIngredients();

echo $ingredients;

?&gt;
</pre>
<p>Poof!</p>
<p>I kept trying $_product-&gt;getIngredients(), but that wasn&#8217;t working.  I think there&#8217;s a way to tell Magento to load that attribute when the product is being loaded.  If anyone knows, let me know!</p>
<p>=============================<em><br />
&#8220;e-commerce done right</em>&#8221;<br />
<a href="http://www.ifuelinteractive.com/" target="_blank">http://www.ifuelinteractive.com</a></p>
<p><img src="file:///C:/Users/Andy/AppData/Local/Temp/moz-screenshot.png" alt="" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.ifuelinteractive.com/2009/09/29/create-a-new-product-attribute-and-then-using-it-on-a-page-in-magento/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>iFuel Standardizes on Magento Commerce</title>
		<link>http://blogs.ifuelinteractive.com/2009/09/10/ifuel-standardizes-on-magento-commerce/</link>
		<comments>http://blogs.ifuelinteractive.com/2009/09/10/ifuel-standardizes-on-magento-commerce/#comments</comments>
		<pubDate>Thu, 10 Sep 2009 15:53:52 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://blogs.ifuelinteractive.com/?p=31</guid>
		<description><![CDATA[After using many many commerce packages &#8211; and WRITING many many commerce packages from scratch, we&#8217;ve standardized on Magento Commerce for all new e-commerce sites.  It&#8217;s an awesome platform, with huge potential for customization and extension.  The list of existing modules (plug-ins basically) is very large and growing all the time.  This is the way [...]]]></description>
			<content:encoded><![CDATA[<p>After using many many commerce packages &#8211; and WRITING many many commerce packages from scratch, we&#8217;ve standardized on <a href="http://www.magentocommerce.com">Magento Commerce</a> for all new e-commerce sites.  It&#8217;s an awesome platform, with huge potential for customization and extension.  The list of existing modules (plug-ins basically) is very large and growing all the time.  This is the way to put up new e-commerce sites, no question about it!</p>
<p>We&#8217;ll be posting lots and lots of Magento information in the weeks and months to come as we continue on our journey with this great tool!</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.ifuelinteractive.com/2009/09/10/ifuel-standardizes-on-magento-commerce/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding to the Cart with a jQuery Ajax Call in Magento</title>
		<link>http://blogs.ifuelinteractive.com/2009/09/10/adding-to-the-cart-with-a-jquery-ajax-call-in-magento/</link>
		<comments>http://blogs.ifuelinteractive.com/2009/09/10/adding-to-the-cart-with-a-jquery-ajax-call-in-magento/#comments</comments>
		<pubDate>Thu, 10 Sep 2009 14:05:53 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[Add to Cart]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://blogs.ifuelinteractive.com/?p=9</guid>
		<description><![CDATA[So, Ajax being the thing and all, I was hunting for a way to add an item to the cart using an Ajax call in Magento.  Recently, I noticed there was a module that apparently does this, but either I hadn&#8217;t seen that or it didn&#8217;t exist yet when I wrote this, so I hacked [...]]]></description>
			<content:encoded><![CDATA[<p>So, Ajax being the thing and all, I was hunting for a way to add an item to the cart using an Ajax call in Magento.  Recently, I noticed there was a module that apparently does this, but either I hadn&#8217;t seen that or it didn&#8217;t exist yet when I wrote this, so I hacked my way through it.</p>
<p>PHP isn&#8217;t my primary language &#8211; I come from the ASP, ASP.Net, C# world, but Magento was compelling enough that I&#8217;ve taken the leap.  I&#8217;m sure there are lots of things I could be doing better/differently here so if you&#8217;ve got some suggestions, I&#8217;m all ears!</p>
<h2>Add to Cart Page</h2>
<p>So first I needed an &#8220;Add to Cart&#8221; page (called &#8211; addToCart.php) that could be called from the client.  This page returns a result in JSON format.  The actual page also returns related items so we can try to cross sell the user, but I&#8217;ve removed that in this sample to make it simpler.</p>
<p><span id="more-9"></span></p>
<pre class="brush: php">

&lt;?php

include_once &#039;../app/Mage.php&#039;;

Mage::app();

try{
// usage /scripts/addToCart.php?product_id=838&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;qty=1
// product_id OR sku is required

// get query string
if (!isset($_GET[&#039;sku&#039;])) { $sku = &#039;&#039;; } else { $sku = $_GET[&#039;sku&#039;]; }
if (!isset($_GET[&#039;product_id&#039;])) { $product_id = &#039;&#039;; } else { $product_id = $_GET[&#039;product_id&#039;]; }
if (!isset($_GET[&#039;qty&#039;])) { $qty = &#039;1&#039;; } else { $qty = $_GET[&#039;qty&#039;]; }

if ($sku != &quot;&quot;){
$product_id = Mage::getModel(&#039;catalog/product&#039;)-&gt;getIdBySku(&quot;$sku&quot;);
if ($product_id == &#039;&#039;) {
$session-&gt;addError(&quot;&lt;strong&gt;Product Not Added&lt;/strong&gt;&lt;br /&gt;The SKU you entered ($sku) was not found.&quot;);
}
}

$request = Mage::app()-&gt;getRequest();

$product = Mage::getModel(&#039;catalog/product&#039;)-&gt;load($product_id);

$session = Mage::getSingleton(&#039;core/session&#039;, array(&#039;name&#039;=&gt;&#039;frontend&#039;));
$cart = Mage::helper(&#039;checkout/cart&#039;)-&gt;getCart();

$cart-&gt;addProduct($product, $qty);

$session-&gt;setLastAddedProductId($product-&gt;getId());
$session-&gt;setCartWasUpdated(true);

$cart-&gt;save();

$result = &quot;{&#039;result&#039;:&#039;success&#039;}&quot;;

echo $result;

} catch (Exception $e) {
$result = &quot;{&#039;result&#039;:&#039;error&#039;&quot;;
$result .= &quot;, &#039;message&#039;: &#039;&quot;.$e-&gt;getMessage().&quot;&#039;}&quot;;
echo $result;
}
</pre>
<h2>Buy Now Button</h2>
<p>Then I need a &#8220;Buy Now&#8221; button that doesn&#8217;t do a post to the server that I can attach my jQuery code to.  I&#8217;ve added the sku as an attribute to the anchor because I have this in a page that has more than one product on the page and I need to know which product has been selected.</p>
<pre class="brush: html">

&lt;a href=&quot;#&quot; sku=&quot;&lt;?php echo $this-&gt;__($product-&gt;sku) ?&gt;&quot;&gt;&lt;img src=&quot;/media/upload/image/product-details/buy-now.jpg&quot; border=0 alt=&quot;&lt;?php echo $this-&gt;__(&#039;Buy Now&#039;) ?&gt;&quot;&gt;&lt;/a&gt;
</pre>
<h2>Client Script</h2>
<p>Finally, I need the client script that gets attached to the button and calls the server &#8220;addToCart.php&#8221; page.</p>
<pre class="brush: js">

/* Cart */
jQuery(document).ready(function($) {
$.ui.dialog.defaults.bgiframe = true;

$(&quot;.add-to-cart&quot;).click(function(e){
var buyNow = $(e.currentTarget);
var listingItem = $(buyNow).closest(&quot;.listing-item&quot;);
var colorSelector = $(&quot;#colorSelector&quot;, listingItem);
var product_id = colorSelector.val();

if (product_id == &quot;&quot;){
showDialog(&quot;Please select a color.&quot;, &quot;Missing Information&quot;);
return false;
}

var stockStatus = $(&quot;option:selected&quot;, colorSelector).attr(&quot;stockstatus&quot;);
if (stockStatus == &quot;out of stock&quot;){
showDialog(&quot;Sorry, that colour is currently unavailable.&quot;, &quot;Out of Stock&quot;)
return false;
}

var qty = $(&quot;#quantity&quot;, listingItem).val();

if (qty == &quot;&quot;){
qty = &quot;1&quot;;
}

$(this).siblings(&quot;.ajax-loader&quot;).show();
var obj = this;

var params = &quot;product_id=&quot; + product_id + &quot;&amp;amp;amp;amp;amp;amp;qty=&quot; + qty;

var result = $.getJSON(&quot;/scripts/addToCart.php&quot;, params, function(data, textStatus){
$(obj).siblings(&quot;.ajax-loader&quot;).hide();

if (textStatus == &quot;error&quot;){
showDialog(&quot;There was an error adding this item to your cart.  Please call customer service for assistance.&quot;, &quot;Error&quot;);
return;
}

if (data.result == &quot;error&quot;){
showDialog(&quot;Sorry, an error occurred while adding the item to your cart.  The error was: &#039;&quot; + data.message + &quot;&#039;&quot;);
return;
}

// SHOW FEEDBACK, ERRORS AND RELATED ITEMS
} // end add to cart

function showDialog(msg, title){
$(&quot;#dialog&quot;).dialog( &#039;destroy&#039; );
$(&quot;#dialog&quot;).html(msg);

$(&quot;#dialog&quot;).dialog({
buttons: {
&quot;Ok&quot;: function() {
$(this).dialog(&quot;close&quot;);
}
}
// , closeOnEscape: true
// , show: &#039;slide&#039;
});

$(&#039;#dialog&#039;).dialog(&#039;option&#039;, &#039;title&#039;, title);
$(&quot;#dialog&quot;).dialog(&#039;open&#039;);
}
});
</pre>
<p>Few things probably need some explanation:</p>
<p>1. I&#8217;ve attached the function to ALL add to cart buttons using the &#8220;add-to-cart&#8221; class.  (There are multiple products on the page.)</p>
<p>2. Each product has a color selector that has the product_id as the value in the drop down.  There&#8217;s also an additional attribute called &#8220;stockstatus&#8221; that will let me know if the color is out of stock.  My customer didn&#8217;t want to hide the out of stock colors, but I obviously can&#8217;t let anyone order them.</p>
<p>3. I put a little animated gif (the &#8220;ajax loader&#8221;) on the page and that gets displayed when the ajax call is being made.</p>
<p>4. If there is an error, I display it using the jQuery UI library and a little showdialog helper function.</p>
<p>5. There&#8217;s a feedback panel that shows related items, but I&#8217;ve removed that in this code just to make it easier to follow.</p>
<p>So there it is.  Hope this helps someone.  And if there are better ways to do this, I&#8217;d love to hear them!</p>
<p>[Update:  I removed the reference to common.php in the code above because it's not needed.  It had some common user functions in it that aren't necessary for this sample]</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.ifuelinteractive.com/2009/09/10/adding-to-the-cart-with-a-jquery-ajax-call-in-magento/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
