简体   繁体   English

在Magento中添加自定义折扣订单总额不会更改销售税

[英]Adding A Custom Discount Order Total in Magento Does Not Change Sales Tax

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). 总计总是正确的,但计算时销售税计算没有考虑我的折扣(因此,如果我给出10美元的折扣,则销售税金额是在我的折扣之前计算的全部金额)。

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%. 税率为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: 在我的config.xml文件中,我有以下内容以使我的订单总计在系统中工作:

     <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. 为了保持这一点,我在计算折扣后删除了很多我的逻辑,现在我试图简单地将订单总额减去10美元作为折扣。 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 . 进入System > Configuration Select " Tax " from the left hand navigation, then open the "Calculation Settings" group if it isn't already. 从左侧导航中选择“ Tax ”,然后打开"Calculation Settings"组(如果尚未打开)。

Try changing the " Apply Customer Tax " parameter to " After Discount " 尝试将“ Apply Customer Tax ”参数更改为“ After Discount

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM