Before I give my answer I believe you may have a problem in your code - sessions should always be called as a singleton. Thus, the line Mage::getModel('checkout/session')
should be Mage::getSingleton('checkout/session')
.
In my opinion, neither approach is "most correct" but the first is likely most preferable.
My approach
The matter being that there should be a separation of concerns. A template, by nature, should style data that is available to it, not fetch the data for itself. This is the very reason we have a Block class - it's a model to render the view and provide data to the template.
I would propose this:
- Create your own custom module
- Use your own block class
- Provide methods to get the cart total from the block class
It would look something like this:
The block
class Company_Module_Block_Cart extends Mage_Core_Block_Template
{
protected $_store;
protected $_quote;
protected function _construct()
{
$this->_store = Mage::app()->getStore();
$this->_quote = Mage::getSingleton('checkout/session')->getQuote();
}
public function getCurrencyRate()
{
return $this->_store->getCurrentCurrencyRate();
}
public function getCurrencyCode()
{
return $this->_store->getCurrentCurrencyCode();
}
public function getCurrencySymbol()
{
$currencyCode = $this->getCurrencyCode();
$localeCurrency = Mage::app()->getLocale()->currency($currencyCode);
return $localeCurrency->getSymbol();
}
public function getCartTotal()
{
return $this->_quote->getGrandTotal();
}
}
This allows you to discretely call each method in your template:
<h1>This is my template</h1>
<p>My currency symbol is <?php echo $this->getCurrencySymbol(); ?> and I use currency code <?php echo $this->getCurrencyCode(); ?></p>
<h2>The current cart total is: <?php echo $this->getCartTotal(); ?></h2>
I wouldn't be worried so much about DRY (don't repeat yourself) code and non-reuse of code so much as the template being clean and a frontend developer being able to create semantic markup that makes use of the data without needing to know HOW to get that data.