Esempio n. 1
1
 /**
  * Prepare and set request to this instance
  *
  * @param RateRequest $request
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function setRequest(RateRequest $request)
 {
     $this->_request = $request;
     $r = new \Magento\Framework\DataObject();
     if ($request->getLimitMethod()) {
         $r->setService($request->getLimitMethod());
     }
     if ($request->getFedexAccount()) {
         $account = $request->getFedexAccount();
     } else {
         $account = $this->getConfigData('account');
     }
     $r->setAccount($account);
     if ($request->getFedexDropoff()) {
         $dropoff = $request->getFedexDropoff();
     } else {
         $dropoff = $this->getConfigData('dropoff');
     }
     $r->setDropoffType($dropoff);
     if ($request->getFedexPackaging()) {
         $packaging = $request->getFedexPackaging();
     } else {
         $packaging = $this->getConfigData('packaging');
     }
     $r->setPackaging($packaging);
     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());
     }
     $r->setOrigCountry($this->_countryFactory->create()->load($origCountry)->getData('iso2_code'));
     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->getDestCountryId()) {
         $destCountry = $request->getDestCountryId();
     } else {
         $destCountry = self::USA_COUNTRY_ID;
     }
     $r->setDestCountry($this->_countryFactory->create()->load($destCountry)->getData('iso2_code'));
     if ($request->getDestPostcode()) {
         $r->setDestPostal($request->getDestPostcode());
     } else {
     }
     $weight = $this->getTotalNumOfBoxes($request->getPackageWeight());
     $r->setWeight($weight);
     if ($request->getFreeMethodWeight() != $request->getPackageWeight()) {
         $r->setFreeMethodWeight($request->getFreeMethodWeight());
     }
     $r->setValue($request->getPackagePhysicalValue());
     $r->setValueWithDiscount($request->getPackageValueWithDiscount());
     $r->setMeterNumber($this->getConfigData('meter_number'));
     $r->setKey($this->getConfigData('key'));
     $r->setPassword($this->getConfigData('password'));
     $r->setIsReturn($request->getIsReturn());
     $r->setBaseSubtotalInclTax($request->getBaseSubtotalInclTax());
     $this->setRawRequest($r);
     return $this;
 }
Esempio n. 2
0
 /**
  * Prepare and set request to this instance
  *
  * @param RateRequest $request
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function setRequest(RateRequest $request)
 {
     $this->_request = $request;
     $rowRequest = new \Magento\Framework\DataObject();
     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)->getData('iso2_code'));
     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)->getData('iso2_code'));
     $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;
 }