0

I am playing around with the Mini Cart content from outside of Magento.

This section of code uses $this:

<?php foreach($cartItems as $_item): ?>
    <?php echo $this->getItemHtml($_item) ?>
<?php endforeach; ?>

get_class($this) tells me that it is using Mage_Checkout_Block_Cart_Sidebar

How can I access this?

For example I know you can replace $this with Mage::helper('checkout/cart'), is there an equivalent for Mage_Checkout_Block_Cart_Sidebar?

2 Answers 2

0
Mage::app()->getLayout()->createBlock('checkout/cart_sidebar')->getItemHtml($item);

but this may not work in this case because item rendering requires a set of renderers attached to the main block.

1
  • Genius. Thank you!
    – Lee
    Sep 5, 2016 at 11:13
0

Though its not god way But you can use outside you can create object via below code and you can use it.

$class = Mage::app()->getLayout()->createBlock('checkout/cart_sidebar');
$class->getItemHtml($_item); 
2
  • you should never instantiate classes using new. Specially blocks. Blocks need to have a layout instance associated to them.
    – Marius
    Sep 5, 2016 at 11:07
  • Ok I will update My answer Sep 5, 2016 at 11:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.