1

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.

0

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;
    }
  • Thanks Amit, however that does not work on form submission - it gives me a 302 Moved Temporarily error - I've edited my question above. – tecjam Feb 5 '15 at 13:34
  • Thank you for your response. So Magento does not allow for this - i guess then it makes sense why the coupon block is not shown on the empty cart page, nor elsewhere in the store. Even with hacking the functions I still receive an invalid code error. Ah well, maybe in version 2 this will be possible. – tecjam Feb 5 '15 at 14:08

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.