3

I have a custom module, with a controller that apply discounts codes in payment page.

After the discount it's applied, I set a success message. Now this message it's showing on homepage, even I apply the discount on payment page. So to see the message I need to go on homepage. My controller where I set the message look like this:

if($values){
        $this->chdxeckoutSession->getQuote()->setCouponCode($couponCode)
            ->collectTotals()
            ->save();
         $this->messageManager->addSuccess(
                                __(
                                    'You used coupon code "%1".',
                                    $escaper->escapeHtml($couponCode)
                                )
                            );

Does anyone know how can I set the location for this message to be in checkout/payment page?

  • after setting sucees message, you can redirect customer to specific page. – Dhiren Vasoya Feb 13 '17 at 10:24
  • the customer shold be on the same page after the message apper – Alin Lupoiu Feb 13 '17 at 10:28
  • You need to do that things. Or simple you can reload same page so message display on same page. – Dhiren Vasoya Feb 13 '17 at 10:29
  • you don't understand my question! i set a cusom discount on payment page, and my message apper on homepage. I need this message on payment page – Alin Lupoiu Feb 13 '17 at 11:05
  • you need to check this, it may help you. magento.stackexchange.com/questions/158378/… – Dhiren Vasoya Feb 13 '17 at 12:04
3

Seem that you try to make an Ajax request to the custom controller in the Checkout Page. Your custom controller should return JSON format.

        $response = [
            'errors' => false,
            'message' => 'The coupon code was applied.'
        ];

    $resultJson = $this->_resultJson->create();
    return $resultJson->setData($response);

In your Js function, you need to get the response message and show it. We can follow the Coupon form on the checkout page.

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.