2016-12-29 35 views
0

我正在使用opencart版本2.3.0.2 ..使用優惠券價值時的Opencart計算?

在這裏我得到的所有值除了當我的優惠券價值的稅值變得錯誤,並顯示值也出錯。

我希望在應用優惠券前使用優惠券和 單位折扣之前的每個產品單位稅。

我已經編寫以下,但不能使用下面的代碼即時得到總優惠金額以獲得正確的值與單位折扣.. 的東西,我想個人稅收優惠和折扣額將優惠券價值

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

      $coupon_info = $this->model_extension_total_coupon->getCoupon($this->session->data['coupon']); 
      if(isset($coupon_info) && !empty($coupon_info)) 
      { 
      foreach($product as $taxpro) { 


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

      $tax_rates = $this->tax->getRates($taxpro['total'] - ($taxpro['total'] - $discount), $taxpro['tax_class_id']); 
      foreach ($tax_rates as $tax_rate) 
          { 
           echo "<pre>"; print_r($total_data['taxes'][$tax_rate['tax_rate_id']]);echo "<pre>"; 
           if ($tax_rate['type'] == 'P') 
           { 

            $total_data['taxes'][$tax_rate['tax_rate_id']] -= $tax_rate['amount']; 
           } 



           echo "<pre>"; print_r($total_data['taxes'][$tax_rate['tax_rate_id']]); 
          } 


      foreach($tax_rates as $tax_coupon) 
      { 
       $protax = $tax_coupon['amount']; 

       $protax_unit = round($protax*$taxpro['quantity'],2); 
       $total_unit_tax += $protax_unit; 

       $coupon_tax += $tax_coupon['amount']; 
      } 
      } 

      } 

回答

0

您將需要保存含稅的所有產品。我省略了大量的代碼,使其在怎麼想的更清楚

例子:

<?php 
$prepareDiscount = array(); 
foreach ($products as $product){ 
$prepareDiscount[$taxRateForProduct] = $productTotal; 

} 

然後你需要遍歷prepareDiscounts陣列:

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

foreach($prepareDiscount as $taxRate => $value){ 
$discountPercentForRate = $value/$total; 
$discountForRate = $discountPercentForRate * $coupon_info['discount']; 
// Now you have the taxRate And the part of the discount which have that rate 
} 

這是一個示例代碼。如果您對更深入的感興趣,請檢查付款網關是如何做到的。獲得所有這些工作的關鍵只是在迭代產品時準備折扣。