1

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?

3 Answers 3

3

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>
1

You can get checkout link in any template file like this:

$checkout_link = Mage::helper('checkout/url')->getCheckoutUrl();

Now just put it anywhere you like:

<a href="<?php echo $checkout_link ?>">Proceed to Checkout</a>

The function itself is located at app\code\core\Mage\Checkout\Helper\Url.php Same way you can call any other function from that file, if you might need for example multishipping link then just call getMSCheckoutUrl()

<?php $multishipping_checkout = Mage::helper('checkout/url')->getMSCheckoutUrl(); ?>
<a href="<?php echo $multishipping_checkout ?>">Multishipping</a>

and so forth..

0

$this->getMethods('top_methods') in checkout/cart.phtml runs the following code:

public function getMethods($nameInLayout)
{
    if ($this->getChild($nameInLayout) instanceof Mage_Core_Block_Abstract) {
        return $this->getChild($nameInLayout)->getSortedChildren();
    }
    return array();
}

This is method of Mage_Checkout_Block_Cart. But if you use $this->getMethods('top_methods') in other block then Magento run native getter "$this->getData('methods')" which return NULL in your case.

Solution for displaying only "Place Checkout" button:

<a href="<?php echo Mage::helper('checkout/url')->getCheckoutUrl() ?>">
    <?php echo Mage::helper('checkout')->__('Proceed to Checkout');?>
</a>
4
  • could you suggest a solution? Is there a way to allow other blocks access to this function?
    – Jai
    Commented Apr 19, 2013 at 14:22
  • If you need only "Place Checkout" button without "Checkout with Multiple Addresses" link then put it in your template: <a href="<?php echo Mage::helper('checkout/url')->getCheckoutUrl() ?>"><?php Mage::helper('checkout')->__('Proceed to Checkout');?></a>
    – Kirill
    Commented Apr 20, 2013 at 5:38
  • I do not see any reason for this: <?php Mage::helper('checkout')->__('Proceed to Checkout');?> and it also does nothing. You at least have to echo it, to have any effect at all, but the correct way, would be just this: <a href="<?php echo Mage::helper('checkout/url')->getCheckoutUrl() ?>"><?php $this->__('Proceed to Checkout');?></a>
    – ruuter
    Commented Apr 21, 2013 at 2:59
  • Yes, you are right. But you forgot "echo", too :) And you can not use $this instead of Mage::helper('checkout') because 'Mage_Checkout' module has translation for string "Proceed to Checkout" and $this would work only if block is part of "Mage_Checkout" module.
    – Kirill
    Commented Apr 21, 2013 at 8:17

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.