在Magento中添加自定义折扣订单总额不会更改营业税 [英] Adding A Custom Discount Order Total in Magento Does Not Change Sales Tax

查看:67
本文介绍了在Magento中添加自定义折扣订单总额不会更改营业税的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个自定义订单总计,在某些情况下可以提供折扣.总计总会正确显示,但是在计算时,营业税计算并未考虑我的折扣(因此,如果我给出10美元的折扣,则营业税金额是在我的折扣之前的全部金额上计算的).

例如以下内容:

Subtotal:              $856.49
Multi Unit Discounts: -$22.50
Shipping:              $10.96
Tax:                   $52.05
Grand Total:           $897.00

我的自定义折扣是多单位折扣.税率为6%.如您所见,总计基于所有订单项都是正确的,但是税额本身是不正确的(它基于除我的折扣以外的所有订单项).

在我的config.xml文件中,我需要执行以下操作以使订单总数在系统中正常工作:

     <sales>
        <quote>
            <totals>
                <mud>
                    <class>Wpe_Multiunitdiscount_Model_Multiunitdiscount</class>
                    <before>tax</before>
                </mud>
            </totals>
        </quote>
    </sales>    

以下是我的订单总计类的内容:

class Wpe_Multiunitdiscount_Model_Multiunitdiscount extends Mage_Sales_Model_Quote_Address_Total_Abstract {

public function collect(Mage_Sales_Model_Quote_Address $address) {

    if ($address->getData('address_type')=='billing') return $this;

    $items = $address->getAllItems();

    $total_discount = 0;

    foreach($items as $item) {
        $product_discounts = Mage::helper("multiunitdiscount")->findDiscounts($item);
        if($product_discounts > 0) {
            $total_discount += $product_discounts;
        }
    }

    $address->setMudAmount($total_discount);

    $address->setGrandTotal($address->getGrandTotal() - $address->getMudAmount() );
$address->setBaseGrandTotal($address->getBaseGrandTotal() - $address->getMudAmount());
    return $this;
}

public function fetch(Mage_Sales_Model_Quote_Address $address) {

    if ($address->getData('address_type')=='billing') return $this;

    if($address->getMudAmount() > 0) {

        $address->addTotal(array(
            'code'  => $this->getCode(),
            'title' => Mage::helper('sales')->__('Multi Unit Discounts'),
            'value' => -$address->getMudAmount(),
        ));
    }
    return $this;
}

}

为了避免在我不确定是否需要在此处发布大量代码的情况,我可以告诉您,上面代码中的帮助程序只是返回折扣中针对该特定商品的金额报价.

有人可以帮助我指出正确的方向来正确计算营业税吗?

为了保持这一简单性,我取消了计算折扣后的许多逻辑,现在尝试简单地从订单总额中扣除10美元作为折扣.如建议的那样,我没有修改地址的总计,现在仅设置折扣金额"和基本折扣金额".现在,营业税不累加,总计已关闭.也许如果那里有一个不错的教程,有人可以指出我的建议会有所帮助?我似乎并不了解订单总数如何相互影响.

public function collect(Mage_Sales_Model_Quote_Address $address) {

    if ($address->getData('address_type')=='billing') return $this;

    $address->setMudDiscount(10);
    $address->setDiscountAmount($address->getDiscountAmount() + $address->getMudDiscount());
    $address->setBaseDiscountAmount($address->getBaseDiscountAmount() + $address->getMudDiscount());

    return $this;
}

public function fetch(Mage_Sales_Model_Quote_Address $address) {

    if ($address->getData('address_type')=='billing') return $this;

    $address->addTotal(array(
        'code'  => $this->getCode(),
        'title' => Mage::helper('sales')->__('Multi Unit Discounts'),
        'value' => -$address->getMudDiscount(),
    ));
    return $this;
}

解决方案

转到System > Configuration.从左侧导航中选择"Tax",然后打开"Calculation Settings"组(如果尚未打开).

