Questions About Creating An Order Total In Magento
I am attempting to create an order total module to do some custom price adjustments. Just to get started with this I am just trying to get it to add $20 to every single order (eventually putting in the real logic).
I am having issues with the module that I created. The first issue is that it appears to be running twice (so it is taking $40 off instead of only $20 -- Logging showed me that both the collect and fetch methods are being run twice)
The second issue is that the discount line item is appearing below the Grand Total line.
Can someone tell me what I am doing wrong here? The contents of my config.xml and order total class are below.
config.xml Content
<global>
<sales>
<quote>
<totals>
<mud>
<class>Wpe_Multiunitdiscount_Model_Multiunitdiscount</class>
<before>grand_tota开发者_如何学JAVAl</before>
</mud>
</totals>
</quote>
</sales>
</global>
Wpe_Multiunitdiscount_Model_Multiunitdiscount Content
class Wpe_Multiunitdiscount_Model_Multiunitdiscount extends Mage_Sales_Model_Quote_Address_Total_Abstract {
public function collect(Mage_Sales_Model_Quote_Address $address) {
$address->setGrandTotal($address->getGrandTotal() + 20 );
$address->setBaseGrandTotal($address->getBaseGrandTotal() + 20);
return $this;
}
public function fetch(Mage_Sales_Model_Quote_Address $address) {
$address->addTotal(array(
'code' => $this->getCode(),
'title' => Mage::helper('sales')->__('Super Tax'),
'value' => 20,
));
return $this;
}
}
Regarding the "double" issue, as far as I understand it, it's because magento collects your total twice, once for the shipping address and once for the billing address.
I'm sure there has to be a better way to manage this, but for now I've added in the first line of my collect method:
if ($address->getData('address_type')=='billing') return $this;
And for the "placement", have you try with "after" instead of "before" (changing the total alias, of course, let's say "tax" for example")?
HTH
You cannot touch any other totals when adding your own custom total. Please see this thread for more information: Magento upfront payment
精彩评论