0

The below code working fine for Logged In users for guest checkout it is not working. it's showing below error

jquery-1.10.2.min.js:6 POST http://example.com/checkout/onepage/coupon/ 503 (Service Unavailable) in the console

enter image description here

This is my Progress.phtml

<div class="block col-lg-3 order-wrap block-progress opc-block-progress<?php if (!$this->isCustomerLoggedIn()/* && !$this->getCheckout()->getStepData('billing', 'is_show')*/): ?> opc-block-progress-step-login<?php endif; ?>">
    <div class="block-title">
        <strong><span><?php echo $this->__('Your Checkout Progress') ?></span></strong>
    </div>
    <div class="block-content">

    <?php //echo $this->getChildHtml('coupon'); ?>
        <dl>

            <?php $getCouponCode = Mage::getSingleton('checkout/cart')->getQuote()->getCouponCode(); ?>
            <form id="discount-coupon-form" action="<?php echo $this->getUrl('checkout/onepage/coupon')?>" method="post">
           <!--  <label for="coupon_code"> <?php //echo $this->__('Enter your coupon code if you have one.') ?></label> -->
            <input type="text" id="coupon_code" name="coupon_code" placeholder="Enter Coupon Code" value="<?php echo $getCouponCode; ?>"/>
            <?php  if(strlen($getCouponCode)) { ?>
            <button type="button"  class="remove_coupon"  onclick="updateCoupon(2); return false;" value="<?php echo $this->__('Remove Coupon')?>"><span><?php echo $this->__('Remove Coupon') ?></span></button>
            <button type="button" class="apply_coupon" style="display:none;" onclick="updateCoupon(1); return false;" value="<?php echo $this->__('Apply Coupon')?>"><span><?php echo $this->__('Apply Coupon') ?></span></button>
            <?php }else{ ?>
            <button type="button"  class="remove_coupon" style="display:none;" onclick="updateCoupon(2); return false;" value="<?php echo $this->__('Remove Coupon')?>"><span><?php echo $this->__('Remove Coupon') ?></span></button>
            <button type="button" class="apply_coupon" onclick="updateCoupon(1); return false;" value="<?php echo $this->__('Apply Coupon')?>"><span><?php echo $this->__('Apply Coupon') ?></span></button>
            <?php } ?>
            <p id="coupon_msg"></p>
            </form>

            <?php if ($this->getCheckout()->getStepData('billing', 'is_show')): ?>
            <div id="billing-progress-opcheckout">
                <?php echo $this->getChildHtml('billing.progress') ?>
            </div>
            <?php endif; ?>

            <?php if ($this->getCheckout()->getStepData('shipping', 'is_show')): ?>
            <div id="shipping-progress-opcheckout">
                <?php echo $this->getChildHtml('shipping.progress') ?>
            </div>
            <?php endif; ?>

            <?php if ($this->getCheckout()->getStepData('shipping_method', 'is_show')): ?>
            <div id="shipping_method-progress-opcheckout">
                <?php echo $this->getChildHtml('shippingmethod.progress') ?>
            </div>
            <?php endif; ?>

            <?php if ($this->getCheckout()->getStepData('payment', 'is_show')): ?>
            <div id="payment-progress-opcheckout">
                <?php echo $this->getChildHtml('payment.progress') ?>
            </div>
            <?php endif; ?>
        </dl>
    </div>

</div>
<script type="text/javascript">
//<![CDATA[

function updateCoupon(reqid) {

    var reqid;
    if(reqid == 2) {  $('coupon_code').setValue('');  }

    /*$('discount-coupon-form').request({
        method: 'post',
        onComplete: payment.onComplete,
        onSuccess: payment.onSave,
        onFailure: checkout.ajaxFailure.bind(checkout)
    });*/

    //ajax call
    //form serialize
    //success
    var url = jQuery('#discount-coupon-form').attr('action');    
    jQuery.ajax({
        url: url,
        dataType: 'json',
        type: 'POST',
        data: 'ajax=true&' + jQuery('#discount-coupon-form').serialize(),
        success: function(data)
        {
           console.log(data);           
           var obj = jQuery.parseJSON(JSON.stringify(data));               
           jQuery('#checkout-review-load').html(obj.update_section.html);

           if(obj.valid == 'success'){
              jQuery('.remove_coupon').show();
              jQuery('.apply_coupon').hide();
              jQuery('#coupon_msg').html(obj.message);
           }else {
              jQuery('.remove_coupon').hide();
              jQuery('.apply_coupon').show();
              jQuery('#coupon_msg').html(obj.message);
           }
        }
    });

}
</script>

this is my cart controller

class Ronnyew_Checkout_CartController extends Mage_Checkout_CartController
{
    function couponPostAction()
    {
        // if not ajax have parent deal with result

        if(!isset($_POST['ajax']))
        {
            parent::couponPostAction();
            return;
        }

        $msg = '';

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

        if (!strlen($couponCode) && !strlen($oldCouponCode)) {
            $this->_goBack();
            return;
        }

        try {
            $this->_getQuote()->getShippingAddress()->setCollectShippingRates(true);
            $this->_getQuote()->setCouponCode(strlen($couponCode) ? $couponCode : '')
                ->collectTotals()
                ->save();

            if ($couponCode) {
                if ($couponCode == $this->_getQuote()->getCouponCode()) {
                    $this->_getSession()->addSuccess(
                        $this->__('Coupon code "%s" was applied.', Mage::helper('core')->htmlEscape($couponCode))
                    );
                }
                else {
                   $msg = $this->__('Coupon code "%s" is not valid.', Mage::helper('core')->htmlEscape($couponCode));
                }
            } else {
                $this->_getSession()->addSuccess($this->__('Coupon code was canceled.'));
            }

        } catch (Mage_Core_Exception $e) {
            $msg = $e->getMessage();
        } catch (Exception $e) {
             $msg = $this->__('Cannot apply the coupon code.');
            Mage::logException($e);
        }

        echo $msg;
    }
}

I got this message in reports

a:5:{i:0;s:46:"The requested Payment Method is not available.";i:1;s:2299:"#0 app/code/core/Mage/Payment/Model/Info.php(82): Mage::throwException('The requested P...')
  • This is not coupon related error. Please check ajax request data. – Prasanta Hatui Jun 7 '17 at 6:39
  • I dont think so it's error comes from ajax request data – prashanth Jun 7 '17 at 7:02
  • it is working fine for logged in users.but not working for guest checkout – prashanth Jun 7 '17 at 10:27

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.