<?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>Magento design, development and suport :: sonassi &#187; Magento</title>
	<atom:link href="http://www.sonassi.com/category/knowledge-base/magento-knowledge-base/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sonassi.com</link>
	<description>Latest press releases, tutorials and thoughts on the world can be found here</description>
	<lastBuildDate>Wed, 18 Jan 2012 14:06:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Magento batch update category quick script</title>
		<link>http://www.sonassi.com/knowledge-base/magento-knowledge-base/magento-batch-update-category-quick-script/</link>
		<comments>http://www.sonassi.com/knowledge-base/magento-knowledge-base/magento-batch-update-category-quick-script/#comments</comments>
		<pubDate>Fri, 09 Sep 2011 17:48:28 +0000</pubDate>
		<dc:creator>Benjamin</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[bulk category update magento]]></category>
		<category><![CDATA[magento bulk category images]]></category>
		<category><![CDATA[magento bulk category update]]></category>
		<category><![CDATA[magento category update]]></category>
		<category><![CDATA[magento import category]]></category>
		<guid isPermaLink="false">http://www.sonassi.com/?p=2123</guid>
		<description><![CDATA[Just to supplement another post we made on bulk creating categories, below is a script used for bulk updating and attaching images to categories based on a specific CSV. There is no documentation to go with this code, I&#8217;m simply &#8230; <a href="http://www.sonassi.com/knowledge-base/magento-knowledge-base/magento-batch-update-category-quick-script/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Just to supplement another post we made on <a href="http://www.sonassi.com/knowledge-base/quick-script-batch-create-magento-categories/" title="bulk creating categories in Magento">bulk creating categories</a>, below is a script used for bulk updating and attaching images to categories based on a specific CSV. </p>
<p>There is no documentation to go with this code, I&#8217;m simply posting it because a subscriber has requested it.</p>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
 <span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MAGENTO'</span><span style="color: #339933;">,</span> <span style="color: #990000;">realpath</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/..&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">require_once</span> MAGENTO <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/app/Mage.php'</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #990000;">umask</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 Mage<span style="color: #339933;">::</span><span style="color: #004000;">app</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCurrentStore</span><span style="color: #009900;">&#40;</span>Mage_Core_Model_App<span style="color: #339933;">::</span><span style="color: #004000;">ADMIN_STORE_ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$write</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;">$count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$headers</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span>MAGENTO <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/var/import/importcats.csv'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'r'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #000088;">$_category</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;">'catalog/category'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$line</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fgetcsv</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$count</span><span style="color: #339933;">++;</span>
&nbsp;
 <span style="color: #666666; font-style: italic;">// First header row</span>
 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$count</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$line</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$id</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$col</span><span style="color: #009900;">&#41;</span>
 <span style="color: #000088;">$headers</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$col</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$id</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
&nbsp;
 <span style="color: #000088;">$_category</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$line</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$headers</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ID'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #000088;">$_category</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMetaTitle</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$line</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$headers</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'meta_title'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$_category</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMetaDescription</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$line</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$headers</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'meta_description'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$_category</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setDescription</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$line</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$headers</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'additional_description'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$_category</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setUrlKey</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$line</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$headers</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url_key'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INSERT INTO catalog_category_entity_varchar
 (entity_type_id, attribute_id, store_id, entity_id, value)
 VALUES
 (9, 113, 0, &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$line</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$headers</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ID'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;, '&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$line</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$headers</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;')
 ON DUPLICATE KEY UPDATE value = '&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$line</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$headers</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;';
 &quot;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #000088;">$write</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>
&nbsp;
 <span style="color: #000088;">$src</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'../media/import/cat_imgs/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$line</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$headers</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$dest</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'../media/catalog/category/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$line</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$headers</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #990000;">copy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dest</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #000088;">$_category</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>
&nbsp;
 <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Completed &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$line</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$headers</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #009900;">&#125;</span></pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.sonassi.com/knowledge-base/magento-knowledge-base/magento-batch-update-category-quick-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento My Imeta Bug fix on category save</title>
		<link>http://www.sonassi.com/knowledge-base/magento-knowledge-base/magento-my-imeta-bug-fix-on-category-save/</link>
		<comments>http://www.sonassi.com/knowledge-base/magento-knowledge-base/magento-my-imeta-bug-fix-on-category-save/#comments</comments>
		<pubDate>Fri, 02 Sep 2011 13:19:41 +0000</pubDate>
		<dc:creator>Benjamin</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[category not saving magento]]></category>
		<category><![CDATA[magento category save crash]]></category>
		<category><![CDATA[magento category save hang]]></category>
		<category><![CDATA[magento my imeta]]></category>
		<guid isPermaLink="false">http://www.sonassi.com/?p=2116</guid>
		<description><![CDATA[A customer recently came to us stating their categories were not saving correctly, it turned out to be a bit of erroneous code in a 3rd party extension they were using. If you are using My_Imeta and are experiencing difficulties &#8230; <a href="http://www.sonassi.com/knowledge-base/magento-knowledge-base/magento-my-imeta-bug-fix-on-category-save/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A customer recently came to us stating their categories were not saving correctly, it turned out to be a bit of erroneous code in a 3rd party extension they were using.</p>
<p>If you are using <a href="http://www.magentocommerce.com/magento-connect/Theodore+Doan/extension/5433/my_imeta/"><strong>My_Imeta</strong></a> and are experiencing difficulties saving your categories, it will be due to this. It is a quick an easy fix.</p>
<p>Open <code>./app/code/community/My/Imeta/Model/Catalog/Category/Observer.php</code></p>
<p>Then replace</p>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$_object</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$observer</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'data_object'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$observer</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'data_object'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$observer</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'object'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>
<p>With</p>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$_object</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$observer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getEvent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCategory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.sonassi.com/knowledge-base/magento-knowledge-base/magento-my-imeta-bug-fix-on-category-save/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento category children count fix</title>
		<link>http://www.sonassi.com/knowledge-base/magento-knowledge-base/magento-category-children-count-fix/</link>
		<comments>http://www.sonassi.com/knowledge-base/magento-knowledge-base/magento-category-children-count-fix/#comments</comments>
		<pubDate>Wed, 31 Aug 2011 13:52:59 +0000</pubDate>
		<dc:creator>Benjamin</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[children_count magento]]></category>
		<category><![CDATA[magento category count]]></category>
		<category><![CDATA[magento children category count]]></category>
		<category><![CDATA[magento children_count]]></category>
		<guid isPermaLink="false">http://www.sonassi.com/?p=2111</guid>
		<description><![CDATA[The children_count field in Magento can sometimes become inaccurate if you have created a category via the PHP API and set an entity_id whilst doing so. It is due to part of the after_save mechanism which overrides the children_count parameter &#8230; <a href="http://www.sonassi.com/knowledge-base/magento-knowledge-base/magento-category-children-count-fix/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The <code>children_count</code> field in Magento can sometimes become inaccurate if you have created a category via the PHP API and set an <code>entity_id</code> whilst doing so. It is due to part of the <code>after_save</code> mechanism which overrides the <code>children_count</code> parameter (even if explicitly set via <code>$_category->setChildrenCount()</code>).</p>
<p>For the majority of the admin area, an inaccurate children count won&#8217;t normally pose an issue, however, upon using the AJAX category tree (Eg. in product edit, promotional rules etc.) &#8211; any category with an inaccurate children count may not display the expand icon.</p>
<p>It can quickly and easily be reset, albeit with a bit of quick and dirty SQL.</p>
<pre class="brush:mysql">
CREATE TABLE catalog_category_entity_tmp LIKE catalog_category_entity;
INSERT INTO catalog_category_entity_tmp SELECT * FROM catalog_category_entity;
UPDATE catalog_category_entity cce
SET children_count =
(
SELECT count(cce2.entity_id) as children_county
FROM catalog_category_entity_tmp cce2
WHERE PATH LIKE CONCAT(cce.path,'%')
);
DROP TABLE catalog_category_entity_tmp;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.sonassi.com/knowledge-base/magento-knowledge-base/magento-category-children-count-fix/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Benchmarking your Magento store</title>
		<link>http://www.sonassi.com/knowledge-base/magento-knowledge-base/benchmarking-your-magento-store/</link>
		<comments>http://www.sonassi.com/knowledge-base/magento-knowledge-base/benchmarking-your-magento-store/#comments</comments>
		<pubDate>Sun, 19 Jun 2011 18:44:57 +0000</pubDate>
		<dc:creator>Benjamin</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[ab]]></category>
		<category><![CDATA[apache jmeter]]></category>
		<category><![CDATA[apachebench]]></category>
		<category><![CDATA[benchmark magento]]></category>
		<category><![CDATA[gtmetix]]></category>
		<category><![CDATA[how can i test the speed of my store]]></category>
		<category><![CDATA[jmeter]]></category>
		<category><![CDATA[magebenchmark]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[magento performance]]></category>
		<category><![CDATA[pingdom]]></category>
		<category><![CDATA[siege]]></category>
		<guid isPermaLink="false">http://www.sonassi.com/?p=2052</guid>
		<description><![CDATA[We get asked this quite a lot by normal store owners who want to see how good their host really is. However, our Magento Benchmark service is only really aimed at web hosts themselves. So to answer a popular question &#8230; <a href="http://www.sonassi.com/knowledge-base/magento-knowledge-base/benchmarking-your-magento-store/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>We get asked this quite a lot by normal store owners who want to see how good their host really is. However, our <a href="http://magebenchmark.sonassi.com" title="Magento Benchmark">Magento Benchmark</a> service is only really aimed at web hosts themselves.</p>
<p>So to answer a popular question (albeit briefly):</p>
<p>There isn’t a standardised test – as there is a myriad of different testing procedures.</p>
<div style="background:#fff; border:6px solid #EDB0AD;padding:10px">
<p><strong>ApacheBench / Siege</strong><br />
Will test PHP performance and PHP processing concurrency only (results are skewed by caching)</p>
<p><strong>GTMetrix </strong><br />
Will test the overall page load time for 1 user (however, the template weight/complexity has a bigger effect on this than server performance)</p>
<p><strong>Pingdom FPT</strong><br />
Much the same as GTMetrix (the results for this are even more skewed though, as it downloads ALL content in the CSS files too – not indicative of real-world load)</p>
<p><strong>Apache jMeter</strong><br />
Will test PHP performance, concurrency, static content delivery, template performance and can replicate real-world browsing habits of customers; adding to basket etc.)
</div>
<p>&nbsp;</p>
<p>
Apache jMeter is our tool of choice, it is a little tricky to configure – but allows you to tailor your test exactly to your type of expected customers browsing habits. By controlling the number of pages they browse, page view time, replicating checkout process, logging in/out etc. It is as close to real-world simulation as you will get.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sonassi.com/knowledge-base/magento-knowledge-base/benchmarking-your-magento-store/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Quickly associate images to your Magento products without using dataflow</title>
		<link>http://www.sonassi.com/knowledge-base/quickly-associate-images-to-your-magento-products-without-using-dataflow/</link>
		<comments>http://www.sonassi.com/knowledge-base/quickly-associate-images-to-your-magento-products-without-using-dataflow/#comments</comments>
		<pubDate>Sat, 18 Jun 2011 17:15:54 +0000</pubDate>
		<dc:creator>Benjamin</dc:creator>
				<category><![CDATA[Knowledge Base]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[image association magento]]></category>
		<category><![CDATA[import images magento]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[magento image import]]></category>
		<guid isPermaLink="false">http://www.sonassi.com/?p=2045</guid>
		<description><![CDATA[Dataflow is great and does allow the association of multiple images natively, but upon wanting to add around 2,500 product images to a catalogue in Magento 1.5.0.1 &#8211; we noticed that they have broke the core support in dataflow for &#8230; <a href="http://www.sonassi.com/knowledge-base/quickly-associate-images-to-your-magento-products-without-using-dataflow/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Dataflow is great and does allow the association of multiple images natively, but upon wanting to add around 2,500 product images to a catalogue in Magento 1.5.0.1 &#8211; we noticed that they have broke the core support in dataflow for this, <span style="font-style:italic;">great!</span></p>
<p>So instead, we just knocked up a quick script which would associate images to products; the name name has to match the product SKU (with the exception of the file extension). It first copies the images from your media/import directory to the proper Magento structure, </p>
<p>eg. For an image named sonassi.jpg</p>
<p><code>./media/catalog/product/s/o/sonassi.jpg</code></p>
<p>If the directory doesn&#8217;t exist, it will create it on the fly. Then once the images are in place, it will check to see what images are to be added &#8211; then check each product to see if any images are already set, and skip those images if already set.</p>
<p>There is a few different types of images for a product:<br />
<code><br />
small_image<br />
base_image<br />
thumbnail<br />
gallery_image<br />
</code><br />
These have different attribute ids (can be found in eav_entity_attribute), for us the IDs were 74,75,76 and 77 respectively. Then, its just a case of running the script. </p>
<p>To create the directory structure, copy the images and populate the database took under 1 second for 2,500 images; so whilst not the proper Magento way &#8211; its saved you a few hours of Dataflow! As always, the below script assumes that the script exists in a subdirectory of the root Magento installation.</p>
<p>Enjoy!</p>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">############################################################################
</span>  <span style="color: #666666; font-style: italic;">#
</span>  <span style="color: #666666; font-style: italic;">#  Change these variables to suit your store!
</span>  <span style="color: #666666; font-style: italic;">#
</span>  <span style="color: #000088;">$_mediaBase</span> <span style="color: #339933;">=</span> <span style="color: #990000;">realpath</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'../media/catalog/product'</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;">$_imagesSrc</span> <span style="color: #339933;">=</span> <span style="color: #990000;">realpath</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'../media/import/product_images'</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;">$imgAttrIds</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">74</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">75</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">76</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$imageGalId</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">77</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'../app/Mage.php'</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">#
</span>  <span style="color: #666666; font-style: italic;">############################################################################
</span>
  <span style="color: #990000;">umask</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #990000;">error_reporting</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">E_ALL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'display_errors'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Mage<span style="color: #339933;">::</span><span style="color: #004000;">setIsDeveloperMode</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  Mage<span style="color: #339933;">::</span><span style="color: #004000;">app</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCurrentStore</span><span style="color: #009900;">&#40;</span>Mage_Core_Model_App<span style="color: #339933;">::</span><span style="color: #004000;">ADMIN_STORE_ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$conn</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;">$connW</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: #000088;">$images</span> <span style="color: #339933;">=</span> <span style="color: #990000;">scandir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_imagesSrc</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
  <span style="color: #666666; font-style: italic;">/*
   *    Relocate the images into Magento friendly format
   */</span>
&nbsp;
  <span style="color: #000088;">$imgArr</span> <span style="color: #339933;">=</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: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$images</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$image</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: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'..'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$firstDir</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_mediaBase</span><span style="color: #339933;">.</span><span style="color: #000088;">$image</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$secondDir</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$firstDir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$image</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$path</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$secondDir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$image</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;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Making <span style="color: #006699; font-weight: bold;">$secondDir</span> and copying to <span style="color: #006699; font-weight: bold;">$path</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$secondDir</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #990000;">mkdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$secondDir</span><span style="color: #339933;">,</span> <span style="color: #208080;">0775</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #990000;">copy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_imagesSrc</span><span style="color: #339933;">.</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000088;">$imgArr</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">str_ireplace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.jpg&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$image</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT *
          FROM catalog_product_entity
          WHERE sku IN (&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$imgArr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;)&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$_products</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$conn</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: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$entitySkuMap</span> <span style="color: #339933;">=</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: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_products</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$product</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000088;">$entitySkuMap</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$product</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sku'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$product</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'entity_id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">/*
   *    Check the existing images
   */</span>
&nbsp;
  <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT *
          FROM catalog_product_entity_media_gallery
          WHERE entity_id IN (&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$entitySkuMap</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;)&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$_galleryImgs</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$conn</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: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT *
          FROM catalog_product_entity_varchar
          WHERE entity_id IN (&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$entitySkuMap</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;)
          AND attribute_id IN (&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$imgAttrIds</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;)&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$_imageAssoc</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$conn</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: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$existingImgs</span> <span style="color: #339933;">=</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: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_imageAssoc</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$existingImgs</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$img</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'entity_id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$img</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'attribute_id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$img</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">/*
   *    Then associate to the product itself.
   */</span>
&nbsp;
  <span style="color: #000088;">$insertData</span> <span style="color: #339933;">=</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: #000088;">$skusToInsert</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</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;">$_products</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$productArrId</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$product</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000088;">$missingImgs</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$imgAttrIds</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$imageName</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$product</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sku'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$product</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sku'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$product</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sku'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.jpg'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Check if it has an image associated already ...</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$product</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'entity_id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$existingImgs</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// Check which images exists and remove those already set</span>
      <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$imgAttrIds</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$id</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$val</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: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$val</span> <span style="color: #339933;">,</span> <span style="color: #000088;">$existingImgs</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$product</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'entity_id'</span><span style="color: #009900;">&#93;</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: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$existingImgs</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$product</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'entity_id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;no_selection&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;DELETE FROM catalog_product_entity_varchar WHERE value_id = '&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$existingImgs</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$product</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'entity_id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value_id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$connW</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>
          <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$missingImgs</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$id</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: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$missingImgs</span><span style="color: #009900;">&#41;</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: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_mediaBase</span><span style="color: #339933;">.</span><span style="color: #000088;">$imageName</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$missingImgs</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$insertData</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;(4, &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$img</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;, 0, &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$product</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'entity_id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;, '&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$imageName</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;')&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$skusToInsert</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;(&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$imageGalId</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;, &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$product</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'entity_id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;, '&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$imageName</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;')&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">/*
   *    Now add the images to the DB
   */</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$skusToInsert</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INSERT INTO catalog_product_entity_media_gallery (attribute_id, entity_id, value) VALUES &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$skusToInsert</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$connW</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>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Updated &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$skusToInsert</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; images<span style="color: #000099; font-weight: bold;">\n</span>&quot;</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;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$insertData</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INSERT INTO catalog_product_entity_varchar (entity_type_id, attribute_id, store_id, entity_id, value) VALUES &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$insertData</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$connW</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>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Updated &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$insertData</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; images&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.sonassi.com/knowledge-base/quickly-associate-images-to-your-magento-products-without-using-dataflow/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Magento Go SAAS announced</title>
		<link>http://www.sonassi.com/blogs/magento-go-saas-announced/</link>
		<comments>http://www.sonassi.com/blogs/magento-go-saas-announced/#comments</comments>
		<pubDate>Tue, 08 Feb 2011 19:10:59 +0000</pubDate>
		<dc:creator>Benjamin</dc:creator>
				<category><![CDATA[Blogs]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[go magento]]></category>
		<category><![CDATA[magento go]]></category>
		<category><![CDATA[magento imagine]]></category>
		<category><![CDATA[magento partner program]]></category>
		<category><![CDATA[magento saas]]></category>
		<category><![CDATA[saas magento]]></category>
		<category><![CDATA[varien]]></category>
		<guid isPermaLink="false">http://www.sonassi.com/?p=1998</guid>
		<description><![CDATA[What is Magento Go Consulting, technical support, use and hosting services for the performance of e-commerce transactions; Software as a Service (SaaS) featuring computer software to allow users to perform electronic business transactions in the field of ecommerce. Attendees of &#8230; <a href="http://www.sonassi.com/blogs/magento-go-saas-announced/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h3>What is Magento Go</h3>
<p><img class="right" src="http://www.sonassi.com/wp-content/uploads/2011/02/magento-go-300x111.png" alt="" title="magento-go" width="300" height="111" class="alignnone size-medium wp-image-2001" /></p>
<p>Consulting, technical support, use and hosting services for the performance of e-commerce transactions; Software as a Service (SaaS) featuring computer software to allow users to perform electronic business transactions in the field of ecommerce.</p>
<p>Attendees of Magento Imagine will be familiar with the above branding and concept, but official release isn&#8217;t quite due so information is being kept quiet for now, so we can only speculate as to its purpose. </p>
<p>From an outsider of the <strong>Magento Imagine</strong> conference, I&#8217;ve probably taken the entirely wrong view of this or at least <strong>I certainly hope I&#8217;m wrong</strong>.</p>
<p class="h3 cu-myprocond">Magento SAAS was inevitable</p>
<p>If it is what we think is it, it was only a matter of time before Varien began to offer <strong>turnkey Magento solutions</strong>. But it does beg the question, what is to happen to the &#8220;paid-up&#8221; <a href="http://www.magentocommerce.com/partners/hosting-partners" rel="external">Magento hosting</a> and <a rel="external" href="http://www.magentocommerce.com/partners/solution-partners">Magento development</a> partners (<em>read members</em>, you have to buy your way in).</p>
<p><strong>Setting the foundations in place</strong></p>
<p>The <a rel="external" href="http://www.magentocommerce.com/partners">Magento partner program</a> was launched quite a while ago in its early form, offering a single grade of registration for a nominal yearly fee. Since then, Varien&#8217;s revenue scheme has grown and changed shape slightly; from the community based, <em>free</em>, open-source product with optional chargeable support; to an enterprise application with enterprise level support.</p>
<p>Now, Varien offers three core products, Magento Community Edition, Magento Professional and Magento Enterprise. To facilitate quick, rapid and convincing deployment of these chargeable flavours &#8211; distributors were recruited, these firms are known as Magento partners.</p>
<p><strong>Agencies ready, Hosting providers ready &#8230;</strong></p>
<p>So, with a league of willing developers and hosting providers in tow, Varien are positioned correctly to set the flip the e-commerce market up-side down. This is where <strong>Magento Go</strong> comes in. With all the afore-mentioned groundwork that Varien have put in &#8211; it would seem bizarre if their new turnkey operation was provided solely in-house.</p>
<p>So, it looks like Varien might just set in place a strategic standardisation of quality and delivery, governing their partners on best-practice; in return, handing over the initial and future development of any <strong>Magento Go</strong> store to a Magento solution partner. </p>
<p>I can&#8217;t quite figure out how the hosting partners might be involved in this though. If you remember, around 1 year ago, Varien ran a webinar on Magento performance, specifically tied with Zend Server. There were some white papers released after this, but it was never really reinforced or actively promoted. Perhaps Zend and Varien have teamed together to provide a standalone environment, with a recommended infrastructure and user interface. This could then be effectively handed over to a Magento hosting partner to provide a distributed service with centralised billing and management.</p>
<p class="h3 cu-myprocond">Worst case scenario</p>
<p>The unified structure above would mean Varien not only monopolising the Magento development and hosting workspace, but potentially dictating full control.</p>
<p><strong>BUT and its a big one</strong></p>
<p>There are some potential pitfalls for agencies for those that don&#8217;t buy in, but no more than that of other real-world businesses. Take the car industry for example, you have the option of taking your BMW to the dealership for a service, or your local independent garage. Hopefully, competition will stay active enough for everyone to thrive from Magento and specifically, Magento Go. Which leads me on to say that &#8230;</p>
<h2>Scaremongering aside &#8211; Magento Go has A LOT of benefits</h2>
<p>This is potentially a developers dream. Imagine a standardised platform providing infinite levels of integration, with existing, well developed links with common service providers (SagePay, SecureTrading, ParcelForce, UPS etc.) and a library of web services to integrate with your client&#8217;s in-house services.</p>
<p>With a large proportion of Magento stores hosted in a central location, monitoring, reporting and debugging information could easily be fed straight back to Varien&#8217;s core development team. Giving them valuable automated feedback as to where improvements can be made. This could ensure a stable, secure and highly optimised Magento core that will benefit everyone.</p>
<p>It could remove the reliance on 3rd party extensions, moving all functionality to the core, <strong>safe and secure</strong>.</p>
<p>But its not just developers who will benefit, the end-user, your clients, could reap massive rewards. A centralised database of every Magento stores&#8217; products could offer uniformity of data &#8211; resulting in quick, painless product population with a wealth of accurate, rich attributes at your fingertips. </p>
<p>The future then provides potential of distributors dealing direct with Varien, giving the end user access to cheaper supplies or drop shipping services.</p>
<h3>Magento Go, a real game changer</h3>
<p>This platform has infinite potential for good and an equally large potential for bad, the only comment I can close on, is &#8230;</p>
<p><strong>With great power, comes great responsibility</strong></p>
<p>Read more about Magento Go <a href="http://www.magentocommerce.com/getready.html" rel="external" title="Magento Go">http://www.magentocommerce.com/getready.html</a><br />
Watch a video about Magento Go <a href="http://www.youtube.com/watch?v=2CyIJpEeoF0" rel="external">http://www.youtube.com/watch?v=2CyIJpEeoF0</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sonassi.com/blogs/magento-go-saas-announced/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Automatically change the VAT rate on 4th January</title>
		<link>http://www.sonassi.com/knowledge-base/magento-knowledge-base/automatically-change-the-vat-rate-on-1st-january/</link>
		<comments>http://www.sonassi.com/knowledge-base/magento-knowledge-base/automatically-change-the-vat-rate-on-1st-january/#comments</comments>
		<pubDate>Fri, 03 Dec 2010 17:41:30 +0000</pubDate>
		<dc:creator>Benjamin</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[20% vat magento]]></category>
		<category><![CDATA[auto change tax magento]]></category>
		<category><![CDATA[auto change vat magento]]></category>
		<category><![CDATA[automatic tax change magento]]></category>
		<category><![CDATA[magento change tax automatically]]></category>
		<category><![CDATA[magento tax auto change]]></category>
		<category><![CDATA[magento tax change 1st jan]]></category>
		<category><![CDATA[vat change magento]]></category>
		<guid isPermaLink="false">http://www.sonassi.com/?p=1687</guid>
		<description><![CDATA[Unless you are lucky enough to have a development agency that is willing to make changes to your store just after New Years Day, you might benefit from running this little script. With the proposed change to 20% on January &#8230; <a href="http://www.sonassi.com/knowledge-base/magento-knowledge-base/automatically-change-the-vat-rate-on-1st-january/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Unless you are lucky enough to have a development agency that is willing to make changes to your store just after New Years Day, you might benefit from running this little script. With the proposed change to 20% on January 4th 2011, you can automate the rate change in your Magento installation. </p>
<p>You&#8217;ll need to set a few variables, then set-up a cron to run the job. We made the script standalone as a not all people have set up their Magento crons.</p>
<p>First, go to &#8220;Admin > Sales > Tax > Manage Tax Zones &#038; Rates&#8221;, then select your UK VAT rate.</p>
<p><img src="http://www.sonassi.com/wp-content/uploads/2010/12/ratescreen.png" alt="ratescreen" title="ratescreen" width="675" height="233" class="alignnone size-full wp-image-1688" /></p>
<p>Then look in the URL at the top to identify the ID of the rule,</p>
<p><img src="http://www.sonassi.com/wp-content/uploads/2010/12/rateid.png" alt="rateid" title="rateid" width="621" height="64" class="alignnone size-full wp-image-1689" /></p>
<p>Then, create the file below (wherever you want), and set <code>magento</code>, <code>tax_rule</code> and <code>admin_email</code> with your own details. You can check if the script will execute correctly by setting the <code>is_test_run</code> flag to <code>true</code>.</p>
<p>Then create the cron job, we&#8217;ve set it to run every hour, every day &#8211; just in case!</p>
<p><img src="http://www.sonassi.com/wp-content/uploads/2010/12/cronjob.png" alt="cronjob" title="cronjob" width="570" height="103" class="alignnone size-full wp-image-1690" /></p>
<p>And finally, create the <code>AutoTax.php</code> script itself using the code below:</p>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
  <span style="color: #990000;">set_time_limit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">86400</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'memory_limit'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'128M'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$op</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
          <span style="color: #0000ff;">'magento'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</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: #666666; font-style: italic;">// the relative directory to your base Magento directory</span>
          <span style="color: #0000ff;">'tax_rule'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'3'</span><span style="color: #339933;">,</span>                   <span style="color: #666666; font-style: italic;">// the id of the tax rule to change</span>
          <span style="color: #0000ff;">'date_change'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'04-01-2011'</span><span style="color: #339933;">,</span>          <span style="color: #666666; font-style: italic;">// the date of the change. eg. 01-01-2011</span>
          <span style="color: #0000ff;">'new_rate'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'20'</span><span style="color: #339933;">,</span>                  <span style="color: #666666; font-style: italic;">// the new tax rate</span>
          <span style="color: #0000ff;">'admin_email'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'your@email.com'</span><span style="color: #339933;">,</span>      <span style="color: #666666; font-style: italic;">// the confirmation email recipient</span>
          <span style="color: #0000ff;">'is_test_run'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span>                   <span style="color: #666666; font-style: italic;">// run a test first eg. true/false</span>
             <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># Do not change anything below this line
</span>  <span style="color: #b1b100;">require_once</span> <span style="color: #000088;">$op</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'magento'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'app/Mage.php'</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">umask</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Mage<span style="color: #339933;">::</span><span style="color: #004000;">app</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCurrentStore</span><span style="color: #009900;">&#40;</span>Mage_Core_Model_App<span style="color: #339933;">::</span><span style="color: #004000;">ADMIN_STORE_ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Varien_Object<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setData</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$op</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$rateId</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTaxRule</span><span style="color: #009900;">&#40;</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;">$rateId</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$rateModel</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;">'tax/calculation_rate'</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;">$rateId</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    Mage<span style="color: #339933;">::</span><span style="color: #004000;">throwException</span><span style="color: #009900;">&#40;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tax'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Could not load tax rule'</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;">$oldModel</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rateModel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getData</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$timeToChange</span> <span style="color: #339933;">=</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDateChange</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: #990000;">time</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: #cc66cc;">86400</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;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getIsTestRun</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #339933;">||</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">app</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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: #0000ff;">'is_test'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000088;">$rateModel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setRate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNewRate</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;">echo</span> <span style="color: #0000ff;">&quot;Current data is:<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$oldModel</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Proposed new data is:<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rateModel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getData</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: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>With an effective change in &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$timeToChange</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; days&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;d-m-Y&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDateChange</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: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$rateModel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNewRate</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;
      try <span style="color: #009900;">&#123;</span>
&nbsp;
          <span style="color: #000088;">$rateModel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setRate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNewRate</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;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$rateModel</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: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$emailData</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Varien_Object<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$emailData</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setData</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'comment'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;AutoTax rate changed successfully!<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rateModel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getData</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'subject'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;AutoTax rate changed successfully!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            Mage<span style="color: #339933;">::</span><span style="color: #004000;">getModel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core/email_template'</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setTemplateSubject</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'AutoTax rate changed successfully!'</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">sendTransactional</span><span style="color: #009900;">&#40;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">getStoreConfig</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'contacts/email/email_template'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Sonassi AutoTax'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'email'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'contact@sonassi.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAdminEmail</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Customer'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'data'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$emailData</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            Mage<span style="color: #339933;">::</span><span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Tax rate changed successfully!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
          <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Save failed&quot;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
&nbsp;
          <span style="color: #666666; font-style: italic;">// see http://www.sonassi.com/knowledge-base/magento-knowledge-base/catalog-search-index-refresh-running-slow-or-haltingfreezing/</span>
          <span style="color: #666666; font-style: italic;">// 2. Product Prices Index product prices</span>
          <span style="color: #666666; font-style: italic;">// 4. Product Flat Data Reorganize EAV product structure to flat structure</span>
&nbsp;
          <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">version_compare</span><span style="color: #009900;">&#40;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">getVersion</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1.4'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&gt;='</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$id</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
              <span style="color: #000088;">$process</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;">'index/process'</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;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
              <span style="color: #000088;">$process</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">reindexAll</span><span style="color: #009900;">&#40;</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>
&nbsp;
      <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: #000088;">$e</span><span style="color: #339933;">;</span>
        Mage<span style="color: #339933;">::</span><span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Change in &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$timeToChange</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; days<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.sonassi.com/knowledge-base/magento-knowledge-base/automatically-change-the-vat-rate-on-1st-january/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Controlling the cache size when using database as a backend Magento</title>
		<link>http://www.sonassi.com/knowledge-base/magento-knowledge-base/controlling-the-cache-size-when-using-database-as-a-backend-magento/</link>
		<comments>http://www.sonassi.com/knowledge-base/magento-knowledge-base/controlling-the-cache-size-when-using-database-as-a-backend-magento/#comments</comments>
		<pubDate>Thu, 11 Nov 2010 16:14:48 +0000</pubDate>
		<dc:creator>Benjamin</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[big magento database]]></category>
		<category><![CDATA[core_cache]]></category>
		<category><![CDATA[core_cache_tag]]></category>
		<category><![CDATA[magento core_cache]]></category>
		<category><![CDATA[magento database large]]></category>
		<category><![CDATA[magento slow backend]]></category>
		<category><![CDATA[truncate core_cache]]></category>
		<guid isPermaLink="false">http://www.sonassi.com/?p=1678</guid>
		<description><![CDATA[If you have been using the database as a cache storage mechanism (Eg. ) and you have a large number of SKUs, you will start to see a database that increases in size by quite a measure. A customer of &#8230; <a href="http://www.sonassi.com/knowledge-base/magento-knowledge-base/controlling-the-cache-size-when-using-database-as-a-backend-magento/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you have been using the database as a cache storage mechanism (Eg. <code><slow_backend></code>) and you have a large number of SKUs, you will start to see a database that increases in size by quite a measure.</p>
<p>A customer of ours with around 160k SKUs, had a &#8220;core_cache&#8221; table that had grown to just under 10Gb and around 960k rows &#8211; causing difficulties during some operations due to table locks. Whilst it is safe to empty the table, truncating a 10Gb table will take quite a long time, and all the while it will be locked, causing connections to queue up, eventually maxing out the available connections for your MySQL user/total &#8211; <em>not good</em>.</p>
<p>To make it a little more manageable, we quickly added a little intelligence to the table, so that it can &#8220;self-rotate&#8221;. This could be applied in the PHP itself, but for now, it was quicker to address the issue via the DB directly.</p>
<p>Moving the old table out the way was essential to begin with</p>
<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #008000;">`new<span style="color: #008080; font-weight: bold;">_</span>core<span style="color: #008080; font-weight: bold;">_</span>cache`</span> <span style="color: #CC0099; font-weight: bold;">LIKE</span> <span style="color: #008000;">`core<span style="color: #008080; font-weight: bold;">_</span>cache`</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">RENAME</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #008000;">`core<span style="color: #008080; font-weight: bold;">_</span>cache`</span> <span style="color: #990099; font-weight: bold;">TO</span> <span style="color: #008000;">`old<span style="color: #008080; font-weight: bold;">_</span>core<span style="color: #008080; font-weight: bold;">_</span>cache`</span><span style="color: #000033;">,</span> <span style="color: #008000;">`new<span style="color: #008080; font-weight: bold;">_</span>core<span style="color: #008080; font-weight: bold;">_</span>cache`</span> <span style="color: #990099; font-weight: bold;">TO</span> <span style="color: #008000;">`core<span style="color: #008080; font-weight: bold;">_</span>cache`</span><span style="color: #000033;">;</span>
&nbsp;
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #008000;">`new<span style="color: #008080; font-weight: bold;">_</span>core<span style="color: #008080; font-weight: bold;">_</span>cache<span style="color: #008080; font-weight: bold;">_</span>tag`</span> <span style="color: #CC0099; font-weight: bold;">LIKE</span> <span style="color: #008000;">`core<span style="color: #008080; font-weight: bold;">_</span>cache<span style="color: #008080; font-weight: bold;">_</span>tag`</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">RENAME</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #008000;">`core<span style="color: #008080; font-weight: bold;">_</span>cache<span style="color: #008080; font-weight: bold;">_</span>tag`</span> <span style="color: #990099; font-weight: bold;">TO</span> <span style="color: #008000;">`old<span style="color: #008080; font-weight: bold;">_</span>core<span style="color: #008080; font-weight: bold;">_</span>cache<span style="color: #008080; font-weight: bold;">_</span>tag`</span><span style="color: #000033;">,</span> <span style="color: #008000;">`new<span style="color: #008080; font-weight: bold;">_</span>core<span style="color: #008080; font-weight: bold;">_</span>cache<span style="color: #008080; font-weight: bold;">_</span>tag`</span> <span style="color: #990099; font-weight: bold;">TO</span> <span style="color: #008000;">`core<span style="color: #008080; font-weight: bold;">_</span>cache<span style="color: #008080; font-weight: bold;">_</span>tag`</span><span style="color: #000033;">;</span>
&nbsp;
<span style="color: #990099; font-weight: bold;">ALTER</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #008000;">`core<span style="color: #008080; font-weight: bold;">_</span>cache<span style="color: #008080; font-weight: bold;">_</span>tag`</span> <span style="color: #990099; font-weight: bold;">ADD</span> <span style="color: #990099; font-weight: bold;">FOREIGN KEY</span> <span style="color: #FF00FF;">&#40;</span> <span style="color: #008000;">`cache<span style="color: #008080; font-weight: bold;">_</span>id`</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">REFERENCES</span> <span style="color: #008000;">`core<span style="color: #008080; font-weight: bold;">_</span>cache`</span> <span style="color: #FF00FF;">&#40;</span>
<span style="color: #008000;">`id`</span>
<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">ON</span> <span style="color: #990099; font-weight: bold;">DELETE</span> <span style="color: #990099; font-weight: bold;">CASCADE</span> <span style="color: #990099; font-weight: bold;">ON</span> <span style="color: #990099; font-weight: bold;">UPDATE</span> <span style="color: #990099; font-weight: bold;">CASCADE</span><span style="color: #000033;">;</span></pre></div></div>
<p>This then left us with the old two tables, which can be safely dropped in an instant</p>
<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">DROP</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #008000;">`old<span style="color: #008080; font-weight: bold;">_</span>core<span style="color: #008080; font-weight: bold;">_</span>cache<span style="color: #008080; font-weight: bold;">_</span>tag`</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">DROP</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #008000;">`old<span style="color: #008080; font-weight: bold;">_</span>core<span style="color: #008080; font-weight: bold;">_</span>cache`</span><span style="color: #000033;">;</span></pre></div></div>
<p>Looking at the number of rows, and volume of data, a safe average was for every 100,000 records stored, it consumed 1GB of space. To make the DB a little more manageable, we wanted to add a 100,000 row ceiling to the DB (we could also try to cap by size, but InnoDB cannot report an accurate size). The cap was put in place using a MySQL trigger. Essentially, when the table hits 100,000 records, it will rotate off the row that expires the soonest to allow room for the next row.</p>
<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TRIGGER</span> <span style="color: #008000;">`after<span style="color: #008080; font-weight: bold;">_</span>insert<span style="color: #008080; font-weight: bold;">_</span>core<span style="color: #008080; font-weight: bold;">_</span>cache<span style="color: #008080; font-weight: bold;">_</span>tag`</span> <span style="color: #990099; font-weight: bold;">AFTER</span> <span style="color: #990099; font-weight: bold;">INSERT</span> <span style="color: #990099; font-weight: bold;">ON</span> <span style="color: #008000;">`core<span style="color: #008080; font-weight: bold;">_</span>cache<span style="color: #008080; font-weight: bold;">_</span>tag`</span>
 <span style="color: #990099; font-weight: bold;">FOR EACH ROW</span> <span style="color: #990099; font-weight: bold;">BEGIN</span>
  <span style="color: #990099; font-weight: bold;">DECLARE</span> num_rows <span style="color: #999900; font-weight: bold;">INTEGER</span><span style="color: #000033;">;</span>
  <span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #000099;">count</span><span style="color: #FF00FF;">&#40;</span>id<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">INTO</span> num_rows <span style="color: #990099; font-weight: bold;">FROM</span> core_cache<span style="color: #000033;">;</span>
  <span style="color: #009900;">IF</span> num_rows <span style="color: #CC0099;">&gt;</span> <span style="color: #008080;">100000</span> <span style="color: #009900;">THEN</span>
    <span style="color: #990099; font-weight: bold;">DELETE</span> <span style="color: #990099; font-weight: bold;">FROM</span> core_cache
    <span style="color: #990099; font-weight: bold;">WHERE</span> expire_time <span style="color: #CC0099;">&gt;</span> <span style="color: #008080;">0</span>
    <span style="color: #990099; font-weight: bold;">ORDER BY</span> expire_time <span style="color: #990099; font-weight: bold;">ASC</span>
    <span style="color: #990099; font-weight: bold;">LIMIT</span> <span style="color: #008080;">1000</span><span style="color: #000033;">;</span>
  <span style="color: #009900;">END</span> <span style="color: #009900;">IF</span><span style="color: #000033;">;</span>
<span style="color: #009900;">END</span>
<span style="color: #CC0099;">//</span></pre></div></div>
<p>There is probably more efficient methods than this, but as a temporary resolve, it should keep things in check.</p>
<p>It may also be worth commenting/modifying any <code>thread_stack</code> definitions in your MySQL configuration if you run into errors when inserting rows.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sonassi.com/knowledge-base/magento-knowledge-base/controlling-the-cache-size-when-using-database-as-a-backend-magento/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Amasty multiple coupons bug fix for Magento 1.4.0.x</title>
		<link>http://www.sonassi.com/knowledge-base/magento-knowledge-base/amasty-multiple-coupons-bug-fix-for-magento-1-4-0-x/</link>
		<comments>http://www.sonassi.com/knowledge-base/magento-knowledge-base/amasty-multiple-coupons-bug-fix-for-magento-1-4-0-x/#comments</comments>
		<pubDate>Thu, 04 Nov 2010 16:37:24 +0000</pubDate>
		<dc:creator>Benjamin</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[amasty]]></category>
		<category><![CDATA[amasty coupons]]></category>
		<category><![CDATA[magento multiple coupons]]></category>
		<category><![CDATA[multiple coupons magento]]></category>
		<guid isPermaLink="false">http://www.sonassi.com/?p=1676</guid>
		<description><![CDATA[We installed the Amasty Mutiple Coupons extension for a client recently, but ran into a few hiccups immediately after installation. Fortunately, it is quickly fixed. In Amasty_Coupons_Model_Rewrite_Mysql4_Rule_Collection on line +62 + if &#40;version_compare&#40;Mage::getVersion&#40;&#41;, '1.4.1.0', '&#62;='&#41;&#41; $this-&#62;getSelect&#40;&#41;-&#62;where&#40;'main_table.coupon_type = ?', Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON&#41;;]]></description>
			<content:encoded><![CDATA[<p>We installed the <a href="http://www.magentocommerce.com/magento-connect/Amasty/extension/4660/multiple_coupons" title="Amasty Mutiple Coupons">Amasty Mutiple Coupons</a> extension for a client recently, but ran into a few hiccups immediately after installation. Fortunately, it is quickly fixed.</p>
<p>In <code>Amasty_Coupons_Model_Rewrite_Mysql4_Rule_Collection</code> on line <strong>+62</strong></p>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">+</span>          <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">version_compare</span><span style="color: #009900;">&#40;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">getVersion</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1.4.1.0'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&gt;='</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSelect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'main_table.coupon_type = ?'</span><span style="color: #339933;">,</span> Mage_SalesRule_Model_Rule<span style="color: #339933;">::</span><span style="color: #004000;">COUPON_TYPE_NO_COUPON</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.sonassi.com/knowledge-base/magento-knowledge-base/amasty-multiple-coupons-bug-fix-for-magento-1-4-0-x/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to fix PaymentSense&#8217;s gateway &#8220;orderStatus&#8221; error</title>
		<link>http://www.sonassi.com/knowledge-base/magento-knowledge-base/how-to-fix-paymentsenses-gateway-orderstatus-error/</link>
		<comments>http://www.sonassi.com/knowledge-base/magento-knowledge-base/how-to-fix-paymentsenses-gateway-orderstatus-error/#comments</comments>
		<pubDate>Thu, 04 Nov 2010 14:26:14 +0000</pubDate>
		<dc:creator>francois</dc:creator>
				<category><![CDATA[Magento]]></category>
		<guid isPermaLink="false">http://www.sonassi.com/?p=1662</guid>
		<description><![CDATA[We recently integrated the PaymentSense&#8217;s gateway for one of our customers. While making some test transactions, we noticed the extension raised a basic PHP error on the callback: Undefined variable: orderState in /http/app/code/local/Paymentsense/Paymentsensegateway/controllers/PaymentController.php on line 812 Hopefully, this error will &#8230; <a href="http://www.sonassi.com/knowledge-base/magento-knowledge-base/how-to-fix-paymentsenses-gateway-orderstatus-error/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>We recently integrated the PaymentSense&#8217;s gateway for one of our customers. While making some test transactions, we noticed the extension raised a basic PHP error on the callback:</p>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Undefined variable<span style="color: #339933;">:</span> orderState  in <span style="color: #339933;">/</span>http<span style="color: #339933;">/</span>app<span style="color: #339933;">/</span>code<span style="color: #339933;">/</span>local<span style="color: #339933;">/</span>Paymentsense<span style="color: #339933;">/</span>Paymentsensegateway<span style="color: #339933;">/</span>controllers<span style="color: #339933;">/</span>PaymentController<span style="color: #339933;">.</span>php on line <span style="color: #cc66cc;">812</span></pre></div></div>
<p> Hopefully, this error will be fixed in their new release.</p>
<h3>Undefined variable: orderState</h3>
<p>The following fix removed the error and assigned the right status to the order. If you still face problems after applying it, please let us know and we will update this ticket.</p>
<p>Editing on <code>app/code/local/Paymentsense/Paymentsensegateway/controllers/PaymentController.php</code> on line <code>+812</code>, change :</p>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setState</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$orderState</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'pys_paid'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$message</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>
<p>To</p>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setState</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$status</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'pys_paid'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$message</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.sonassi.com/knowledge-base/magento-knowledge-base/how-to-fix-paymentsenses-gateway-orderstatus-error/feed/</wfw:commentRss>
		<slash:comments>0</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 303/331 queries in 0.256 seconds using disk
Object Caching 24705/24794 objects using disk

Served from: www.sonassi.com @ 2012-02-11 01:53:24 -->
