如果设置了结束日期,有没有办法在opencart 1.5.5.1的产品页面上显示特价的结束日期?
我将此添加到我的目录/ controller / product / 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'] = '';
}
和我的目录/ view / theme / default / template / product / product.tpl这个:
Special Ends: <?php echo $date_end; ?>
但似乎效果不佳。如果我将日期设置为特殊产品,我会看到日期,但如果我没有,它仍会显示: 30.11.-0001
如果未设置结束日期,如何才能显示任何内容?
答案 0 :(得分: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']));
}