2016-06-29 77 views
0

我需要在產品頁面中顯示產品尺寸。 這是我的代碼,但沒有執行。 我加入目錄/控制器/產品/ product.php在opencart產品頁面中顯示尺寸

<?php 
$this->data['length'] = number_format($product_info['length'],2) . ' cm'; 
    $this->data['width'] = number_format($product_info['width'],2) . ' cm'; 
    $this->data['height'] = number_format($product_info['height'],2) . ' cm'; 

,並在同一文件

$this->data['text_dimensions'] = $this->language->get('text_dimensions'); 
     $this->data['text_by'] = $this->language->get('text_by'); 

和在目錄/視圖/主題/默認/模板/產品/ product.tpl

<?php echo $length; ?><?php echo $text_by; ?><?php echo width; ?><?php echo $text_by; ?><?php echo $height; ?><?php echo $text_by; ?> 

,並在我的目錄/語言/英文/產品/ product.php

$_['text_dimensions'] = 'Dimensions:'; 
     $_['text_by'] = 'x'; 

嘗試此代碼維度未在opencart中顯示。

+0

版本是你的工作內容Opencart的? –

+0

你通過控制器傳遞了語言變量嗎? 如果是這樣,他們是否出現在該地方的頁面上? –

+0

opencart 2.1.0.2版本 – narendra

回答

0

這裏是controller file你正在使用的版本(OC 2.1.0.2)

$這個 - >數據是沒有更多的用於傳遞變量在Opencart的2.X的視圖。代替渲染方法接受第二個參數,這是一個變量數組傳遞到一般$data變量用於視圖

​​

在將數據傳遞給呈現方法之前,您需要將變量插入到數組中。

另一個問題,我發現你是硬編碼(釐米),這可能也可以從系統中檢索。

還有一件事:不要忘記通過控制器傳遞您創建的語言變量以及其他變量。

+0

我試過目錄/控制器/產品/產品。PHP文件$ data ['length'] = $ product_info ['length']; $ data ['width'] = $ product_info ['width']; $ data ['height'] = $ product_info ['height'];在查看頁面我寫<?php echo $ length; ?>它顯示了未定義的變量長度 – narendra

+0

你可以指定在哪裏插入你的代碼在這裏https://github.com/opencart/opencart/blob/2.1.0.2/upload/catalog/controller/product/product.php? –

0

控制器代碼:

$data['weight'] = $this->weight->format($product_info['weight'], $product_info['weight_class_id']); 
$data['length'] = $this->length->format($product_info['length'], $product_info['length_class_id']); 
$data['width'] = $this->length->format($product_info['width'], $product_info['length_class_id']); 
$data['height'] = $this->length->format($product_info['height'], $product_info['length_class_id']); 

查看文件(product.tpl)代碼:

<li><?php echo $weight; ?></li> 
<li><?php echo $length; ?></li> 
<li><?php echo $width; ?></li> 
<li><?php echo $height; ?></li> 

它在Opencart的版本2.1.x的工作對我來說

相關問題