我需要在最近添加的产品上贴上“新”标签。我已在 上完成此操作extension/module/latest.tpl
,但我还希望此标签也可以在其他页面上使用,例如product/product.tpl
,product/category
等等...
我如何在不购买任何扩展程序的情况下做到这一点?
- 开放购物车 2.3
- 模板:默认
更新
/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)
);
}
这就是我在 product/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']) { ?>