0

I have racking my brain about this but not sure where the issue is, though my knowledge of php and ajax is about as minimal as it gets. I have been able to get the discount button on the last step of my onepage checkout process. However, when entering the code and clicking 'apply coupon' .. nothing happens. So I am not sure if there is a call that should be going on or what.

coupon.phtml

<form id="discount-coupon-form" action="<?php echo $this->getUrl('checkout/cart/couponPost') ?>" method="post">
    <div class="discount">
        <h2><?php echo $this->__('Discount Codes') ?></h2>
        <div class="discount-form">
            <label for="coupon_code"><?php echo $this->__('Enter your coupon code if you have one.') ?></label>
            <input type="hidden" name="remove" id="remove-coupone" value="0" />
            <div class="input-box">
                <input class="input-text" id="coupon_code" name="coupon_code" value="<?php echo $this->escapeHtml($this->getCouponCode()) ?>" />
            </div>
            <div class="buttons-set">
                <button type="button" title="<?php echo $this->__('Apply Coupon') ?>" class="button" onclick="discountForm.submit(false)" value="<?php echo $this->__('Apply Coupon') ?>"><span><span><?php echo $this->__('Apply Coupon') ?></span></span></button>
                <?php if(strlen($this->getCouponCode())): ?>
                    &nbsp; <button type="button" title="<?php echo $this->__('Cancel Coupon') ?>" class="button" onclick="discountForm.submit(true)" value="<?php echo $this->__('Cancel Coupon') ?>"><span><span><?php echo $this->__('Cancel Coupon') ?></span></span></button>
                <?php endif;?>
            </div>
        </div>
    </div>  </form>  <script type="text/javascript"> //<![CDATA[ var discountForm = new VarienForm('discount-coupon-form'); discountForm.submit = function (isRemove) {
    if (isRemove) {
        $('coupon_code').removeClassName('required-entry');
        $('remove-coupone').value = "1";
    } else {
        $('coupon_code').addClassName('required-entry');
        $('remove-coupone').value = "0";
    }
    return VarienForm.prototype.submit.bind(discountForm)(); } //]]> </script>

I also posted this within the checkout.xml

<block type="checkout/onepage_review_info" name="root" output="toHtml" template="checkout/onepage/review/info.phtml">    
...    
    <block type="checkout/cart_coupon" name="checkout.cart.coupon" as="coupon" template="checkout/cart/coupon.phtml"/>    
...    
</block>

as per noted here: https://stackoverflow.com/questions/28759782/magento-how-to-add-promo-code-form-on-one-page-checout-page

Again, the block is there, it just has no functionality currently. Would love for a little help! If any other file documentation is needed, just ask!

  • Please share any errors you might see in the browser console. – pspahn Jun 4 '15 at 19:56
  • Just did that now, not sure why it took so long to think to do so.. but I am getting this error when clicking 'apply coupon' ... Uncaught ReferenceError: discountForm is not defined – ne0nlight Jun 4 '15 at 19:58
  • Is there a bit of javascript somewhere that initializes the form? You should probably have var discountForm = new VarienForm('discount-coupon-form'); – pspahn Jun 4 '15 at 20:25
  • It does have that bit of code towards the bottom, however i found that takeing out type="button" on the apply coupon button makes it work...oddly enough – ne0nlight Jun 4 '15 at 20:42

Your Answer

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

Browse other questions tagged or ask your own question.