views:

26

answers:

2

Hi!

inside the checkout onepage billing.phtml I have to do several checks and even remove or add stuff to the cart.
But I don't seem to find how to do that

how can I change the cart from within an template?

Thanks,
Joe

+1  A: 

From that file you can use $this->getQuote() to get a Mage_Sales_Model_Quote object. Methods you might find useful on that object are getAllItems(), addItem() and removeItem().

clockworkgeek
+2  A: 

I would recommend that you don't apply these logic changes in the phtml. You should try to work with the Shipping or Payment method PHP code, either by extending Magento's core methods or writing your own. There are numerous tutorials on the Magento wiki or other blogs on how to achieve this.

By editing the phtml directly, you run the risk of breaking when Magento releases patches or upgrades, and it is bad practice in general.

Jonathan Day
Views are for viewing, controllers are for controlling. Jonathan is absolutely correct in that you should *not* change the values of a cart from within a template. Worst case scenario, add an observer for the relevant action method and do the transformations there.
Joseph Mastey
my problem is with the time to develop it, I have only today to build it and will probably work on this weekend, so I have no choice for now and use everything in the template, but I get your point, you are right about it. Thanks.
Jonathan