1

How can i override vendor/magento/module-offline-shipping/Model/Carrier/Flatrate.php file as i need to add

 if($request->getSubtotalIncludingTax() > 25){
         return false;
    }

code so that if my cart value is > 25 then hide flatrate shipping method

Inside function collectRates(RateRequest $request)

1

etc\di.xml

     <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
        <type name="Magento\OfflineShipping\Model\Carrier\Flatrate">
    <plugin name="Vendor_Module_Plugin" type="Vendor\Module\Plugin\OfflinePlugin" sortOrder="10" disabled="false"  />
</type>

Vendor\Module\Plugin\OfflinePlugin.php

     <?php

        namespace Vendor\Module\Plugin;

        class OfflinePlugin
        {

           public function 
           aftercollectRates(\Magento\OfflineShipping\Model\Carrier\Flatrate $subject, $result)
          {

           //set your logic here

           }

}

Note: Don't use preference as per magento coding standard

1

You Can Override File And Change As Per Your Requirment :-

etc/di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">    
    <preference for="Magento\OfflineShipping\Model\Carrier\Flatrate" type="Namespace\Module\Model\OfflineShipping\Carrier\Override\FlatrateOverride" />
</config>
1

In order to override, you just need to add Flatrate.php in your custom module

Path should be like: app/code/Yourpackage/Yourmodule/Model/Carrier/Flatrate.php

Add whatever you want in above path file

if($request->getSubtotalIncludingTax() > 25){
         return false;
}

You need to add di.xml in your module

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">    
    <preference for="Magento\OfflineShipping\Model\Carrier\Flatrate" type="Yourpackage\Yourmodule\Model\Carrier\Flatrate" />
</config>

I hope this will help

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.