【问题标题】:display special price's end date to my product page in opencart在 opencart 中的我的产品页面上显示特价和日期
【发布时间】:2023-03-25 01:28:02
【问题描述】:

如果设置了结束日期,有什么方法可以在我的 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'] = '';
         }

到我的目录/视图/主题/default/template/product/product.tpl 这个:

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

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

如果没有设置结束日期,如何让它不显示?

【问题讨论】:

    标签: php date opencart


    【解决方案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']));
    }
    

    【讨论】:

    • 恐怕不行。我用你的代码替换了我的代码行,没有任何改变
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多