我需要爲最近添加的產品標註「新」標籤。我有這個做了extension/module/latest.tpl
,但希望我也有這個標籤上的另一個頁面太工作,像product/product.tpl
,product/category
等等...將標籤添加到OpenCart中最近添加的產品中
我怎麼能做到這一點無需購買任何擴展?
- Opencart的2.3
- 模板:默認
UPDATE
/controller/product/category.php
/*start added part*/
if(strtotime($result['date_added']) > (time() - (60*60*24*10))){
//(note that 10 means ten days, to consider a product as a new product, you can change it based on your need.)
$is_new = true;
} else {
$is_new = false;
}
/*end added part*/
$data['products'][] = array(
'is_new' => $is_new, //added code
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get($this->config->get('config_theme') . '_product_description_length')) . '..',
'price' => $price,
'special' => $special,
'tax' => $tax,
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
'rating' => $result['rating'],
'href' => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url)
);
}
這是我在做產品/category.tpl
<?php foreach ($products as $product) { ?>
<div class="product-layout product-list col-xs-12">
<div class="product-thumb">
<div class="image"><a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" class="img-responsive" /></a></div>
<div>
<div class="caption">
<h4><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a></h4>
<?php if($product['is_new']){ ?><span>NEW</span><?php } ?>
<p><?php echo $product['description']; ?></p>
<?php if ($product['price']) { ?>
打招呼@Mojtaba Sabeti,感謝您的回覆 我嘗試了第一個解決方案(不使用vqmod),但沒有得到ny的結果,它只是不顯示任何東西(我使用'clear'opencart2.3沒有安裝任何其他擴展)...我把代碼放在我的問題更新(抱歉,如果我做錯了,我是新的stackoverflow: - )),也許我做錯了什麼? 請幫助.... –
我也嘗試vqmod,但仍然沒有結果...我也嘗試使用最新的模塊,它顯示latly增加產品... –
你好,我上面寫的那一天,我測試了我的工作,它工作正常,請耐心等待,我會盡快重新檢查。 – DigitCart