Reputation: 393
I'm working on creating some new email templates for a store.
I have the template 95% working my only problem is that in the table showing the order items I cannot seem to find the file where the totals are pulled in, linked to an image showing the issue below.
Naturally I would like to be able add some inline code to this area due to it being for emails, and also to change the labels on the left. I've managed to track the totals area down to the following file
template/sales/order/totals.phtml
I'm at a loss as to what file this then calls.
Upvotes: 1
Views: 5203
Reputation: 734
If you look in
layout/sales.xml:268
You will see the layout handle sales_email_order_items. Inside there is a block "order_totals", which has that template. To add a new total to the email you would just have to add it as a child of that. On line 275 you can see they add a block named 'tax'.
Inside the totals.phtml file you can see it call $this->getTotals() as part of a foreach. That method is defined at
Mage/Sales/Block/Order/Totals.php:281
This just returns the totals that are already defined. This data is populated by config.xml files that have defined:
<global><sales><quote><totals>...
Jumping back to totals.phtml, it checks if the total has a block defined for it. This would be a field in the config.xml file. If you have a totals model you want to customize you would do it that way.
Otherwise, before the page is rendered (call to _beforeToHtml() on line 44) it interates over the child blocks and, if they respond to the method 'initTotals', calls that method. That method should create an object that represents your total and add it to the parent. For example, here is the code for a totals block I recently wrote (which is based on code I can't post publicly):
public function initTotals()
{
if ((float)$this->getParentBlock()->getSource()->getMytotalAmount() == 0) {
return $this;
}
$total = new Varien_Object(array(
'code' => $this->getNameInLayout(),
'block_name'=> $this->getNameInLayout(),
'area' => $this->getArea()
));
$after = $this->getAfterTotal();
if (!$after) {
$after = 'subtotal';
}
$this->getParentBlock()->addTotal($total, $after);
return $this;
}
I hope this helped.
Upvotes: 3