0

In the listing of items in checkout/cart, I have declared the following:

Mage::helper('checkout/cart')->group_rate_shipping_info=$group_rate['shipping_info'];

to be used in another .phtml file. This is being done in ../checkout/cart.phtml

That file then calls this->getChildHtml('totals'), which in turn calls two (+ more) .phtml files:

  1. /frontend/base/default/template/tax/checkout/subtotal.phtml - it works here, the value is set and prints
  2. /frontend/mycompany/default/template/tax/checkout/grandtotal.phtml - it doesn't work here.

I have several questions:

  1. Obviously first, why not? I suspect that the path to declaring Mage::helper(..) is somehow different inside mycompany files, but I don't know
  2. What working class could I attach an attribute to to work in both phtml files?
  3. Should I use Mage:getSingleton(..) instead?
  4. Is there a better "Magento way" of doing this?

Obviously I want to avoid using global variables... Thanks

Oliver Williams
  • 5,966
  • 7
  • 36
  • 78
  • Chances are that there is a different block hierarchy between the templates that work and don't. To share between them you'll need to store it somehow, whether you do that with `Mage::register()` and `registry()`, sessions or something else is up toyou – scrowler Jul 11 '15 at 21:32
  • Not sure if this is what you're trying to do: http://stackoverflow.com/questions/3340982/how-do-i-save-value-in-my-own-session-variable-in-magento – PedroKTFC Jul 12 '15 at 10:42

1 Answers1

0

There's the Magento registry:

Mage::register('group_rate_shipping_info', $group_rate['shipping_info']);

Make sure that this is registered first before the totals are rendered out. The Magento registry is a sort of session for the current request only. Usually the registry is used in controllers to register an object or variable for later access in the dispatch cycle. For example, in a catalog controller, the registry is used to store the current product or category for later access in one of the blocks or templates:

//in controller:
Mage::register('current_product', $product);
...
//later on in block:
$_product = Mage::registry('current_product');

Note:

Mage::helper('checkout/cart')->group_rate_shipping_info = $group_rate['shipping_info'];

This will not work as most Magento helper classes do not have public properties.