【问题标题】:Trying to calculate sales tax on an individual item in Magento without displaying prices including tax尝试在 Magento 中计算单个商品的销售税而不显示含税价格
【发布时间】:2012-10-24 23:51:21
【问题描述】:

Magento CE 版本。 1.7.0.2

我正在尝试从我们的 Magento 商店获取一些订单数据,以集成到我们的其他业务软件中。就我而言,我需要计算单个商品的价格加税。以下代码仅在 在目录中显示产品价格 设置为 IncludeBoth(在系统 > 配置 > 销售 > 税收中)时有效。如何在网站显示不含税价格的同时计算商品的税费?

$customer_tax_class = Mage::getModel('tax/calculation')->getRateRequest()->getCustomerClassId();
$_product = Mage::getModel('catalog/product')->loadByAttribute('sku',$skunumber);
$my_price = Mage::helper('tax')->getPrice($_product, $_product->getPrice(), true, $shippingAddress, $billingAddress, $customer_tax_class);

我也尝试过使用它,但我仍然得到不含税的价格(除非我更改上述显示设置):

$_finalPriceInclTax = Mage::helper('tax')->getPrice($_product, $_product->getFinalPrice(), true, $shippingAddress, $billingAddress, $customer_tax_class); 

我知道这一定是可能的,因为 Magento 在您下订单时会计算税款。任何帮助将不胜感激。

【问题讨论】:

    标签: magento


    【解决方案1】:

    获得所需的所有参数需要一段时间,因为我们使用的是高度自定义的结帐,但这是最终对我有用的方法

        $my_quote = Mage::getSingleton('checkout/session')->getQuote();             
        $my_customer = Mage::getSingleton('customer/session')->getCustomer();
        $my_items = $quote->getAllItems();
        $taxClassId = $qty = $price = array();
        foreach ($my_items as $key => $my_item) {
          //get the price plus tax for this item
          // get the product tax id for this item first.
          $my_sku = $my_item->getSku();
          $qty[$my_sku] = $my_item->getQty(); 
          $taxClassId[$my_sku] = Mage::getModel('catalog/product')->load(
                      $my_item->getProductID())->getData("tax_class_id");
          $price[$my_sku] = Mage::getModel('catalog/product')->load(
                      $my_item->getProductID())->getData("price");
        }
        $my_store = Mage::app()->getStore($my_quote->getStoreId());
        $ctc = $my_customer->getTaxClassId();
        $tax_calc = Mage::getSingleton('tax/calculation');
        $tax_rate_req = $tax_calc->getRateRequest(
            $shippingAddress,
            $billingAddress,
            $ctc,
            $my_store);
        if(is_Array($taxClassId)){
        foreach($taxClassId as $key => $value){
          $my_rate[$key] = Mage::getSingleton('tax/calculation')->getRate(
                     $tax_rate_req->setProductClassId($value));
        }    
        foreach($my_rate as $key => $value){
          foreach($split_filter as $my_key => $my_value){
             //This is used because we split orders based on their shipping method
            if($my_value == $key){
            // This code might malfunction if tax rate is an integer (i.e. 8%)
            if(is_float($value)){
              $my_price = $price[$key];
              $my_qty = $qty[$key];
              $taxy = Mage::getModel('tax/calculation')->calcTaxAmount(
                 $my_price, 
                 $value
              );
              $price_withtax = $my_price + $taxy;
              // still need to multiply times qty ordered to get row totals
              $row_total = ($price_withtax * $my_qty);
            } else {// $value is not a float.
              $row_total = ($price[$key] * $qty[$key]);
            }
              // then add to other rows to get subtotal
              $subtotal_with_tax += $row_total;
          }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多