0

如果设置了结束日期,有什么方法可以在 opencart 1.5.5.1 的产品页面上显示特价的结束日期?

我将此添加到我的目录/控制器/产品/product.php:

$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'] = '';
         }

和我的目录/视图/主题/默认/模板/产品/产品.tpl 这个:

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

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

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

4

1 回答 1

1

问题是你只是得到一个产品的特别优惠,不管它是真的过时的还是针对那个客户群的。用于获取特殊信息的完整查询位于/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']));
}
于 2013-07-05T14:42:55.167 回答