多嚿魚教室

Opencart優化技巧

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;會保留其套用文本中的空格和換行符號。