Esempio n. 1
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;
 }
Esempio n. 2
0
 /**
  * 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;
 }