php
  • date
  • opencart
  • 2013-07-05 35 views 0 likes 
    0

    如果設置了結束日期,是否有任何方法可以在我的產品頁面上的opencart 1.5.5.1上顯示特價的結束日期?將特價的結束日期顯示在我的opencart產品頁面

    我將此添加到我的目錄/控制器/產品/ 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'] = ''; 
         } 
    

    和我的目錄/視圖/主題/默認/模板/產品/ product.tpl這樣的:

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

    但它似乎不工作得很好。我看到日期是否設置了特殊產品的日期,但如果我沒有,它仍然顯示:30.11.-0001

    如何在沒有設置結束日期的情況下使其不顯示任何內容?

    回答

    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'])); 
    } 
    
    +0

    它不工作,我害怕。我用你的代碼替換了我的代碼行,並且沒有任何變化 –

    +0

    @RaduCristian - 請參閱上面的編輯 –

    +0

    這就實現了!非常感謝你的幫助! –

    相關問題