Magento – How to move the “Proceed to Checkout” button outside of the cart block

checkoutmagento-1.7onepage-checkout

So when you click on a product, you get taken to the cart page, in my layouts I have a sidebar included before the content, so i can get a two column layout.

I want the proceed to checkout button to be in the sidebar and not the content area with all the products, buttons etc..

This is what my sidebar include/block looks like:

<aside class="checkout-process">    
   <div class="totals">     
       <?
           echo $this->getChildHtml('totals');

           if(!$this->hasError())
           {                
               ?>
                   <ul class="checkout-types">
                       <?
                           foreach ($this->getMethods('top_methods') as $method)
                           {
                               if ($methodHtml = $this->getMethodHtml($method))
                               {
                                   ?>
                                       <li><?= $methodHtml; ?></li>
                                   <? 
                               }
                           } 
                       ?>
                  </ul>
              <?
            }
        ?>      
    </div>
</aside>

However When I tried this, i got an error saying that

Warning: Invalid argument supplied for foreach()  in /httpdocs/app/design/frontend/choice/default/template/page/html/checkout_process.phtml on line 12

I've spend the past 3 hours searching through google and stack overflow, but i've come up dry, could anyone explain what i need to do to move this button into another block? or direct me to a tutorial that will help?

Best Answer

Create a new instance of Mage_Checkout_Block_Cart as e.g. custom_methods, assign that as the child of your column parent (e.g. "right"), and then set the checkout.cart.top_methods block as a child of your block:

<checkout_cart_index>
    <reference name="right">
        <block name="custom_methods" type="checkout/cart" template="custom/template.phtml" >
            <action method="insert">
                <block>checkout.cart.top_methods</block>
                <sib></sib>
                <after />
                <alias>myMethodDisplay</alias>
            </action>
        </block>
    </reference>
</checkout_cart_index>

Then in your custom/template.phtml, do the following:

<div class="page-title title-buttons">
    <?php if(!$this->hasError()): ?>
    <ul class="checkout-types">
    <?php foreach ($this->getMethods('myMethodDisplay') as $method): ?>
        <?php if ($methodHtml = $this->getMethodHtml($method)): ?>
        <li><?php echo $methodHtml; ?></li>
        <?php endif; ?>
    <?php endforeach; ?>
    </ul>
    <?php endif; ?>
</div>
Related Topic