0

My intention is to create something close to rwd from 1.9 but I'm on 1.8.1 and it's difficult to update as there have been so many changes on this magento.
I've successfully added something from the minicart copying some text from mini_cart_top.phtml.

<?php

$prova = new Mage_Checkout_Block_Cart_Sidebar();
$_items = $prova->getRecentItems() ?>
    <?php if(count($_items)): ?>
            <div id="header-items">

                <div class="block-subtitle"><span><?php echo $prova->__('Producto(s) a&ntilde;adido(s)') ?></span> <div style="clear: both;"></div></div>

                <ol id="cart-sidebar" class="mini-products-list">
                <?php foreach($_items as $_item): ?>
                    <?php echo $prova->getItemHtml($_item) ?>
                <?php endforeach; ?>
                </ol>
                <div class="summary">
                    <?php echo $prova->__('Total + iva:') ?> 
                    <?php if ($prova->canApplyMsrp()): ?>
                        <span class="map-cart-sidebar-total"><?php echo $prova->__('ORDER TOTAL WILL BE DISPLAYED BEFORE YOU SUBMIT THE ORDER'); ?></span>
                    <?php else: ?>
                        <?php echo Mage::helper('checkout')->formatPrice($prova->getSubtotal()) ?>
                        <?php if ($_subtotalInclTax = $prova->getSubtotalInclTax()): ?>
                            <?php echo Mage::helper('checkout')->formatPrice($_subtotalInclTax) ?> <?php echo Mage::helper('tax')->getIncExcText(true) ?>
                        <?php endif; ?>
                    <?php endif; ?> 
                </div>                                  
                <button type="button" title="<?php echo $prova->__('Ver presupuesto') ?>" class="button btn-view" onclick="window.location='<?php echo $prova->getUrl('checkout/cart')?>';"><span><span><?php echo $prova->__('Ver presupuesto') ?></span></span></button>                                
                <button type="button" title="<?php echo $prova->__('Solicitar presupuesto') ?>" class="button btn-checkout" onclick="window.location='<?php echo $prova->getUrl('checkout/onepage')?>';"><span><span><?php echo $prova->__('Solicitar presupuesto') ?></span></span></button>                                
            </div>
        <script type="text/javascript">decorateList('cart-sidebar', 'none-recursive')</script>

    <?php else: ?>
        <div id="header-items" class="empty">
            <p class="empty"><?php echo $prova->__('No hay ning&uacute;n art&iacute;culo seleccionado.') ?></p>
        </div>
    <?php endif ?>

But <?php echo $prova->getItemHtml($_item) ?> gives me error:

Fatal error: Call to a member function createBlock() on a non-object in C:\wamp\www\ravanetto\app\code\core\Mage\Checkout\Block\Cart\Abstract.php on line 107

Why am I missing?

Edit:
That's how I call it through xml.

<default>
    <reference name="header">
        <block type="core/template" name="rwdtopCart" as="rwdtopCart" template="rwdmenu/rwdtopcart.phtml"/>
    <reference/>
<default/>

And I add this somewhere in header.phtml.

<div id="rwd-header-cart" class="skip-content">
    <?php echo $this->getChildHtml('rwdtopCart') ?>
</div>
2
  • Where is your XML? I think you're missing the reference to the block for this template.
    – Roy
    Oct 15, 2015 at 12:06
  • Just edited it.
    – danibg
    Oct 15, 2015 at 13:11

1 Answer 1

1

You're referencing to the core/template block which doesn't have the functions you're using in your template. Because it's based on the minicart I think you've to use the checkout/cart_minicart block. Try this:

<default>
    <reference name="header">
        <block type="checkout/cart_minicart" name="rwdtopSearch" as="rwdtopSearch" template="rwdmenu/rwdtopsearch.phtml"/>
    <reference/>
<default/>

If that's not working try the checkout/cart_sidebar block. Have a look at the default XML for the default used blocks, for example in app/design/frontend/rwd/default/layout/checkout.xml. Maybe you need the define the item renders (addItemRender) to.

After that you can change

$prova = new Mage_Checkout_Block_Cart_Sidebar();
$_items = $prova->getRecentItems();

To what it originally was:

$_items = $this->getRecentItems();
2
  • Wow, that was awesome. It was cart_sidebar. I just need to add some css now and it'll be done. Thank you very much!
    – danibg
    Oct 15, 2015 at 14:06
  • You're welcome!
    – Roy
    Oct 15, 2015 at 14:15

Your Answer

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

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