magento - Custom Mage_Sales_Model_Quote_Address_Total_Abstract calculate twice: billing&shipping address -
i intended make custom credit module can use our store's credits discount. after looking examples, added checkout step onepage checkout. , extends mage_sales_model_quote_address_total_abstract have custom collector calculate total. hard coded discount value see how works:
public function collect(mage_sales_model_quote_address $address) { parent::collect ( $address ); //if($address->getdata('address_type')=='billing') return $this; try { $this->_setamount ( -10 )->_setbaseamount ( -10 ); } catch ( exception $e ) { mage::throwexception ( $e->getmessage () ); //do nothing. } return $this; } public function fetch(mage_sales_model_quote_address $address) { parent::fetch ( $address ); //if($address->getdata('address_type')=='billing') return $this; $title = mage::helper ( 'sales' )->__ ( 'credittest' ); $address->addtotal ( array ('code' => $this->getcode (), 'title' => $title, 'value' => -10 ) ); return $this; }
the section in config.xml looks this:
<sales> <quote> <totals> <credittest> <class>sales/quote_address_total_credit</class> <after>tax_subtotal,subtotal,freeshipping</after> <before>grand_total</before> </credittest> </totals> </quote> </sales>
however result comes out -20 deducted. after debug tracing, custom collector called twice, once address type "billing" , "shipping". added commented code above calculate when shipping address comes in. i'm not sure if right way go.
why other class in mage_sales_model_quote_address won't calculate twice? invoked twice according tracing. , what's right way solve issue?
thank in advance.
Comments
Post a Comment