应用优惠券价值时的Opencart计算?

时间:2016-12-29 14:39:05

标签: opencart tax

我使用的是opencart版本2.3.0.2 ..

我获取所有值,除非我的优惠券价值导致税收出错并显示值也出错。

在申请优惠券之前,我想要每个产品单位税 申请优惠券后的单位折扣。

我已在下面编写了一些内容,但无法通过单位折扣获得正确的值。 通过使用以下代码获得总折扣金额,我需要个人折扣税和应用优惠券价值时的折扣金额

$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'];
             }
            }

           }

1 个答案:

答案 0 :(得分: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
}

这是一个示例代码。如果您对更深入的兴趣,请查看付款网关是如何做到的。实现所有这些工作的关键是在迭代产品时准备折扣。