多嚿魚教室

Opencart優化技巧

本文最後更新日期:2012年3月12日

無叉用點算?
 
假設在個別商品的頁面,數目欄打「6」,再按一下,購物車內就有6件該商品。然後在數目欄打「4」,再按一下,購物車的該商品數目不是改成4,而是累加成10。

Finding Solution

要令購物車不要累計同一商品,就要修改[system\library\cart.php]的程式碼。
因為有其他網誌教授了這程式修改碼的方法,所以我不多詳述。今次我直接提供vQmod XML Script,適用於Opencart v1.5.1.3。


<p>
&#60;!--<br />
Make sure that you have properly installed Opencart vQmod.<br />
Copy this page of script.<br />
Save as a .xml file of utf-8 encoding without BOM into the directory [vqmod/xml].<br />
Name the file as you like.<br />
--&gt;</p>
<pre contenteditable="true">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;modification&gt;
 &lt;id&gt;Prevent accumulation of number of add to cart product&lt;/id&gt;
 &lt;version&gt;1.1.0&lt;/version&gt;
 &lt;author&gt;Flexidigi Solution Ltd.&lt;/author&gt;
 &lt;file name=&quot;system/library/cart.php&quot;&gt;
  &lt;operation error=&quot;skip&quot;&gt;
   &lt;search position=&quot;replace&quot; index=&#34;1&#34;&gt;&lt;![CDATA[if ((int)$qty &amp;&amp; ((int)$qty &gt; 0)) {]]&gt;&lt;/search&gt;
 &#160; &lt;add&gt;&lt;![CDATA[
   $this-&gt;session-&gt;data[&#39;cart&#39;][$key] = (int)$qty;
   if (false) {]]&gt;&lt;/add&gt;
  &lt;/operation&gt;
 &lt;/file&gt;
&lt;/modification&gt;
</pre>

有些商品我沒有加入圖片。怎樣不顯示它們在Special、Featured和Latest這三個模版內?
沒有圖片的商品顯示出來實在格格不入!
Finding Solution
以下方法適用於Opencart v1.5.1.3
修改步驟:
  1. 開啟[catalog/view/theme/default/template/module]。
  2. 編輯三個檔案:[special.tpl]、[featured.tpl]、[special.tpl]。
  3. 搜尋以下程式碼:
    $this->data['products'][] = array(
  4. 在前一行加入以下程式碼:
    if ($image) 
這樣沒有圖片的商品就不會顯示在Special、Featured和Latest這三個模版內。
<p>
&#60;!--<br />
Make sure that you have properly installed Opencart vQmod.<br />
Copy this page of script.<br />
Save as a .xml file of utf-8 encoding without BOM into the directory [vqmod/xml].<br />
Name the file as you like.<br />
--&gt;</p>
<pre contenteditable="true">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;modification&gt;
&nbsp;&lt;id&gt;Hide products without photos&lt;/id&gt;
&nbsp;&lt;version&gt;1.0.0&lt;/version&gt;
&nbsp;&lt;author&gt;Flexidigi Solution Ltd&lt;/author&gt;
&nbsp;&lt;file name=&quot;catalog/controller/module/latest.php&quot;&gt;
&nbsp;&nbsp;&lt;operation error=&quot;skip&quot;&gt;
&#32;&#160;&nbsp;&lt;search position=&quot;before&quot;&gt;&lt;![CDATA[
&#32;&#160;&nbsp;$this-&gt;data[&#39;products&#39;][] = array(
&#32;&#160;&nbsp;]]&gt;&lt;/search&gt;
&#32;&#160;&nbsp;&lt;add&gt;&lt;![CDATA[if ($image) ]]&gt;&lt;/add&gt;
&nbsp;&nbsp;&lt;/operation&gt;
&nbsp;&lt;/file&gt;
&nbsp;&lt;file name=&quot;catalog/controller/module/featured.php&quot;&gt;
&nbsp;&nbsp;&lt;operation error=&quot;skip&quot;&gt;
&#32;&#160;&nbsp;&lt;search position=&quot;before&quot;&gt;&lt;![CDATA[
&#32;&#160;&nbsp;$this-&gt;data[&#39;products&#39;][] = array(
&#32;&#160;&nbsp;]]&gt;&lt;/search&gt;
&#32;&#160;&nbsp;&lt;add&gt;&lt;![CDATA[if ($image) ]]&gt;&lt;/add&gt;
&nbsp;&nbsp;&lt;/operation&gt;
&nbsp;&lt;/file&gt;
&nbsp;&lt;file name=&quot;catalog/controller/module/special.php&quot;&gt;
&nbsp;&nbsp;&lt;operation error=&quot;skip&quot;&gt;
&#32;&#160;&nbsp;&lt;search position=&quot;before&quot;&gt;&lt;![CDATA[
&#32;&#160;&nbsp;$this-&gt;data[&#39;products&#39;][] = array(
&#32;&#160;&nbsp;]]&gt;&lt;/search&gt;
&#32;&#160;&nbsp;&lt;add&gt;&lt;![CDATA[if ($image) ]]&gt;&lt;/add&gt;
&nbsp;&nbsp;&lt;/operation&gt;
&nbsp;&lt;/file&gt;
&lt;/modification&gt;
</pre>