Opencart 1.5.1.x: страница товара - на вкладку характеристик добавлен вес и размеры

Добавлен показ веса и размеров на вкладке характеристик товара (Opencart 1.5)

По умолчанию они почему-то не выводятся в характеристиках товара и увидеть их можно только на странице сравнения.

Вывести подготовленные данные (вес и размеры товара) можно в другом месте шаблона (например вверху, рядом с моделью и бонусными баллами) -- думаю, не составит труда переставить вывод в более удобное место самостоятельно.

Изменения для обеих версий одинаковые. Просто на вкладке для 1.5.1.3 более полная версия: включает в себя изменение системных библиотек для более аккуратного вывода нулевых значений веса и размеров. В версии 1.5.1.2 я это изменение вносил давно и забыл про него написать.

1.5.x - 1.5.1.2

commit a26a849f1ac31fd2ab24f491860748b64f588ef8
Author: Ruslan Brest <rb@labtodo.com>
Date:   Thu Nov 17 18:20:47 2011 +0200
    [+] catalog: информация о товаре - на вкладку характеристик добавлен вес и размеры
diff --git a/public_html/catalog/controller/product/product.php b/public_html/catalog/controller/product/product.php
index 25ba580..8062941 100644
--- a/public_html/catalog/controller/product/product.php
+++ b/public_html/catalog/controller/product/product.php
@@ -3,6 +3,7 @@ class ControllerProductProduct extends Controller {
    private $error = array();

    public function index() {
+       $this->language->load('product/compare');
        $this->language->load('product/product');

        $this->data['breadcrumbs'] = array();
@@ -154,6 +155,9 @@ class ControllerProductProduct extends Controller {
            $this->data['text_share'] = $this->language->get('text_share');
            $this->data['text_wait'] = $this->language->get('text_wait');
            $this->data['text_tags'] = $this->language->get('text_tags');
+           $this->data['text_weight_and_dim'] = $this->language->get('text_weight_and_dim');
+           $this->data['text_weight'] = $this->language->get('text_weight');
+           $this->data['text_dimension'] = $this->language->get('text_dimension');

            $this->data['entry_name'] = $this->language->get('entry_name');
            $this->data['entry_review'] = $this->language->get('entry_review');
@@ -178,10 +182,14 @@ class ControllerProductProduct extends Controller {
            $this->data['product_id'] = $this->request->get['product_id'];
            $this->data['manufacturer'] = $product_info['manufacturer'];
            $this->data['manufacturers'] = $this->url->link('product/manufacturer/product', 'manufacturer_id=' . $product_info['manufacturer_id']);
-           $this->data['model'] = $product_info['model'];
+           $this->data['model']  = $product_info['model'];
            $this->data['reward'] = $product_info['reward'];
            $this->data['points'] = $product_info['points'];
-
+           $this->data['weight'] = $this->weight->format($product_info['weight'], $product_info['weight_class_id']);
+           $this->data['length'] = $this->length->format($product_info['length'], $product_info['length_class_id']);
+           $this->data['width']  = $this->length->format($product_info['width'], $product_info['length_class_id']);
+           $this->data['height'] = $this->length->format($product_info['height'], $product_info['length_class_id']);
+           
            if ($product_info['quantity'] <= 0) {
                $this->data['stock'] = $product_info['stock_status'];
            } elseif ($this->config->get('config_stock_display')) {
@@ -309,7 +317,7 @@ class ControllerProductProduct extends Controller {
            $this->data['rating'] = (int)$product_info['rating'];
            $this->data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');
            $this->data['attribute_groups'] = $this->model_catalog_product->getProductAttributes($this->request->get['product_id']);
-
+           
            $this->data['products'] = array();

            $results = $this->model_catalog_product->getProductRelated($this->request->get['product_id']);
diff --git a/public_html/catalog/language/english/product/product.php b/public_html/catalog/language/english/product/product.php
index 16f42c5..1771dc0 100644
--- a/public_html/catalog/language/english/product/product.php
+++ b/public_html/catalog/language/english/product/product.php
@@ -25,6 +25,7 @@ $_['text_upload']       = 'Your file was successfully uploaded!';
 $_['text_wait']         = 'Please Wait!';
 $_['text_tags']         = 'Tags:';
 $_['text_error']        = 'Product not found!';
+$_['text_weight_and_dim'] = 'Weight and dimension';

 // Entry
 $_['entry_name']        = 'Your Name:';
diff --git a/public_html/catalog/language/russian/product/product.php b/public_html/catalog/language/russian/product/product.php
index 7542b96..fae7e99 100644
--- a/public_html/catalog/language/russian/product/product.php
+++ b/public_html/catalog/language/russian/product/product.php
@@ -25,6 +25,8 @@ $_['text_upload']       = 'Ваш файл был успешно загруже
 $_['text_wait']         = 'Пожалуйста, подождите!';
 $_['text_tags']         = 'Метки:';
 $_['text_error']        = 'Товар не найден!';
+$_['text_weight']       = 'Вес';
+$_['text_weight_and_dim'] = 'Вес и размеры';
 // Entry
 $_['entry_name']        = 'Ваше имя:';
 $_['entry_review']      = 'Ваш отзыв:';
diff --git a/public_html/catalog/view/theme/default/template/product/product.tpl b/public_html/catalog/view/theme/default/template/product/product.tpl
index aaeab64..8e8f8e8 100644
--- a/public_html/catalog/view/theme/default/template/product/product.tpl
+++ b/public_html/catalog/view/theme/default/template/product/product.tpl
@@ -221,6 +221,24 @@
   <?php if ($attribute_groups) { ?>
   <div id="tab-attribute" class="tab-content">
     <table class="attribute">
+
+      <thead>
+        <tr>
+          <td colspan="2"><?php echo $text_weight_and_dim; ?></td>
+        </tr>
+      </thead>
+      <tbody>
+      <tr>
+        <td><?php echo $text_weight; ?></td>
+        <td><?php echo $weight; ?></td>
+      </tr>
+      <tr>
+        <td><?php echo $text_dimension; ?></td>
+        <td><?php echo $length; if(!empty($length)) echo " x "; echo $width; if(!empty($width)) echo " x "; echo $height; ?></td>
+      </tr>
+      </tbody>
+
+
       <?php foreach ($attribute_groups as $attribute_group) { ?>
       <thead>
         <tr>

1.5.1.3

commit 2dec5cba9d01d1fbef34e34bfaa5558bb7676c3e
Author: Ruslan Brest <rb@labtodo.com>
Date:   Wed Feb 15 10:17:52 2012 +0200
    [+] catalog: информация о товаре - на вкладку характеристик добавлен вес и размеры
diff --git a/upload/admin/language/english/english.php b/upload/admin/language/english/english.php
index 891da64..7f05d1c 100644
--- a/upload/admin/language/english/english.php
+++ b/upload/admin/language/english/english.php
@@ -7,6 +7,8 @@ $_['date_format_long']        = 'l dS F Y';
 $_['time_format']             = 'h:i:s A';
 $_['decimal_point']           = '.';
 $_['thousand_point']          = ',';
+$_['length_decimals']       = 0;
+$_['weight_decimals']       = 0;

 // Text
 $_['text_yes']                = 'Yes';
diff --git a/upload/admin/language/russian/russian.php b/upload/admin/language/russian/russian.php
index 2860121..f3fcd1a 100644
--- a/upload/admin/language/russian/russian.php
+++ b/upload/admin/language/russian/russian.php
@@ -7,6 +7,8 @@ $_['date_format_long']        = 'l, d F Y';
 $_['time_format']             = 'H:i:s';
 $_['decimal_point']           = '.';
 $_['thousand_point']          = ',';
+$_['length_decimals']       = 0;
+$_['weight_decimals']       = 0;

 // Text
 $_['text_yes']                = 'Да';
diff --git a/upload/catalog/controller/product/product.php b/upload/catalog/controller/product/product.php
index eadd2f3..c51d220 100644
--- a/upload/catalog/controller/product/product.php
+++ b/upload/catalog/controller/product/product.php
@@ -3,6 +3,7 @@ class ControllerProductProduct extends Controller {
    private $error = array(); 

    public function index() { 
+       $this->language->load('product/compare');
        $this->language->load('product/product');

        $this->data['breadcrumbs'] = array();
@@ -154,6 +155,9 @@ class ControllerProductProduct extends Controller {
            $this->data['text_share'] = $this->language->get('text_share');
            $this->data['text_wait'] = $this->language->get('text_wait');
            $this->data['text_tags'] = $this->language->get('text_tags');
+           $this->data['text_weight_and_dim'] = $this->language->get('text_weight_and_dim');
+           $this->data['text_weight'] = $this->language->get('text_weight');
+           $this->data['text_dimension'] = $this->language->get('text_dimension');

            $this->data['entry_name'] = $this->language->get('entry_name');
            $this->data['entry_review'] = $this->language->get('entry_review');
@@ -181,6 +185,11 @@ class ControllerProductProduct extends Controller {
            $this->data['model'] = $product_info['model'];
            $this->data['reward'] = $product_info['reward'];
            $this->data['points'] = $product_info['points'];
+
+           $this->data['weight'] = $this->weight->format($product_info['weight'], $product_info['weight_class_id']);
+           $this->data['length'] = $this->length->format($product_info['length'], $product_info['length_class_id']);
+           $this->data['width']  = $this->length->format($product_info['width'], $product_info['length_class_id']);
+           $this->data['height'] = $this->length->format($product_info['height'], $product_info['length_class_id']);

            if ($product_info['quantity'] <= 0) {
                $this->data['stock'] = $product_info['stock_status'];
diff --git a/upload/catalog/language/english/english.php b/upload/catalog/language/english/english.php
index cdf17cf..74b1bd6 100644
--- a/upload/catalog/language/english/english.php
+++ b/upload/catalog/language/english/english.php
@@ -7,6 +7,8 @@ $_['date_format_long']      = 'l dS F Y';
 $_['time_format']           = 'h:i:s A';
 $_['decimal_point']         = '.';
 $_['thousand_point']        = ',';
+$_['length_decimals']       = 0;
+$_['weight_decimals']       = 0;

 // Text
 $_['text_home']             = 'Home';
diff --git a/upload/catalog/language/english/product/product.php b/upload/catalog/language/english/product/product.php
index 16f42c5..762f0b5 100644
--- a/upload/catalog/language/english/product/product.php
+++ b/upload/catalog/language/english/product/product.php
@@ -25,6 +25,8 @@ $_['text_upload']       = 'Your file was successfully uploaded!';
 $_['text_wait']         = 'Please Wait!';
 $_['text_tags']         = 'Tags:';
 $_['text_error']        = 'Product not found!';
+$_['text_weight']       = 'Weight';
+$_['text_weight_and_dim'] = 'Weight and dimension';

 // Entry
 $_['entry_name']        = 'Your Name:';
diff --git a/upload/catalog/language/russian/product/product.php b/upload/catalog/language/russian/product/product.php
index 7542b96..e44ea79 100644
--- a/upload/catalog/language/russian/product/product.php
+++ b/upload/catalog/language/russian/product/product.php
@@ -25,6 +25,9 @@ $_['text_upload']       = 'Ваш файл был успешно загруже
 $_['text_wait']         = 'Пожалуйста, подождите!';
 $_['text_tags']         = 'Метки:';
 $_['text_error']        = 'Товар не найден!';
+$_['text_weight']       = 'Вес';
+$_['text_weight_and_dim'] = 'Вес и размеры';
+
 // Entry
 $_['entry_name']        = 'Ваше имя:';
 $_['entry_review']      = 'Ваш отзыв:';
diff --git a/upload/catalog/language/russian/russian.php b/upload/catalog/language/russian/russian.php
index 48829a5..f69f200 100644
--- a/upload/catalog/language/russian/russian.php
+++ b/upload/catalog/language/russian/russian.php
@@ -7,6 +7,8 @@ $_['date_format_long']      = 'l d F Y';
 $_['time_format']           = 'H:i:s';
 $_['decimal_point']         = '.';
 $_['thousand_point']        = '';
+$_['length_decimals']       = 0;
+$_['weight_decimals']       = 0;

 // Text
 $_['text_home']             = 'Главная';
diff --git a/upload/catalog/view/theme/default/template/product/product.tpl b/upload/catalog/view/theme/default/template/product/product.tpl
index 81d6334..b7a3d15 100644
--- a/upload/catalog/view/theme/default/template/product/product.tpl
+++ b/upload/catalog/view/theme/default/template/product/product.tpl
@@ -27,6 +27,8 @@
         <span><?php echo $text_manufacturer; ?></span> <a href="<?php echo $manufacturers; ?>"><?php echo $manufacturer; ?></a>
         <?php } ?>
         <span><?php echo $text_model; ?></span> <?php echo $model; ?>
+       <?php echo $product_info['sku']; ?>
+
         <span><?php echo $text_reward; ?></span> <?php echo $reward; ?>
         <span><?php echo $text_stock; ?></span> <?php echo $stock; ?></div>
       <?php if ($price) { ?>
@@ -227,7 +229,7 @@
     </div>
   </div>
   <div id="tabs" class="htabs"><a href="#tab-description"><?php echo $tab_description; ?></a>
-    <?php if ($attribute_groups) { ?>
+    <?php if ($attribute_groups || strcmp('', $weight . $length . $width . $height)) { ?>
     <a href="#tab-attribute"><?php echo $tab_attribute; ?></a>
     <?php } ?>
     <?php if ($review_status) { ?>
@@ -238,14 +240,26 @@
     <?php } ?>
   </div>
   <div id="tab-description" class="tab-content"><?php echo $description; ?></div>
-  <?php if ($attribute_groups) { ?>
+  <?php if ($attribute_groups || strcmp('', $weight . $length . $width . $height)) { ?>
   <div id="tab-attribute" class="tab-content">
+    <table class="attribute">

-        <?php echo $weight; ?>
-        <?php echo $length; ?> x <?php echo $width; ?> x <?php echo $height; ?>
-
+      <thead>
+        <tr>
+          <td colspan="2"><?php echo $text_weight_and_dim; ?></td>
+        </tr>
+      </thead>
+      <tbody>
+      <tr>
+        <td><?php echo $text_weight; ?></td>
+        <td><?php echo $weight; ?></td>
+      </tr>
+      <tr>
+        <td><?php echo $text_dimension; ?></td>
+        <td><?php echo $length; if(!empty($length)) echo " x "; echo $width; if(!empty($width)) echo " x "; echo $height; ?></td>
+      </tr>
+      </tbody>

-    <table class="attribute">
       <?php foreach ($attribute_groups as $attribute_group) { ?>
       <thead>
         <tr>
diff --git a/upload/system/library/length.php b/upload/system/library/length.php
index 70f1b0f..f4d120a 100644
--- a/upload/system/library/length.php
+++ b/upload/system/library/length.php
@@ -5,6 +5,7 @@ final class Length {
    public function __construct($registry) {
        $this->db = $registry->get('db');
        $this->config = $registry->get('config');
+       $this->language = $registry->get('language');

        $length_class_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "length_class mc LEFT JOIN " . DB_PREFIX . "length_class_description mcd ON (mc.length_class_id = mcd.length_class_id) WHERE mcd.language_id = '" . (int)$this->config->get('config_language_id') . "'");

@@ -39,10 +40,11 @@ final class Length {
    }

    public function format($value, $length_class_id, $decimal_point = '.', $thousand_point = ',') {
+       if( 0 == $value ) return "";
        if (isset($this->lengths[$length_class_id])) {
-           return number_format($value, 2, $decimal_point, $thousand_point) . $this->lengths[$length_class_id]['unit'];
+           return number_format($value, (int)$this->language->get('length_decimals'), $decimal_point, $thousand_point) . $this->lengths[$length_class_id]['unit'];
        } else {
-           return number_format($value, 2, $decimal_point, $thousand_point);
+           return number_format($value, (int)$this->language->get('length_decimals'), $decimal_point, $thousand_point);
        }
    }
 }
diff --git a/upload/system/library/weight.php b/upload/system/library/weight.php
index 584df3c..6b8c59f 100644
--- a/upload/system/library/weight.php
+++ b/upload/system/library/weight.php
@@ -5,6 +5,7 @@ final class Weight {
    public function __construct($registry) {
        $this->db = $registry->get('db');
        $this->config = $registry->get('config');
+       $this->language = $registry->get('language');

        $weight_class_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "weight_class wc LEFT JOIN " . DB_PREFIX . "weight_class_description wcd ON (wc.weight_class_id = wcd.weight_class_id) WHERE wcd.language_id = '" . (int)$this->config->get('config_language_id') . "'");

@@ -34,10 +35,11 @@ final class Weight {
    }

    public function format($value, $weight_class_id, $decimal_point = '.', $thousand_point = ',') {
+       if( 0 == $value ) return "";
        if (isset($this->weights[$weight_class_id])) {
-           return number_format($value, 2, $decimal_point, $thousand_point) . $this->weights[$weight_class_id]['unit'];
+           return number_format($value, (int)$this->language->get('weight_decimals'), $decimal_point, $thousand_point) . $this->weights[$weight_class_id]['unit'];
        } else {
-           return number_format($value, 2, $decimal_point, $thousand_point);
+           return number_format($value, (int)$this->language->get('weight_decimals'), $decimal_point, $thousand_point);
        }
    }
Tags: