我需要为最近添加的产品标注“新”标签。我有这个做了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