1

Unable to place COD for guest user getting below error in console. Once reload the page the error goes away and everything works fine enter image description here

No third party module or custom template. Simply giving error. Plugin to check if COD is available for the post code.

public function afterIsAvailable(\Magento\Payment\Model\Method\AbstractMethod $subject, $result)
{
    $postcode = $this->_checkoutSession->getQuote()->getShippingAddress()->getPostcode();
    if (condition) {
                return $result;
    }

    return false;
}
  • Any custom module on checkout? – Prathap Gunasekaran Feb 14 '19 at 11:45
  • No. I added one step in checkout but removed. still getting this error. One plugin I have created to check if COD is available or not afterIsAvaiable method. Please see the updated query – Abhinav Kumar Feb 14 '19 at 11:58
  • The default magento isAvailable method has one argument $quote, which i think you need to pass in after method as well as third parameter. public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null) – Yash Shah Feb 14 '19 at 12:15
  • @yash7690 for after plugin its not mandatory if you are not using the parameter. Thanks tried this also but no luck – Abhinav Kumar Feb 14 '19 at 18:41
1

Open following file

vendor/magento/module-offline-payments/view/frontend/web/js/view/payment/method-renderer/cashondelivery-method.js

Put this file on your custom theme. (For testing purpose you can direct change file from vendor)

Change following code

getInstructions: function() {
     return window.checkoutConfig.payment.instructions[this.item.method];
}

with following

getInstructions: function() {
     if (typeof window.checkoutConfig.payment.instructions != 'undefined')
          {
              return window.checkoutConfig.payment.instructions[this.item.method];
          }
     }

Run following command

php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy

I hope this will work for you.

  • Its work but why, don't know. Can you explain :) – Abhinav Kumar Feb 14 '19 at 18:44
  • In magento 2.1 there is issue with that. Some how payment instruction object not initiate and return undefined because of that. I have checked object type, before it used. – user55548 Feb 15 '19 at 4:58

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.