尝试将"Apply Customer Tax"参数更改为"After Discount"

I have created a custom order total that gives a discount in certain situations. The grand total always comes out correct, however the sales tax calculation is not taking my discount into account when calculating (so if I was giving a discount of $10, the sales tax amount was calculated on the entire amount before my discount).

Take for example the following:

Subtotal:              $856.49
Multi Unit Discounts: -$22.50
Shipping:              $10.96
Tax:                   $52.05
Grand Total:           $897.00

My custom discount is the Multi Unit Discounts. The tax rate is 6%. As you can see the grand total is correct based on all the line items, but the tax amount itself is not correct (it is based on all the line items except my discount).

In my config.xml file I have the following to get my order total working in the system:

     <sales>
        <quote>
            <totals>
                <mud>
                    <class>Wpe_Multiunitdiscount_Model_Multiunitdiscount</class>
                    <before>tax</before>
                </mud>
            </totals>
        </quote>
    </sales>    

The following is the contents of my order total class:

class Wpe_Multiunitdiscount_Model_Multiunitdiscount extends Mage_Sales_Model_Quote_Address_Total_Abstract {

public function collect(Mage_Sales_Model_Quote_Address $address) {

    if ($address->getData('address_type')=='billing') return $this;

    $items = $address->getAllItems();

    $total_discount = 0;

    foreach($items as $item) {
        $product_discounts = Mage::helper("multiunitdiscount")->findDiscounts($item);
        if($product_discounts > 0) {
            $total_discount += $product_discounts;
        }
    }

    $address->setMudAmount($total_discount);

    $address->setGrandTotal($address->getGrandTotal() - $address->getMudAmount() );
$address->setBaseGrandTotal($address->getBaseGrandTotal() - $address->getMudAmount());
    return $this;
}

public function fetch(Mage_Sales_Model_Quote_Address $address) {

    if ($address->getData('address_type')=='billing') return $this;

    if($address->getMudAmount() > 0) {

        $address->addTotal(array(
            'code'  => $this->getCode(),
            'title' => Mage::helper('sales')->__('Multi Unit Discounts'),
            'value' => -$address->getMudAmount(),
        ));
    }
    return $this;
}

}

For the sake of not posting a huge chunk of code in here that I am not sure is necessary, I can tell you that the helper in the above code simply returns the amount of money the discount is for that particular item in the quote.

Can someone help point me in the right direction for getting the sales tax calculation correct?

EDIT:

In order to keep this simple, I have removed a lot of my logic behind calculating the discount and am now trying to simple take $10 off the order total as a discount. As suggested I did not modify the Grand Total of the address and am now only setting the Discount Amount and Base Discount Amount. Now the sales tax does not add up and the grand total is off. Maybe if there is a good tutorial out there that someone can point me towards would help? I do not seem to be grasping how the order totals all interact with each other.

public function collect(Mage_Sales_Model_Quote_Address $address) {

    if ($address->getData('address_type')=='billing') return $this;

    $address->setMudDiscount(10);
    $address->setDiscountAmount($address->getDiscountAmount() + $address->getMudDiscount());
    $address->setBaseDiscountAmount($address->getBaseDiscountAmount() + $address->getMudDiscount());

    return $this;
}

public function fetch(Mage_Sales_Model_Quote_Address $address) {

    if ($address->getData('address_type')=='billing') return $this;

    $address->addTotal(array(
        'code'  => $this->getCode(),
        'title' => Mage::helper('sales')->__('Multi Unit Discounts'),
        'value' => -$address->getMudDiscount(),
    ));
    return $this;
}

解决方案

Go to System > Configuration. Select "Tax" from the left hand navigation, then open the "Calculation Settings" group if it isn't already.

Try changing the "Apply Customer Tax" parameter to "After Discount"

这篇关于在Magento中添加自定义折扣订单总额不会更改营业税的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