I want to add some extra amount to Grand total in Magento. So in checkout page, order review section will look like this:
This extra charges will depends on some conditions.
My question is: How can I change the grand total in checkout page? For this what I did is: I create a module. Please look my code:
app/code/local/Locwiseship/Customprice/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Locwiseship_Customprice>
<version>1.0.10</version>
</Locwiseship_Customprice>
</modules>
<global>
<events>
<!-- Création éventuelle du lien de parrainage lors de la commande -->
<sales_quote_collect_totals_after>
<observers>
<set_custom_price_locwiseship>
<type>singleton</type>
<class>Locwiseship_Customprice_Model_Sales_Quote_Address_Total_Mytotal</class>
<method>collect</method>
<method>fetch</method>
</set_custom_price_locwiseship>
</observers>
</sales_quote_collect_totals_after>
</events>
</global>
</config>
app/code/local/Locwiseship/Customprice/Model/Observer.php
<?php
/**
* @category Locwiseship
* @package Locwiseship_Customprice
*/
class Locwiseship_Customprice_Model_Sales_Quote_Address_Total_Mytotal
extends Mage_Sales_Model_Quote_Address_Total_Abstract
{
public function __construct()
{
$this->setCode('mytotal');
}
public function collect(Mage_Sales_Model_Quote_Address $address)
{
parent::collect($address);
foreach ($this->_getAddressItems($address) as $item) {
// These two lines represent whatever logic you're
// using to calculate these amounts
$baseAmt = 10;
$amt = 10;
// Set the item's total
$item->setBaseMytotalAmount($baseAmt);
$item->setMytotalAmount($amt);
// These methods automatically take care of summing
// "mytotal_amount" on the quote address
$this->_addBaseAmount($baseAmt);
$this->_addAmount($amt);
}
return $this;
}
public function fetch(Mage_Sales_Model_Quote_Address $address)
{
// Naturally, this exists on the quote address because "collect" ran already
$amt = $address->getMytotalAmount();
if ($amt != 0) {
$address->addTotal(array(
'code' => $this->getCode(),
'title' => Mage::helper('Locwiseship_Customprice')->__('My Total'),
'value' => $amt
));
}
return $this;
}
}
app/etc/modules/Locwiseship_Customprice.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Locwiseship_Customprice>
<active>true</active>
<codePool>local</codePool>
</Locwiseship_Customprice>
</modules>
</config>
Thais is my code. But Nothing happened..This is not working.. Is this the correct approach? How can I make this working? Please help me.. I am using Magento 1.9.0.1