在 OpenCart 中为最近添加的产品添加标签
Add label to recently added products in OpenCart
我需要在最近添加的产品上添加标签 "new"。我在 extension/module/latest.tpl
上完成了此操作,但我也希望此标签也能在其他页面上使用,例如 product/product.tpl
、product/category
等等...
如何在不购买任何扩展的情况下执行此操作?
- OpenCart 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']) { ?>
您可以将产品的date_added
与当前时间进行比较,您需要为类别修改两个文件:
第一个文件:catalog/controller/product/category.php
查找:
$data['products'][] = array(
在前面加上:
if(strtotime($result['date_added']) > (time() - (60*60*24*10) )){
$is_new = true;
} else {
$is_new = false;
}
(注意10
表示十天,将产品视为新产品,您可以根据需要更改。)
后面加上:
'is_new' => $is_new,
现在这一段一定是这样的:
if(strtotime($result['date_added']) > (time() - (60*60*24*10) )){
$is_new = true;
} else {
$is_new = false;
}
$data['products'][] = array(
'is_new' => $is_new,
'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),
);
第二个文件:catalog/view/theme/default/template/product/category.tpl
在 foreach
产品循环中添加此代码,例如之前:<p><?php echo $product['description']; ?></p>
:
<?php if($product['is_new']){ ?><span class="new-product">NEW</span><?php } ?>
我为 vqmod 创建了一个 xml 脚本:
<?xml version="1.0" encoding="UTF-8"?>
<modification>
<id>Products New Label</id>
<version>2.x</version>
<vqmver required="true">2.6.0</vqmver>
<author>sabeti05@gmail.com</author>
<file name="catalog/controller/product/category.php">
<operation error="skip">
<search position="replace"><![CDATA[$data['products'][] = array(]]></search>
<add><![CDATA[
if(strtotime($result['date_added']) > (time() - (60*60*24*10) )){
$is_new = true;
} else {
$is_new = false;
}
$data['products'][] = array(
'is_new' => $is_new,
]]></add>
</operation>
</file>
<file name="catalog/view/theme/*/template/product/category.tpl">
<operation error="skip">
<search position="before"><![CDATA[<p><?php echo $product['description']; ?></p>]]></search>
<add><![CDATA[
<?php if($product['is_new']){ ?><span class="new-product">NEW</span><?php } ?>
]]></add>
</operation>
</file>
</modification>
我需要在最近添加的产品上添加标签 "new"。我在 extension/module/latest.tpl
上完成了此操作,但我也希望此标签也能在其他页面上使用,例如 product/product.tpl
、product/category
等等...
如何在不购买任何扩展的情况下执行此操作?
- OpenCart 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']) { ?>
您可以将产品的date_added
与当前时间进行比较,您需要为类别修改两个文件:
第一个文件:catalog/controller/product/category.php
查找:
$data['products'][] = array(
在前面加上:
if(strtotime($result['date_added']) > (time() - (60*60*24*10) )){
$is_new = true;
} else {
$is_new = false;
}
(注意10
表示十天,将产品视为新产品,您可以根据需要更改。)
后面加上:
'is_new' => $is_new,
现在这一段一定是这样的:
if(strtotime($result['date_added']) > (time() - (60*60*24*10) )){
$is_new = true;
} else {
$is_new = false;
}
$data['products'][] = array(
'is_new' => $is_new,
'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),
);
第二个文件:catalog/view/theme/default/template/product/category.tpl
在 foreach
产品循环中添加此代码,例如之前:<p><?php echo $product['description']; ?></p>
:
<?php if($product['is_new']){ ?><span class="new-product">NEW</span><?php } ?>
我为 vqmod 创建了一个 xml 脚本:
<?xml version="1.0" encoding="UTF-8"?>
<modification>
<id>Products New Label</id>
<version>2.x</version>
<vqmver required="true">2.6.0</vqmver>
<author>sabeti05@gmail.com</author>
<file name="catalog/controller/product/category.php">
<operation error="skip">
<search position="replace"><![CDATA[$data['products'][] = array(]]></search>
<add><![CDATA[
if(strtotime($result['date_added']) > (time() - (60*60*24*10) )){
$is_new = true;
} else {
$is_new = false;
}
$data['products'][] = array(
'is_new' => $is_new,
]]></add>
</operation>
</file>
<file name="catalog/view/theme/*/template/product/category.tpl">
<operation error="skip">
<search position="before"><![CDATA[<p><?php echo $product['description']; ?></p>]]></search>
<add><![CDATA[
<?php if($product['is_new']){ ?><span class="new-product">NEW</span><?php } ?>
]]></add>
</operation>
</file>
</modification>