Magento 1.9 Changing Totals Layout and Calculations
-
11-01-2021 - |
Pergunta
I want to change to layout of order totals on review, print, email and admin panel somehow i manage to do that with cod fee its showing perfect as screenshot attached COD Fee Vat (5%) Subtotal Same i want to do that with Shipping and Subtotal of products from the backend i mange to bring price with and without tax but showing tax in separte line for each total ( subtotal and shipping total )
also i want to remove that tax line
Solução
This can be achieved by combining some tricks First, make tax rule 5% for shipping class in Magento back office
then create a copy of core file in local
This "app\code\core\Mage\Tax\Block\Sales\Order\Tax.php"
into this "app\code\local\Mage\Tax\Block\Sales\Order\Tax.php"
because we should never edit the core file directly, we can override them by placing in the local folder with the same path
in function _initSubtotal()
Change this
$totalExcl = new Varien_Object(array(
'code' => 'subtotal_excl',
'value' => $subtotal,
'base_value'=> $baseSubtotal,
'label' => $this->__('Subtotal (Excl.Tax)')
));
$totalIncl = new Varien_Object(array(
'code' => 'subtotal_incl',
'value' => $subtotalIncl,
'base_value'=> $baseSubtotalIncl,
'label' => $this->__('Subtotal (Incl.Tax)')
));
$parent->addTotal($totalExcl, 'subtotal');
$parent->addTotal($totalIncl, 'subtotal_excl');
To This
$totalExcl = new Varien_Object(array(
'code' => 'subtotal_excl',
'value' => $subtotal,
'base_value'=> $baseSubtotal,
'label' => $this->__('Product RSP (Net)')
));
$subtotal_vat= ($subtotal* 0.05);
$base_subtotal_vat= ($baseSubtotal* 0.05);
$totalVat = new Varien_Object(array(
'code' => 'subtotal_vat',
'value' => $subtotal_vat,
'base_value'=> $base_subtotal_vat,
'label' => $this->__('VAT (5%)')
));
$totalIncl = new Varien_Object(array(
'code' => 'subtotal_incl',
'value' => $subtotalIncl,
'base_value'=> $baseSubtotalIncl,
'label' => $this->__('Subtotal')
));
$parent->addTotal($totalExcl, 'subtotal');
$parent->addTotal($totalVat, 'subtotal_excl');
$parent->addTotal($totalIncl, 'subtotal_vat');
That will do the job for the subtotal of products Now let's move on to shipping
same file function _initShipping() Change this
$totalExcl = new Varien_Object(array(
'code' => 'shipping',
'value' => $shipping,
'base_value'=> $baseShipping,
'label' => $this->__('Shipping & Handling (Excl.Tax)')
));
$totalIncl = new Varien_Object(array(
'code' => 'shipping_incl',
'value' => $shippingIncl,
'base_value'=> $baseShippingIncl,
'label' => $this->__('Shipping & Handling (Incl.Tax)')
));
$parent->addTotal($totalExcl, 'shipping');
$parent->addTotal($totalIncl, 'shipping');
To this
$totalExcl = new Varien_Object(array(
'code' => 'shipping_excl',
'value' => $shipping,
'base_value'=> $baseShipping,
'label' => $this->__('Shipping & Handling')
));
$shipping_vat = ($shipping * 0.05);
$base_shipping_vat= ($baseShipping* 0.05);
$totalVat = new Varien_Object(array(
'code' => 'shipping_vat',
'value' => $shipping_vat, // this can be easily calculated
'base_value'=> $base_shipping_vat,
'label' => $this->__('VAT (5%)')
));
$totalIncl = new Varien_Object(array(
'code' => 'shipping_incl',
'value' => $shippingIncl,
'base_value'=> $baseShippingIncl,
'label' => $this->__('Subtotal')
));
$parent->addTotal($totalExcl, 'shipping');
$parent->addTotal($totalVat, 'shipping_excl');
$parent->addTotal($totalIncl, 'shipping_vat');
Removing tax is the easy part
app\design\frontend[your-theme-name]\default\template\tax\checkout\tax.phtml
if file is not present then just copy that from base Just comment out every code in that file in your theme