2

I would like to move the coupon code block from the cart page to the checkout page if this is possible or add an extra block on to the onepage checkout I am using CE 1.7.

  • have you try something – Amit Bera May 7 '15 at 10:21
  • Nope, I know how to remove the block from the cart but not add it to the checkout page – Michael May 7 '15 at 10:25
  • are you magento default onepage checkout or any extension ? – Amit Bera May 7 '15 at 10:47
  • It is the default magento onepage checkout. Thanks Mike – Michael May 7 '15 at 11:31
  • on which step are you want? – Amit Bera May 7 '15 at 12:10
0

There is free extension available for that

http://www.magentocommerce.com/magento-connect/add-coupon-code-from-your-checkout-process.html

https://www.apptha.com/blog/add-discount-coupon-in-magento-one-page-checkout-with-and-without-coding/

Note::I am not promoting this extension ,,i have placed here due to free extension

1

As you want to apply the coupon on review step then you need to apply coupon and update review content using ajax.

Step1: First override the controller Onepagecontroller.php using below link

  1. Making edits to core controllers OnepageController.php
  2. How to override a controller in Magento

Step2: Then on the override controller Amit_CustomCheckout_OnepageController add a function applycouponAction,in where you have send the ajax request to apply coupon and return update content of review step.

<?php 
require_once Mage::getModuleDir('controllers', "Mage_Checkout").DS."IndexController.php";
class Amit_CustomCheckout_OnepageController extends Mage_Checkout_OnepageController
{
    public function applycouponAction(){        /**
         * No reason continue with empty shopping cart
         */
        if (!$this->getOnepage()->getQuote()->getItemsCount()) {
                    $result['error']=true;
                    $result['message']=$this->__('No item in cart.');
         $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));

            return;
        }

        $couponCode = (string) $this->getRequest()->getParam('coupon_code');
        if ($this->getRequest()->getParam('remove') == 1) {
            $couponCode = '';
        }
        $oldCouponCode = $this->getOnepage()->getQuote()->getCouponCode();

        if (!strlen($couponCode) && !strlen($oldCouponCode)) {
                    $result['error']=true;
                    $result['message']=$this->__('Coupon code "%s" is not valid.', Mage::helper('core')->escapeHtml($couponCode));
         $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
            return;
        }

        try {
            $codeLength = strlen($couponCode);
            $isCodeLengthValid = $codeLength && $codeLength <= Mage_Checkout_Helper_Cart::COUPON_CODE_MAX_LENGTH;

            $this->getOnepage()->getQuote()->getShippingAddress()->setCollectShippingRates(true);
            $this->getOnepage()->getQuote()->setCouponCode($isCodeLengthValid ? $couponCode : '')
                ->collectTotals()
                ->save();

            $result=array();

            if ($codeLength) {
                if ($isCodeLengthValid && $couponCode == $this->getOnepage()->getQuote()->getCouponCode()) {
                    $result['error']=false;
                    $result['message']=$this->__('Coupon code "%s" was applied.', Mage::helper('core')->escapeHtml($couponCode));
                    $result['html']=$this->_getReviewHtml();
                } else {
                    $result['error']=true;
                    $result['message']=$this->__('Coupon code "%s" is not valid.', Mage::helper('core')->escapeHtml($couponCode));
                }
            } else {

                    $result['error']=false;
                    $result['message']=$this->__('Coupon code was canceled.');
                    $result['html']=$this->_getReviewHtml();

            }

        } catch (Mage_Core_Exception $e) {
            $this->_getSession()->addError($e->getMessage());
                    $result['error']=true;
                    $result['message']=$this->__('Cannot apply the coupon code.');

        } catch (Exception $e) {
                    $result['error']=true;
                    $result['message']=$this->__('Cannot apply the coupon code.');
                    Mage::logException($e);
        }
        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));

}
}

In this code, i have return json data with a flag field name errooe .html return contend of handler checkout_onepage_review and check this handler file at checkout.xml

Then basic on this logic you need to update content

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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