1

マジェント CE ver. 1.7.0.2

Magento ストアから注文データを取得して、他のビジネス ソフトウェアに統合しようとしています。私の場合、個々の商品の価格と税金を計算する必要があります。以下のコードは、[カタログに製品価格を表示] が [含める]または[両方]に設定されている場合にのみ機能します([システム] > [構成] > [販売] > [税])。ウェブサイトに税抜価格を表示したまま、商品の税額を計算するにはどうすればよいですか?

$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が税金を計算するので、それが可能であるに違いないことはわかっています。どんな助けでも大歓迎です。

4

1 に答える 1

2

高度にカスタマイズされたチェックアウトを使用しているため、必要なすべてのパラメーターを取得するのに時間がかかりましたが、最終的には次のようになりました

    $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;
      }
    }
于 2012-11-02T14:45:40.187 に答える