How to Get Coupon Code Block to Work on Custom CMS Page

blockscmscoupon

I've been trying to get the coupon block from the cart to show up on a custom cms page:

{{block type="core/template" title="Coupon" template="checkout/cart/coupon.phtml"}}

The Coupomn Block is displayed, but submitting a coupon code does not seem to work? I was expecting it to direct me to the cart and let me know that the code has been used.

Alternatively I have tried adding the block to the template/checkout/cart/noItems.phtml page using this code:

<div class="couponpop"><?php echo $this->getLayout()->createBlock("core/template")->setTemplate("checkout/cart/coupon.phtml")->toHtml();?></div>

and trying to have it pop up in fancybox2 on pageload, but again, submitting a working coupon code does not seem to apply any discounts if in a fancybox2 modal or in the page content.

Any help would be greatly appreciated.

— EDIT:

I've tried Amit Bera's suggestion below, however this gives me a 302 error on the POST form-action.

Here is the content of my noItems.phtml file:

<div class="page-title">
    <h1><?php echo $this->__('Shopping Cart is Empty') ?></h1>
</div>
<div class="cart-empty">
    <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
    <?php echo $this->getChildHtml('checkout_cart_empty_widget'); ?>
    <p><?php echo $this->__('You have no items in your shopping cart.') ?></p>
    <p><?php echo $this->__('Click <a href="%s">here</a> to continue shopping.', $this->getContinueShoppingUrl()) ?></p>

    <div class="couponpop"><?php echo $this->getLayout()->createBlock("checkout/cart_coupon")->setTemplate("checkout/cart/coupon.phtml")->toHtml();?></div>

    <?php echo $this->getChildHtml('shopping.cart.table.after'); ?>
</div>

and here is what the console is telling me:

— EDIT 2:

As Amit rightly pointed out, this is not allowed by the magento system and even with a bit of core function hacking i couldn't get a coupon code to work without already having a product in your cart.

Best Answer

Just chnage block type checkout/cart_coupon from core/template.

Cms Block code should be:

{{block type="checkout/cart_coupon" name="cmsCoupon" template="checkout/cart/coupon.phtml"}}

And pragmatically code is

<div class="couponpop"><?php echo $this->getLayout()->createBlock("checkout/cart_coupon")->setTemplate("checkout/cart/coupon.phtml")->toHtml();?></div>

According too Magento logic , you cannot apply a coupon without cart any item at Cart.

At couponPostAction() function of cart controller file just check you currently have any product if not then redirect 302 using _goBack() function

if (!$this->_getCart()->getQuote()->getItemsCount()) {
        $this->_goBack();
        return;
    }
Related Topic