1

How to change a shipping method config error message by custom module in magento 2

See the below image, I want to update display error message in e checkout page with custom module.

I know that we change display error using shipping method configuration but i want to need custom module

This is a shipping method configuration error message

enter image description here

Custom module admin from restriction message

enter image description here

I expect like below image

enter image description here

I override the template vendor/magento/module-checkout/view/frontend/web/template/shipping.html to my custom module app/code/Vendor/Module/view/frontend/web/template/shipping.html

 <!-- ko if:  method.error_message -->
       <tr class="row row-error">
           <td class="col col-error custom" colspan="4">
              <div class="message error">
                   // here how to bind my custom module error message (restriction message) 
                    <div data-bind="text: method.error_message"></div>  
              </div>
              <span class="no-display">
                   <input type="radio" data-bind="attr: {'value' : method.method_code, 'id': 's_method_' + method.method_code}"/>
              </span>
           </td>
         </tr>
 <!-- /ko -->
  • Are you sure the error message come from app/code/Vendor/Module/view/frontend/web/template/shipping.html ? – Ranganathan Dec 6 '19 at 7:01
  • Ya, configuration error message from vendor/magento/module-checkout/view/frontend/web/template/shipping.html – divya sekar Dec 6 '19 at 7:05
  • backend configuration error message shown on frontend prnt.sc/q6yu6r – divya sekar Dec 6 '19 at 7:15
0

app/code/Vendor/Module/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Checkout\Model\CompositeConfigProvider">
        <arguments>
            <argument name="configProviders" xsi:type="array">
                <item name="additional_provider" xsi:type="object">Vendor\Module\Model\AdditionalConfigProvider</item>
            </argument>
        </arguments>
    </type>
</config>

Vendor\Module\Model\AdditionalConfigProvider.php

<?php

namespace Vendor\Model\Model;

class AdditionalConfigProvider implements \Magento\Checkout\Model\ConfigProviderInterface
{
    protected $scopeConfig;
    public function __construct(
      \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
    ) {
      $this->scopeConfig = $scopeConfig;
    }

    /**
     * add array to checkoutconfig
     */
    public function getConfig()
    {
        $output['shipping_error_msg'] = $this->scopeConfig->getValue('yoursection/yourgroup/yourfield', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
        return $output;
    }
}

Now you can get your custom error message in ko js files. So you need to overide \vendor\magento\module-checkout\view\frontend\web\js\view\shipping.js file and add below function

customError: function (step) {
    return window.checkoutConfig.shipping_error_msg;
},

Call this customError in shipping.html as below

<!-- ko if:  method.error_message -->
       <tr class="row row-error">
           <td class="col col-error custom" colspan="4">
              <div class="message error">
                   // here how to bind my custom module error message (restriction message) 
                    <div data-bind="text: customError()"></div>  
              </div>
              <span class="no-display">
                   <input type="radio" data-bind="attr: {'value' : method.method_code, 'id': 's_method_' + method.method_code}"/>
              </span>
           </td>
         </tr>
 <!-- /ko -->
|improve this answer|||||

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.