1

I need to override the collectRates() function in file (\Magento\OfflineShipping\Model\Carrier\Freeshipping) file.

I want to hide CarrierTitle & MethodTitle on the checkout page so I am planning pass set blank CarrierTitle & MethodTitle for that I need to override collectRates() function

3

1 Answer 1

0

To overide that file you need to do following things.

  1. create di.xml file at following location.

app\code\Vendor\Extension\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">
 <preference for="Magento\OfflineShipping\Model\Carrier\Freeshipping" type="Vendor\Extension\Model\Carrier\Freeshipping" />
</config>
  1. now create the Freeshipping.php at following location.

app\code\Vendor\Extension\Model\Carrier\Freeshipping.php

<?php
    namespace Vendor\Extension\Model\Carrier;

    use Magento\Quote\Model\Quote\Address\RateRequest;

    class Freeshipping extends \Magento\OfflineShipping\Model\Carrier\Freeshipping
    {
        public function collectRates(RateRequest $request)
        {
            // Do your logic here
        }

    }
4
  • how can i override $method->setCarrierTitle($this->getConfigData('title'));
    – Arjun
    Jun 7, 2019 at 8:42
  • Check my answer, you have already overide entire function. so here you need to put what every you want instade of that one. Jun 7, 2019 at 10:14
  • I have used the same method which you gave but I am getting error of blank value being retuned from this getConfigData() which was defined in Magento\Shipping\Model\Carrier\AbstractCarrier file so do I need to include that 2
    – Arjun
    Jun 7, 2019 at 11:19
  • if you have new question then ask seprately, so other can also reply you. hope you understand. Jun 7, 2019 at 11:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.