예제 #1
0
 /**
  * @param \Magento\Sales\Model\Order\Shipment $shipment
  * @param RequestInterface $request
  * @return void
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function create(\Magento\Sales\Model\Order\Shipment $shipment, RequestInterface $request)
 {
     $order = $shipment->getOrder();
     $carrier = $this->carrierFactory->create($order->getShippingMethod(true)->getCarrierCode());
     if (!$carrier->isShippingLabelsAvailable()) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Shipping labels is not available.'));
     }
     $shipment->setPackages($request->getParam('packages'));
     $response = $this->labelFactory->create()->requestToShipment($shipment);
     if ($response->hasErrors()) {
         throw new \Magento\Framework\Exception\LocalizedException(__($response->getErrors()));
     }
     if (!$response->hasInfo()) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Response info is not exist.'));
     }
     $labelsContent = [];
     $trackingNumbers = [];
     $info = $response->getInfo();
     foreach ($info as $inf) {
         if (!empty($inf['tracking_number']) && !empty($inf['label_content'])) {
             $labelsContent[] = $inf['label_content'];
             $trackingNumbers[] = $inf['tracking_number'];
         }
     }
     $outputPdf = $this->combineLabelsPdf($labelsContent);
     $shipment->setShippingLabel($outputPdf->render());
     $carrierCode = $carrier->getCarrierCode();
     $carrierTitle = $this->scopeConfig->getValue('carriers/' . $carrierCode . '/title', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipment->getStoreId());
     if (!empty($trackingNumbers)) {
         $this->addTrackingNumbersToShipment($shipment, $trackingNumbers, $carrierCode, $carrierTitle);
     }
 }
예제 #2
0
 /**
  * @param string $code
  * @return \Magento\Framework\Phrase|string|bool
  */
 public function getCarrierTitle($code)
 {
     $carrier = $this->_carrierFactory->create($code);
     if ($carrier) {
         return $carrier->getConfigData('title');
     } else {
         return __('Custom Value');
     }
     return false;
 }
예제 #3
0
 /**
  * Retrieve all system carriers
  *
  * @param   mixed $store
  * @return  array
  */
 public function getAllCarriers($store = null)
 {
     $carriers = [];
     $config = $this->_scopeConfig->getValue('carriers', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store);
     foreach (array_keys($config) as $carrierCode) {
         $model = $this->_carrierFactory->create($carrierCode, $store);
         if ($model) {
             $carriers[$carrierCode] = $model;
         }
     }
     return $carriers;
 }
예제 #4
0
 /**
  * Retrieve detail for shipment track
  *
  * @return \Magento\Framework\Phrase|string
  */
 public function getNumberDetail()
 {
     $carrierInstance = $this->_carrierFactory->create($this->getCarrierCode());
     if (!$carrierInstance) {
         $custom = [];
         $custom['title'] = $this->getTitle();
         $custom['number'] = $this->getTrackNumber();
         return $custom;
     } else {
         $carrierInstance->setStore($this->getStore());
     }
     $trackingInfo = $carrierInstance->getTrackingInfo($this->getNumber());
     if (!$trackingInfo) {
         return __('No detail for number "%1"', $this->getNumber());
     }
     return $trackingInfo;
 }
예제 #5
0
 /**
  * Return content types of package
  *
  * @return array
  */
 public function getContentTypes()
 {
     $order = $this->getShipment()->getOrder();
     $storeId = $this->getShipment()->getStoreId();
     $address = $order->getShippingAddress();
     $carrier = $this->_carrierFactory->create($order->getShippingMethod(true)->getCarrierCode());
     $countryShipper = $this->_scopeConfig->getValue(\Magento\Sales\Model\Order\Shipment::XML_PATH_STORE_COUNTRY_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
     if ($carrier) {
         $params = new \Magento\Framework\DataObject(['method' => $order->getShippingMethod(true)->getMethod(), 'country_shipper' => $countryShipper, 'country_recipient' => $address->getCountryId()]);
         return $carrier->getContentTypes($params);
     }
     return [];
 }
예제 #6
0
 /**
  * Check is carrier has functionality of creation shipping labels
  *
  * @return bool
  */
 public function canCreateShippingLabel()
 {
     $shippingCarrier = $this->_carrierFactory->create($this->getOrder()->getShippingMethod(true)->getCarrierCode());
     return $shippingCarrier && $shippingCarrier->isShippingLabelsAvailable();
 }