2012-02-16 48 views
1

我正在做一個opencart項目的更新。我們將創建將應用折扣的優惠券。它包含在結帳頁面中。我們在管理員端添加了優惠券詳細信息,例如優惠券代碼,折扣,exp date等,但用戶端沒有任何反應。同時輸入優惠券代碼沒有任何反應價格沒有降低,我們也沒有收到任何錯誤信息。優惠券在opencart中不起作用

+0

你需要調試你的代碼。你確定你能看到錯誤信息嗎? – 2012-02-16 05:29:25

+0

沒有收到任何錯誤消息 – Natasha 2012-02-16 06:25:03

+0

錯誤報告級別,display_errors ini標誌和數據庫錯誤如何? – 2012-02-16 06:31:10

回答

4

優惠券的正常工作方式確實使其無效。原因是日期有點尷尬。您需要將開始日期設置爲一天後才能使用,並將結束日期設置爲一天後。這很奇怪,我知道,但這是它的工作原理,所以要確保日期是有效的優惠券

0

擴大周杰倫的答案的方式......

如果是日期的問題,這是因爲Opencart的希望優惠券是大於/小於(不等於)的日期

打開/catalog/model/checkout/coupon.php

首先功能應當getCoupon

找到這行:

$coupon_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "coupon WHERE code = '" . $this->db->escape($code) . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) AND status = '1'"); 

變化DATE_START < NOW()DATE_START < = NOW()

而且DATE_END < NOW()DATE_END < = NOW()

導致:

$coupon_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "coupon WHERE code = '" . $this->db->escape($code) . "' AND ((date_start = '0000-00-00' OR date_start <= NOW()) AND (date_end = '0000-00-00' OR date_end >= NOW())) AND status = '1'"); 
3

剛剛有一個類似的問題,優惠券申請成功但沒有折扣。

發現問題是由於訂單總訂購的方式,'小計'需要在'優惠券'之前。

感覺不對發佈的答案沒有任何代碼,所以這裏是我做了我的調試:目錄/模型/總/ coupon.php

的$總數爲0,這樣的折扣是越來越復位。

public function getTotal(&$total_data, &$total, &$taxes) { 
    if (isset($this->session->data['coupon'])) { 
     $this->load->language('total/coupon'); 

     $this->load->model('checkout/coupon'); 

     $coupon_info = $this->model_checkout_coupon->getCoupon($this->session->data['coupon']); 

     if ($coupon_info) { 
      $discount_total = 0; 

      if (!$coupon_info['product']) { 
       $sub_total = $this->cart->getSubTotal(); 
      } else { 
       $sub_total = 0; 

       foreach ($this->cart->getProducts() as $product) { 
        if (in_array($product['product_id'], $coupon_info['product'])) { 
         $sub_total += $product['total']; 
        } 
       } 
      } 

      if ($coupon_info['type'] == 'F') { 
       $coupon_info['discount'] = min($coupon_info['discount'], $sub_total); 
      } 

      foreach ($this->cart->getProducts() as $product) { 
       $discount = 0; 

       if (!$coupon_info['product']) { 
        $status = true; 
       } else { 
        if (in_array($product['product_id'], $coupon_info['product'])) { 
         $status = true; 
        } else { 
         $status = false; 
        } 
       } 

       if ($status) { 
        if ($coupon_info['type'] == 'F') { 
         $discount = $coupon_info['discount'] * ($product['total']/$sub_total); 
        } elseif ($coupon_info['type'] == 'P') { 
         $discount = $product['total']/100 * $coupon_info['discount']; 
        } 

        if ($product['tax_class_id']) { 
         $tax_rates = $this->tax->getRates($product['total'] - ($product['total'] - $discount), $product['tax_class_id']); 

         foreach ($tax_rates as $tax_rate) { 
          if ($tax_rate['type'] == 'P') { 
           $taxes[$tax_rate['tax_rate_id']] -= $tax_rate['amount']; 
          } 
         } 
        } 
       } 

       $discount_total += $discount; 
      } 

      if ($coupon_info['shipping'] && isset($this->session->data['shipping_method'])) { 
       if (!empty($this->session->data['shipping_method']['tax_class_id'])) { 
        $tax_rates = $this->tax->getRates($this->session->data['shipping_method']['cost'], $this->session->data['shipping_method']['tax_class_id']); 

        foreach ($tax_rates as $tax_rate) { 
         if ($tax_rate['type'] == 'P') { 
          $taxes[$tax_rate['tax_rate_id']] -= $tax_rate['amount']; 
         } 
        } 
       } 

       $discount_total += $this->session->data['shipping_method']['cost']; 
      } 

      // If discount greater than total 
      if ($discount_total > $total) { 
       $discount_total = $total; 
      } 

      $total_data[] = array(
       'code'  => 'coupon', 
       'title'  => sprintf($this->language->get('text_coupon'), $this->session->data['coupon']), 
       'value'  => -$discount_total, 
       'sort_order' => $this->config->get('coupon_sort_order') 
      ); 

      $total -= $discount_total; 
     } 
    } 
} 
0

從約翰的回答繼...在catalog/model/total/coupon.php我換出

// If discount greater than total 
if ($discount_total > $total) { 
    $discount_total = $total; 
} 

爲:

// If discount greater than total 
if ($coupon_info['type'] == 'F' && $discount_total > $subtotal) { 
    $discount_total = $subtotal; 
} 

希望沒有人曾經有調試這一個!