Example #1
0
 /**
  * Set recipient details into request
  * @param \Magento\Shipping\Model\Shipment\Request $request
  * @param \Magento\Sales\Model\Order\Address $address
  * @return void
  */
 protected function setRecipientDetails(Request $request, Address $address)
 {
     $request->setRecipientContactPersonName(trim($address->getFirstname() . ' ' . $address->getLastname()));
     $request->setRecipientContactPersonFirstName($address->getFirstname());
     $request->setRecipientContactPersonLastName($address->getLastname());
     $request->setRecipientContactCompanyName($address->getCompany());
     $request->setRecipientContactPhoneNumber($address->getTelephone());
     $request->setRecipientEmail($address->getEmail());
     $request->setRecipientAddressStreet(trim($address->getStreetLine(1) . ' ' . $address->getStreetLine(2)));
     $request->setRecipientAddressStreet1($address->getStreetLine(1));
     $request->setRecipientAddressStreet2($address->getStreetLine(2));
     $request->setRecipientAddressCity($address->getCity());
     $request->setRecipientAddressStateOrProvinceCode($address->getRegionCode() ?: $address->getRegion());
     $request->setRecipientAddressRegionCode($address->getRegionCode());
     $request->setRecipientAddressPostalCode($address->getPostcode());
     $request->setRecipientAddressCountryCode($address->getCountryId());
 }
Example #2
0
 /**
  * Do request to shipment
  *
  * @param \Magento\Shipping\Model\Shipment\Request $request
  * @return array|\Magento\Framework\Object
  * @throws \Magento\Framework\Model\Exception
  */
 public function requestToShipment($request)
 {
     $packages = $request->getPackages();
     if (!is_array($packages) || !$packages) {
         throw new \Magento\Framework\Model\Exception(__('No packages for request'));
     }
     $result = $this->_doShipmentRequest($request);
     $response = new \Magento\Framework\Object(array('info' => array(array('tracking_number' => $result->getTrackingNumber(), 'label_content' => $result->getShippingLabelContent()))));
     $request->setMasterTrackingId($result->getTrackingNumber());
     return $response;
 }
 /**
  * Do request to RMA shipment
  *
  * @param Request $request
  * @return \Magento\Framework\Object
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function returnOfShipment($request)
 {
     $request->setIsReturn(true);
     $packages = $request->getPackages();
     if (!is_array($packages) || !$packages) {
         throw new LocalizedException(__('No packages for request'));
     }
     if ($request->getStoreId() != null) {
         $this->setStore($request->getStoreId());
     }
     $data = [];
     foreach ($packages as $packageId => $package) {
         $request->setPackageId($packageId);
         $request->setPackagingType($package['params']['container']);
         $request->setPackageWeight($package['params']['weight']);
         $request->setPackageParams(new \Magento\Framework\Object($package['params']));
         $request->setPackageItems($package['items']);
         $result = $this->_doShipmentRequest($request);
         if ($result->hasErrors()) {
             $this->rollBack($data);
             break;
         } else {
             $data[] = ['tracking_number' => $result->getTrackingNumber(), 'label_content' => $result->getShippingLabelContent()];
         }
         if (!isset($isFirstRequest)) {
             $request->setMasterTrackingId($result->getTrackingNumber());
             $isFirstRequest = false;
         }
     }
     $response = new \Magento\Framework\Object(['info' => $data]);
     if ($result->getErrors()) {
         $response->setErrors($result->getErrors());
     }
     return $response;
 }