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

2
  • why you need to set CarrierTitle and CarrierTitle bank? – Amit Bera Jun 7 '19 at 7:15
  • In case of free shipping I want to hide CarrierTitle and CarrierTitle & instead of $0.00 i want to change text to Free Shipping. – Arjun Jun 7 '19 at 7:17
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 '19 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. – Dhiren Vasoya Jun 7 '19 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 '19 at 11:19
  • if you have new question then ask seprately, so other can also reply you. hope you understand. – Dhiren Vasoya Jun 7 '19 at 11:34

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.