0

我正在使用 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'];
             }
            }

           }
4

1 回答 1

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
}

这是一个示例代码。如果您对更深入的内容感兴趣,只需检查支付网关是如何做到的。让所有这些工作的关键只是在迭代产品时准备折扣。

于 2017-07-05T09:22:08.317 回答