【问题标题】:Opencart calculation when applying coupon value?应用优惠券价值时的Opencart计算?
【发布时间】:2016-12-29 14:39:04
【问题描述】:

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

           }

【问题讨论】:

    标签: opencart tax


    【解决方案1】:

    您需要保存所有含税的产品。我省略了很多代码,以便更清楚地了解如何思考

    例子:

    <?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
    }
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-07
      • 2012-08-30
      • 2020-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-04
      相关资源
      最近更新 更多