0

I want to show message "Coupon already used" If coupon limit/used by customer instead of "The coupon code isnt valid."

But Didnt know how to add this condition. Thank you in advanced.

0

Path for the core file for set coupon details:

"project\vendor\magento\module-sales-rule\view\frontend\web\js\action\set-coupon-code.js"

You can extend this file and can change the message like this:

    this file consist of this code:
        /**
         * Copyright © Magento, Inc. All rights reserved.
         * See COPYING.txt for license details.
         */

        /**
         * Customer store credit(balance) application
         */
    define([
        'ko',
        'jquery',
        'Magento_Checkout/js/model/quote',
        'Magento_Checkout/js/model/resource-url-manager',
        'Magento_Checkout/js/model/error-processor',
        'Magento_SalesRule/js/model/payment/discount-messages',
        'mage/storage',
        'mage/translate',
        'Magento_Checkout/js/action/get-payment-information',
        'Magento_Checkout/js/model/totals',
        'Magento_Checkout/js/model/full-screen-loader'
    ], function (ko, $, quote, urlManager, errorProcessor, messageContainer, storage, $t, getPaymentInformationAction,
        totals, fullScreenLoader
    ) {
        'use strict';

        return function (couponCode, isApplied) {
            var quoteId = quote.getQuoteId(),
                url = urlManager.getApplyCouponUrl(couponCode, quoteId),
                message = $t('Your coupon was successfully applied.');

            fullScreenLoader.startLoader();

            return storage.put(
                url,
                {},
                false
            ).done(function (response) {
                var deferred;

                if (response) {
                    deferred = $.Deferred();

                    isApplied(true);
                    totals.isLoading(true);
                    getPaymentInformationAction(deferred);
                    $.when(deferred).done(function () {
                        fullScreenLoader.stopLoader();
                        totals.isLoading(false);
                    });
                    messageContainer.addSuccessMessage({
                        'message': message
                    });
                }
            }).fail(function (response) {

//changes starts for add custom error msg


            var newerrormessage = $t("dasdasdasdasdadasdsa");
            messageContainer.addErrorMessage({
                    'message': newerrormessage 
                });

//changes end 

                fullScreenLoader.stopLoader();
                totals.isLoading(false);
                errorProcessor.process(response, messageContainer);
            });
        };
    });

after this comment "//changes starts for add custom error msg" you can set the new msg like shown in code like that by adding a new error message using "messageContainer" object.

3
  • Thanks for answer @nihal , I want message according to conditions .. mean "Coupon already used ", "In valid coupon" May 7 '20 at 1:18
  • yeah you can add a condition or use the success or failure condition to show your message already defined in this code. 1.if you want to add a message when coupon succesfully applied, change the text in message variable. 2.if you want to add a message when coupon applied failed, change the text in newerrormessage variable. May 7 '20 at 8:20
  • no not success message. If customer has reached coupon to limit "Want to show message Coupon used" ... If coupon doesnt exit .. "In valid copon" I want coupon valtion with msg May 7 '20 at 8:35

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.