<?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>gothi &#187; bugs</title>
	<atom:link href="http://www.gothi.co.uk/tag/bugs/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gothi.co.uk</link>
	<description>A badly chosen byte</description>
	<lastBuildDate>Thu, 26 Jan 2012 22:34:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Fixing WP e-Commerce</title>
		<link>http://www.gothi.co.uk/2010/02/fixing-wp-e-commerce/</link>
		<comments>http://www.gothi.co.uk/2010/02/fixing-wp-e-commerce/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 16:48:23 +0000</pubDate>
		<dc:creator>gothi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[e-Commerce]]></category>
		<category><![CDATA[Gold Cart]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.gothi.co.uk/?p=215</guid>
		<description><![CDATA[I&#8217;ve been implementing the WordPress e-Commerce plug-in on another site, it&#8217;s not a bad freebie but if you&#8217;re selling anything more than a handful of items then you&#8217;ll need to let your users search your products.  To add this functionality, along with a few other features, you need to purchase the $50 Gold Cart add-in. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been implementing the WordPress e-Commerce plug-in on another site, it&#8217;s not a bad freebie but if you&#8217;re selling anything more than a handful of items then you&#8217;ll need to let your users search your products.  To add this functionality, along with a few other features, you need to purchase the $50 Gold Cart add-in.</p>
<p>I duly purchased and installed the update only to find that the &#8220;search&#8221; only looked at product titles, meaning that all the description text, additional description text and meta tags were being ignored.   Looking around it appears I wasn&#8217;t the only person who needed this functionality and I was able to get hold of some code to change in gold_shopping_cart.php.  I still didn&#8217;t get the results I was expecting so after checking out the Database table structure I went from</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p215code7'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2157"><td class="code" id="p215code7"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$category_list</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>get_col<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT `id` FROM `&quot;</span><span style="color: #339933;">.</span>WPSC_TABLE_PRODUCT_CATEGORIES<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;` WHERE `name` LIKE '&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$search_string_title</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>to</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p215code8'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2158"><td class="code" id="p215code8"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$category_list</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>get_col<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT id FROM `&quot;</span><span style="color: #339933;">.</span>WPSC_TABLE_PRODUCT_LIST<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;` WHERE name LIKE '&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$search_string_title</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' OR description LIKE '&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$search_string_title</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' OR additional_description LIKE '&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$search_string_title</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Notice the change in the table being searched.  The original code I found still looked in the WPSC_TABLE_PRODUCT_CATEGORIES table but this does not contain the additional_description field, an oversight on the original modders part.</p>
<p>Yet I still wasn&#8217;t getting the expected results.  A quick count of the $category_list array showed I was getting results but they were getting filtered out further on in the function by this little check:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p215code9'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2159"><td class="code" id="p215code9"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$category_list</span> <span style="color: #339933;">!=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$category_assoc_list</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_col</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT DISTINCT `product_id` FROM `&quot;</span><span style="color: #339933;">.</span>WPSC_TABLE_ITEM_CATEGORY_ASSOC<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;` WHERE `category_id` IN ('&quot;</span><span style="color: #339933;">.</span><a href="http://www.php.net/implode"><span style="color: #990000;">implode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;', '&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$category_list</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: #339933;">;</span>
				<span style="color: #000088;">$category_sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;OR `&quot;</span><span style="color: #339933;">.</span>WPSC_TABLE_PRODUCT_LIST<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;`.`id` IN ('&quot;</span><span style="color: #339933;">.</span><a href="http://www.php.net/implode"><span style="color: #990000;">implode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;', '&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$category_assoc_list</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></pre></td></tr></table></div>

<p>Remember that I&#8217;m now searching products directly and the above code is looking to match the products unique ID against a category ID, clearly this will fail on 99% of searches.  A quick change to the search criteria is all that was needed to return valid results:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p215code10'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p21510"><td class="code" id="p215code10"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$category_list</span> <span style="color: #339933;">!=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$category_assoc_list</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_col</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT DISTINCT `product_id` FROM `&quot;</span><span style="color: #339933;">.</span>WPSC_TABLE_ITEM_CATEGORY_ASSOC<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;` WHERE `product_id` IN ('&quot;</span><span style="color: #339933;">.</span><a href="http://www.php.net/implode"><span style="color: #990000;">implode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;', '&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$category_list</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: #339933;">;</span>
				<span style="color: #000088;">$category_sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;OR `&quot;</span><span style="color: #339933;">.</span>WPSC_TABLE_PRODUCT_LIST<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;`.`id` IN ('&quot;</span><span style="color: #339933;">.</span><a href="http://www.php.net/implode"><span style="color: #990000;">implode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;', '&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$category_assoc_list</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></pre></td></tr></table></div>

<p>With that completed I looked at adding a separate search interface and came across WP e-Commerce Search Widget, a handy bit of code but unfortunately it doesn&#8217;t appear to be compatible with the latest version of WP e-Commerce so I had to quickly update</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p215code11'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p21511"><td class="code" id="p215code11"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>form method<span style="color: #339933;">=</span><span style="color: #0000ff;">'GET'</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">'product_search'</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;productsearchform&quot;</span> action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php bloginfo('home');  ?&gt;/&quot;</span><span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>to</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p215code12'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p21512"><td class="code" id="p215code12"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>form method<span style="color: #339933;">=</span><span style="color: #0000ff;">'GET'</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">'product_search'</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;productsearchform&quot;</span> action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php bloginfo('home');  ?&gt;/products-page/&quot;</span><span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>WP e-Commerce is a lot of work, especially considering you have to pay $50 just to get basic functionality and then hack in the desired features.  Lets hope the checkout refresh bug doesn&#8217;t hit again&#8230;.</p>
<!-- AdSense Now! V1.90 -->
<!-- Post[count: 2] -->
<div class="adsense adsense-leadout" style="text-align:center;margin: 12px;"><script type="text/javascript"><!--
google_ad_client = "pub-5905155743931046";
/* 468x15, created 10/04/10 */
google_ad_slot = "2193001556";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.gothi.co.uk/2010/02/fixing-wp-e-commerce/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

