开车 - 奖励积分不减税



默认情况下,Opencart奖励积分似乎不适用于带税的产品。如果我用积分购买产品,它会减去产品的价格,但没有税,所以我需要增值税来支付那个"免费"产品。这样,您将无法获得带有奖励积分的免费产品,并且发票生成错误。

我正在尝试编辑模型/总计/奖励.php以包括产品的税!我找到了修复程序的片段,但它适用于旧版本,它似乎不适用于我的 1.5.5.1。

有人可以看看吗?

这是找到的代码片段

    <?php
class ModelTotalReward extends Model {
   public function getTotal(&$total_data, &$total, &$taxes) {
      if (isset($this->session->data['reward'])) {
         $this->language->load('total/reward');
         $points = $this->customer->getRewardPoints();
         if ($this->session->data['reward'] <= $points) {
            $discount_total = 0;
            $points_total = 0;
            foreach ($this->cart->getProducts() as $product) {
               if ($product['points']) {
                  $points_total += $product['points'];
               }
            }   
            $points = min($points, $points_total);
            foreach ($this->cart->getProducts() as $product) {
               $discount = 0;
               if ($product['points']) {
                  $discount = $product['total'] * ($this->session->data['reward'] / $points_total);
                  if ($product['tax_class_id']) {
                     $taxes[$product['tax_class_id']] -= ($product['total'] / 100 * $this->tax->getRates($product['tax_class_id'])) - (($product['total'] - $discount) / 100 * $this->tax->getRates($product['tax_class_id']));
                  }
               }
               $discount_total += $discount;
            }
            $total_data[] = array(
               'code'       => 'reward',
                 'title'      => sprintf($this->language->get('text_reward'), $this->session->data['reward']),
                'text'       => $this->currency->format(-$discount_total),
                 'value'      => -$discount_total,
               'sort_order' => $this->config->get('reward_sort_order')
               );
            $total -= $discount_total;
         }
      }
   }
   public function confirm($order_info, $order_total) {
      $this->language->load('total/reward');
      $points = 0;
      $start = strpos($order_total['title'], '(') + 1;
      $end = strrpos($order_total['title'], ')');
      if ($start && $end) { 
         $points = substr($order_total['title'], $start, $end - $start);
      }   
      if ($points) {
         $this->db->query("INSERT INTO " . DB_PREFIX . "customer_reward SET customer_id = '" . (int)$order_info['customer_id'] . "', order_id = '" . (int)$order_info['order_id'] . "', description = '" . $this->db->escape(sprintf($this->language->get('text_order_id'), (int)$order_info['order_id'])) . "', points = '" . (float)-$points . "', date_added = NOW()");            
      }
   }      
}
?>

这是原始模型/总计/奖励.php

    <?php
class ModelTotalReward extends Model {
   public function getTotal(&$total_data, &$total, &$taxes) {
      if (isset($this->session->data['reward'])) {
         $this->language->load('total/reward');
         $points = $this->customer->getRewardPoints();
         if ($this->session->data['reward'] <= $points) {
            $discount_total = 0;
            $points_total = 0;
            foreach ($this->cart->getProducts() as $product) {
               if ($product['points']) {
                  $points_total += $product['points'];
               }
            }   
            $points = min($points, $points_total);
            foreach ($this->cart->getProducts() as $product) {
               $discount = 0;
               if ($product['points']) {
                  $discount = $product['total'] * ($this->session->data['reward'] / $points_total);
                  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;
            }
            $total_data[] = array(
               'code'       => 'reward',
                 'title'      => sprintf($this->language->get('text_reward'), $this->session->data['reward']),
                'text'       => $this->currency->format(-$discount_total),
                 'value'      => -$discount_total,
               'sort_order' => $this->config->get('reward_sort_order')
               );
            $total -= $discount_total;
         }
      }
   }
   public function confirm($order_info, $order_total) {
      $this->language->load('total/reward');
      $points = 0;
      $start = strpos($order_total['title'], '(') + 1;
      $end = strrpos($order_total['title'], ')');
      if ($start && $end) { 
         $points = substr($order_total['title'], $start, $end - $start);
      }   
      if ($points) {
         $this->db->query("INSERT INTO " . DB_PREFIX . "customer_reward SET customer_id = '" . (int)$order_info['customer_id'] . "', description = '" . $this->db->escape(sprintf($this->language->get('text_order_id'), (int)$order_info['order_id'])) . "', points = '" . (float)-$points . "', date_added = NOW()");            
      }
   }      
}
?>

谢谢!

我遇到了同样的困难,只是用我在 OpenCart 论坛上找到的一些代码修复了它。在模型/总计/奖励中.php

      foreach ($this->cart->getProducts() as $product) {
           $discount = 0;
      if ($product['points']) {
              $discount = $product['total'] * ($this->session->data['reward'] / $points_total);
        /* TAX HACK */
        $tr = $this->tax->getRates($product['total'] - ($product['total'] - $discount), $product['tax_class_id']);
        foreach ($tr as $t) {
          $discount += $t['amount'];
        }
        /* TAX HACK */
              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;
        }

让我知道这是否也适合您。干杯!

相关内容

  • 没有找到相关文章

最新更新