/** * Prepare and set request to this instance * * @param \Magento\Sales\Model\Quote\Address\RateRequest $request * @return $this */ public function setRequest(\Magento\Sales\Model\Quote\Address\RateRequest $request) { $this->_request = $request; $r = new \Magento\Framework\Object(); if ($request->getLimitMethod()) { $r->setService($request->getLimitMethod()); } else { $r->setService('ALL'); } 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())); } if ($request->getOrigCountryId()) { $r->setOrigCountryId($request->getOrigCountryId()); } else { $r->setOrigCountryId($this->_scopeConfig->getValue(\Magento\Sales\Model\Order\Shipment::XML_PATH_STORE_COUNTRY_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $request->getStoreId())); } if ($request->getDestCountryId()) { $destCountry = $request->getDestCountryId(); } else { $destCountry = self::USA_COUNTRY_ID; } $r->setDestCountryId($destCountry); if (!$this->_isUSCountry($destCountry)) { $r->setDestCountryName($this->_getCountryName($destCountry)); } if ($request->getDestPostcode()) { $r->setDestPostal($request->getDestPostcode()); } $weight = $this->getTotalNumOfBoxes($request->getPackageWeight()); $r->setWeightPounds(floor($weight)); $r->setWeightOunces(round(($weight - floor($weight)) * self::OUNCES_POUND, 1)); if ($request->getFreeMethodWeight() != $request->getPackageWeight()) { $r->setFreeMethodWeight($request->getFreeMethodWeight()); } $r->setValue($request->getPackageValue()); $r->setValueWithDiscount($request->getPackageValueWithDiscount()); $r->setBaseSubtotalInclTax($request->getBaseSubtotalInclTax()); $this->setRawRequest($r); return $this; }