多嚿魚教室

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>

Opencart的註冊表格是否囊括世上所有國家和特殊政區?如何讓用戶揀選其他地區?
Opencart有兩個註冊表格--Customer和Affiliate,其中地址共有239個國家和特殊政區可供選擇,真是他媽的詳盡!連南極洲都有,方便你將網店生意拓展到企鵝族群。
Country:

不過,Opencart提供的“Country”選擇欄已經過時!例如選擇欄竟然有已經解體的南斯拉夫(Yugoslavia),卻沒有近年新成立的國家,包括塞爾維亞共和國(Serbia)、黑山共和國(Montenegro)、南蘇丹(Republic of South Sudan)。
世界局勢波譎雲詭,政區隨時變改。你可以索性在國家選擇欄加一個“other area”讓客戶選擇,那就不用花心思去更新“Country”選擇欄。
Finding Solution
修改步驟:
  1. 登入Opencart後台,到“System”→“Localisation”→“Zones”。
  2. 將四個原屬於南斯拉夫(Yugoslavia)的地區刪除。
  3. 到“System”→“Localisation”→“Country”,編輯“Yugoslavia”。
  4. 將“Country Name”的值改為“other area”。
  5. “ISO code (2)”和“ISO code (3)”不用修改,因為這兩個的國家代碼不會再用於其他國家。“Postcode required”維持“no”。
  6. 最後按“Save”。
更新後的“Country”選擇欄有“other area”供選擇。揀選“other area”後,“Region/State”選擇欄只有“none”可選。
Country:
你可以自行添加國家/地區到選擇欄。登入Opencart後台,到“System”→“Localisation”→“Country”,再按“Insert”輸入資料。
Country NameISO code (2)ISO code (3)
Republic of South SudanSSSSD
MontenegroMEMNE
Republic of SerbiaRSSRB
以上方法適用於Opencart v1.5.1.3
無叉用的人有福了!

更新了國家資料後,就要更新地區資料。

我在Opencart後台輸入Product的attribute時有換行,但店面顯示的卻沒有換行,怎麼辦?
在Opencart後台輸入Product的attribute時有換行。
店面顯示的Product attribute沒有換行。
Finding Solution
Opencart後台是用<textarea>HTML標籤來裝載你輸入的Product attribute,而HTML會無視textarea的換行符\n,所以店面顯示的Product attribute沒有換行。
解決辦法:將\n轉為HTML換行標籤<br />;或用不會忽略\n的HTML標籤來裝載Product attribute。
我們熱心幫助無叉用的人
以下方法適用於Opencart v1.5.1.3
方法1——PHP修正:
  1. 編輯[catalog/model/catalog/product.php]
  2. 搜尋以下程式碼:
      foreach ($product_attribute_query->rows as $product_attribute) {
        $product_attribute_data[] = array(
          'attribute_id' => $product_attribute['attribute_id'],
          'name'         => $product_attribute['name'],
          'text'         => $product_attribute['text']       
        );
      }
  3. 將$product_attribute['text']更改為nl2br($product_attribute['text'])。
nl2br()是PHP函數,會在\n之前插入HTML換行標籤<br /> 。
方法2——HTML修正:
  1. 編輯[catalog/view/theme/default/template/product/product.tpl]
  2. 搜尋以下程式碼:
    <?php foreach ($attribute_group['attribute'] as $attribute) { ?>
    <tr>
      <td><?php echo $attribute['name']; ?></td>
      <td><?php echo $attribute['text']; ?></td>
    </tr>
    <?php } ?>
  3. 將<td><?php echo $attribute['text']; ?></td>修改為<td><pre><?php echo $attribute['text']; ?></pre></td>。
<pre>會保留文本中的空格和換行符號。
方法3——CSS修正:
  1. 編輯[catalog/view/theme/default/stylesheet/stylesheet.css]
  2. 到最後一行加入以下程式碼:
    .attribute tbody tr td { white-space: pre-wrap; }
    
white-space: pre-wrap;會保留其套用文本中的空格和換行符號。