Пример #1
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;
 }