We are running CE 2.1.2

Magento 2 sets the residential flag in the rates to request based on the configuration data. This means that all quotes are either residential or commercial, depending on what you set in the shipping method.

I want to set the flag based on if the Destination Address has a Company set or not.

What I did is go into /vendor/magento/module-fedex/Model/carrier.php and change line 430 from

'Residential' => (bool)$this->getConfigData('residence_delivery'),


'Residential' => !empty(trim($r->getRecipientContactCompanyName())),

The is not working. Residential is false always. So empty must be returning true always.

Is the getRecipientContactCompanyName() not the right way to get the Company name in this module? Any hints as to what I am doing wrong would be appreciated.

2 Answers 2


The problem is that $r is not an instance of RateRequest, it's a plain DataObject that is created in the setRequest method. You need to add

if ($request->getRecipientContactCompanyName()) {

to the setRequest method before $this->setRawRequest($r);.

You should not alter the core files, instead you should override the class in a module, otherwise your changes may be lost when updating Magento.


At the point in the code that you are building the $r object, the $request array does not contain RecepientContactCompanyName, so getRecipientContactCompanyName() will always return FALSE.

Try pulling the Company Name from the session:


I have this working in for FedEx (show Ground for commercial, Home Delivery for residential) using the following code:

In app/code/local/Mage/Usa/Model/Shipping/Carrier/Fedex.php

public function setRequest(Mage_Shipping_Model_Rate_Request $request) {
    if (Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getCompany()) {
    } else {

protected function _formRateRequest($purpose)   {
'Recipient' => array(
    'Address' => array(
        'PostalCode'  => $r->getDestPostal(),
        'CountryCode' => $r->getDestCountry(),
        'Residential' => $r->getIsResidential()

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.