1

I'm trying to overwrite the function setRequest in /vendor/magento/module-usps/Model/Carrier.php to request "Online" rates from USPS.

My complete module code is below.

My module is enabled. I cleared var/di and var/generation. I ran the code compiler.

I viewed my store in frontend, added an item to my cart and clicked view & edit cart. The resulting page is white and only has the text "Estimate Shipping and Tax".

The system log is full of messages that say "Cache file with merged layout" or "Broken reference".

Thanks!

app/code/RSEI/improvedUSPS/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\Usps\Model\Carrier" type="RSEI\ImprovedUSPS\Model\Rewrite\Usps\Carrier" />
</config>

app/code/RSEI/improvedUSPS/etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="RSEI_improvedUSPS" setup_version="2.0.0"/>
</config>

app/code/RSEI/improvedUSPS/registration.php

  <?php
  \Magento\Framework\Component\ComponentRegistrar::register(
  \Magento\Framework\Component\ComponentRegistrar::MODULE,
  'RSEI_improvedUSPS',
  __DIR__
  );

app/code/RSEI/improvedUSPS/Model/Rewrite/Usps

<?php
namespace RSEI\ImprovedUSPS\Model\Rewrite\Usps;


class Carrier extends \Magento\Usps\Model\Carrier
{

 public function setRequest(\Magento\Quote\Model\Quote\Address\RateRequest $request)
    {
$this->_request = $request;

    $r = new \Magento\Framework\DataObject();

    if ($request->getLimitMethod()) {
        $r->setService($request->getLimitMethod());
    } else {
        $r->setService('ONLINE');
    }

    if ($request->getUspsUserid()) {
        $userId = $request->getUspsUserid();
    } else {
        $userId = $this->getConfigData('userid');
    }
    $r->setUserId($userId);

    if ($request->getUspsContainer()) {
        $container = $request->getUspsContainer();
    } else {
        $container = $this->getConfigData('container');
    }
    $r->setContainer($container);

    if ($request->getUspsSize()) {
        $size = $request->getUspsSize();
    } else {
        $size = $this->getConfigData('size');
    }
    $r->setSize($size);

    if ($request->getGirth()) {
        $girth = $request->getGirth();
    } else {
        $girth = $this->getConfigData('girth');
    }
    $r->setGirth($girth);

    if ($request->getHeight()) {
        $height = $request->getHeight();
    } else {
        $height = $this->getConfigData('height');
    }
    $r->setHeight($height);

    if ($request->getLength()) {
        $length = $request->getLength();
    } else {
        $length = $this->getConfigData('length');
    }
    $r->setLength($length);

    if ($request->getWidth()) {
        $width = $request->getWidth();
    } else {
        $width = $this->getConfigData('width');
    }
    $r->setWidth($width);

    if ($request->getUspsMachinable()) {
        $machinable = $request->getUspsMachinable();
    } else {
        $machinable = $this->getConfigData('machinable');
    }
    $r->setMachinable($machinable);

    if ($request->getOrigPostcode()) {
        $r->setOrigPostal($request->getOrigPostcode());
    } else {
        $r->setOrigPostal(
            $this->_scopeConfig->getValue(
                \Magento\Sales\Model\Order\Shipment::XML_PATH_STORE_ZIP,
                \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
                $request->getStoreId()
            )
        );
    }

}

}
  • did you ever get to the bottom of what caused this? – Will Wright Aug 6 at 7:47
  • Unfortunately, no. – walrus28 Aug 10 at 19:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.