magento - Use a template/block in a helper -


i have helper method items in customer's cart

public function getcartdata() {     //get cart data     $quote = mage::getsingleton('checkout/session')->getquote();     $cartitems = $quote->getallvisibleitems();     $items = '';     foreach ($cartitems $item) {         $items .= $item->getid() . " ";     }     return $items; } 

but want replace line

$items .= $item->getid() . " "; 

with instance of template/checkout/cart/sidebar/default.phtml

how go this? method being called in ajax controller. want update user's cart without page refresh, needs formatted.

so want render what's in template each $item in loop?

if @ app/design/frontend/base/default/layout/checkout.xml, see original sidebar block defined:

<block type="checkout/cart_sidebar" name="cart_sidebar" template="checkout/cart/sidebar.phtml" before="-">     <action method="additemrender"><type>simple</type><block>checkout/cart_item_renderer</block><template>checkout/cart/sidebar/default.phtml</template></action>     <action method="additemrender"><type>grouped</type><block>checkout/cart_item_renderer_grouped</block><template>checkout/cart/sidebar/default.phtml</template></action>     <action method="additemrender"><type>configurable</type><block>checkout/cart_item_renderer_configurable</block><template>checkout/cart/sidebar/default.phtml</template></action> </block> 

i'm not sure if you'll able away using item renderer, checkout/cart_item_renderer (which want based on question), let's try it. you'll have programmatically create instance of block, feed item, assign template, , output html variable.

$items=''; foreach($cartitems $item) {     $items.=mage::app()->getlayout()->createblock('checkout/cart_item_renderer')             ->setitem($item)             ->settemplate('checkout/cart/sidebar/default.phtml')             ->tohtml(); } 

notice how after creating block, set item. that's important, because if examine template you'll see @ top calls:

<?php $_item = $this->getitem() ?> 

give try , see if helps!


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -