How to override UPS shipping Carrier in magento 2

by Sarvesh Tiwari   Last Updated May 16, 2019 05:09 AM

I am trying to override UPS shipping Carrier. But it is not override.

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\Ups\Model\Carrier" type="Sarvesh\Tiwari\Model\Carrier" />    
</config>

Sarvesh/Tiwari/Model/Carrier

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

namespace Sarvesh\Tiwari\Model;

use Magento\Quote\Model\Quote\Address\RateResult\Error;
use Magento\Quote\Model\Quote\Address\RateRequest;
use Magento\Shipping\Model\Carrier\AbstractCarrierOnline;
use Magento\Shipping\Model\Carrier\CarrierInterface;
use Magento\Shipping\Model\Rate\Result;
use Magento\Shipping\Model\Simplexml\Element;
use Magento\Ups\Helper\Config;
use Magento\Framework\Xml\Security;

/**
 * UPS shipping implementation
 * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
 */
class Carrier extends \Magento\Ups\Model\Carrier
{
    public function collectRates(RateRequest $request)
{
    $this->setRequest($request);
    if (!$this->canCollectRates()) {
        return $this->getErrorMessage();
    }

    $this->setRequest($request);
    $this->_result = $this->_getQuotes();
    $this->_updateFreeMethodQuote($request);
   return $this->getResult();
}
}

but its not working anyone can help



Related Questions


Updated February 02, 2018 20:09 PM

Updated July 08, 2015 13:04 PM

Updated October 08, 2016 09:03 AM

Updated January 05, 2018 12:09 PM

Updated March 01, 2017 10:09 AM