Magento 1.9 – How to Change Checkout/Onepage Layout Based on Condition

magento-1.9onepage-checkout

I want to change a checkout/onepage layout based on a condition.

Example:

<?php
    $coupon = Mage::getSingleton('checkout/session')->getQuote()->getCouponCode();
    if(($coupon == "SE50") || ($coupon == "SE00")){
    }
?>

To showcheckout.xml

<action method="setTemplate"><template>page/2columns-right.phtml</template></action>

I mean this page:

Enter image description here

if(empty($coupon))

<action method="setTemplate"><template>page/checkout-onepage.phtml</template></action>

A page like:

Enter image description here

Note: checkout-onepage.phtml is a custom page.

Best Answer

You can use a helper function to set the template based on a condition. Follow the below code.

Change the action tag in your layout.xml to the below.

 <action method="setTemplate"><template helper="your_module/getLayout" /></action>

In your module's helper file Data.php add the below code.

public function getLayout()
{
    $coupon = Mage::getSingleton('checkout/session')->getQuote()->getCouponCode();
    if(($coupon == "SE50") || ($coupon == "SE00")){

        return 'page/2columns-right.phtml';
    }
    else
    {
        return 'page/checkout-onepage.phtml';
    }
}
Related Topic