显示特价';我在opencart的产品页面的结束日期


display special price's end date to my product page in opencart

如果设置了结束日期,我是否可以在opencart 1.5.5.1中的产品页面上显示特价的结束日期?

我把它添加到我的目录/控制器/产品/产品中。hp:

$special_info = $this->db->query("SELECT date_end FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "'");
         if ($special_info->num_rows) {
            $date_end = $special_info->row['date_end'];   
              $this->data['date_end'] = date($this->language->get('date_format_short'), strtotime($date_end));
         }else{
               $this->data['date_end'] = '';
         }

和我的catalog/view/theme/default/template/product/product.tpl这个:

Special Ends: <?php echo $date_end; ?>

但似乎效果不太好。如果我为特殊产品设置了日期,我会看到日期,但如果我没有,它仍然显示:30.11.-0001

如果未设置结束日期,如何使其不显示?

问题是,您只是为某个产品获得了一个特别优惠,而不管它实际上是最新的还是该客户群的。用于获取特殊信息的完整查询在/catalog/model/catalog/product.php

(SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special

因此,您还需要将其添加到查询中,并提供客户组id。您还需要检查日期是否为0000-00-00,因此您的完整代码应如下所示

$this->data['date_end'] = '';
$customer_group_id = $this->customer->isLogged() ? $this->customer->getCustomerGroupId() : $this->config->get('config_customer_group_id');
$special_info = $this->db->query("SELECT date_end FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "' AND customer_group_id ='" . (int) $customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1");
if ($special_info->num_rows && $special_info->row['date_end'] != '0000-00-00') {
    $this->data['date_end'] = date($this->language->get('date_format_short'), strtotime($special_info->row['date_end']));
}