Пример #1
0
 /**
  * Prepare and set request to this instance
  *
  * @param RateRequest $request
  * @return $this
  */
 public function setRequest(RateRequest $request)
 {
     $this->_request = $request;
     $rowRequest = new \Magento\Framework\Object();
     if ($request->getLimitMethod()) {
         $rowRequest->setAction($this->configHelper->getCode('action', 'single'));
         $rowRequest->setProduct($request->getLimitMethod());
     } else {
         $rowRequest->setAction($this->configHelper->getCode('action', 'all'));
         $rowRequest->setProduct('GND' . $this->getConfigData('dest_type'));
     }
     if ($request->getUpsPickup()) {
         $pickup = $request->getUpsPickup();
     } else {
         $pickup = $this->getConfigData('pickup');
     }
     $rowRequest->setPickup($this->configHelper->getCode('pickup', $pickup));
     if ($request->getUpsContainer()) {
         $container = $request->getUpsContainer();
     } else {
         $container = $this->getConfigData('container');
     }
     $rowRequest->setContainer($this->configHelper->getCode('container', $container));
     if ($request->getUpsDestType()) {
         $destType = $request->getUpsDestType();
     } else {
         $destType = $this->getConfigData('dest_type');
     }
     $rowRequest->setDestType($this->configHelper->getCode('dest_type', $destType));
     if ($request->getOrigCountry()) {
         $origCountry = $request->getOrigCountry();
     } else {
         $origCountry = $this->_scopeConfig->getValue(\Magento\Sales\Model\Order\Shipment::XML_PATH_STORE_COUNTRY_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $request->getStoreId());
     }
     $rowRequest->setOrigCountry($this->_countryFactory->create()->load($origCountry)->getIso2Code());
     if ($request->getOrigRegionCode()) {
         $origRegionCode = $request->getOrigRegionCode();
     } else {
         $origRegionCode = $this->_scopeConfig->getValue(\Magento\Sales\Model\Order\Shipment::XML_PATH_STORE_REGION_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $request->getStoreId());
     }
     if (is_numeric($origRegionCode)) {
         $origRegionCode = $this->_regionFactory->create()->load($origRegionCode)->getCode();
     }
     $rowRequest->setOrigRegionCode($origRegionCode);
     if ($request->getOrigPostcode()) {
         $rowRequest->setOrigPostal($request->getOrigPostcode());
     } else {
         $rowRequest->setOrigPostal($this->_scopeConfig->getValue(\Magento\Sales\Model\Order\Shipment::XML_PATH_STORE_ZIP, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $request->getStoreId()));
     }
     if ($request->getOrigCity()) {
         $rowRequest->setOrigCity($request->getOrigCity());
     } else {
         $rowRequest->setOrigCity($this->_scopeConfig->getValue(\Magento\Sales\Model\Order\Shipment::XML_PATH_STORE_CITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $request->getStoreId()));
     }
     if ($request->getDestCountryId()) {
         $destCountry = $request->getDestCountryId();
     } else {
         $destCountry = self::USA_COUNTRY_ID;
     }
     //for UPS, puero rico state for US will assume as puerto rico country
     if ($destCountry == self::USA_COUNTRY_ID && ($request->getDestPostcode() == '00912' || $request->getDestRegionCode() == self::PUERTORICO_COUNTRY_ID)) {
         $destCountry = self::PUERTORICO_COUNTRY_ID;
     }
     // For UPS, Guam state of the USA will be represented by Guam country
     if ($destCountry == self::USA_COUNTRY_ID && $request->getDestRegionCode() == self::GUAM_REGION_CODE) {
         $destCountry = self::GUAM_COUNTRY_ID;
     }
     $rowRequest->setDestCountry($this->_countryFactory->create()->load($destCountry)->getIso2Code());
     $rowRequest->setDestRegionCode($request->getDestRegionCode());
     if ($request->getDestPostcode()) {
         $rowRequest->setDestPostal($request->getDestPostcode());
     } else {
     }
     $weight = $this->getTotalNumOfBoxes($request->getPackageWeight());
     $weight = $this->_getCorrectWeight($weight);
     $rowRequest->setWeight($weight);
     if ($request->getFreeMethodWeight() != $request->getPackageWeight()) {
         $rowRequest->setFreeMethodWeight($request->getFreeMethodWeight());
     }
     $rowRequest->setValue($request->getPackageValue());
     $rowRequest->setValueWithDiscount($request->getPackageValueWithDiscount());
     if ($request->getUpsUnitMeasure()) {
         $unit = $request->getUpsUnitMeasure();
     } else {
         $unit = $this->getConfigData('unit_of_measure');
     }
     $rowRequest->setUnitMeasure($unit);
     $rowRequest->setIsReturn($request->getIsReturn());
     $rowRequest->setBaseSubtotalInclTax($request->getBaseSubtotalInclTax());
     $this->_rawRequest = $rowRequest;
     return $this;
 }