54 \
Magento\Directory\Model\RegionFactory $regionFactory,
57 \
Magento\Backend\Model\Auth\Session $authSession,
60 $this->_authSession = $authSession;
68 $shipmentRequestFactory,
84 public function requestToShipment(
Shipment $orderShipment)
86 $admin = $this->_authSession->getUser();
90 $shipmentStoreId = $orderShipment->
getStoreId();
91 $shipmentCarrier = $this->_carrierFactory->create(
$order->getShippingMethod(
true)->getCarrierCode());
92 $baseCurrencyCode = $this->_storeManager->getStore($shipmentStoreId)->getBaseCurrencyCode();
93 if (!$shipmentCarrier) {
95 __(
'The "%1" carrier is invalid. Verify and try again.',
$shippingMethod->getCarrierCode())
98 $shipperRegionCode = $this->_scopeConfig->getValue(
100 ScopeInterface::SCOPE_STORE,
103 if (is_numeric($shipperRegionCode)) {
104 $shipperRegionCode = $this->_regionFactory->create()->load($shipperRegionCode)->getCode();
107 $originStreet1 = $this->_scopeConfig->getValue(
109 ScopeInterface::SCOPE_STORE,
112 $storeInfo =
new DataObject(
113 (array)$this->_scopeConfig->getValue(
114 'general/store_information',
115 ScopeInterface::SCOPE_STORE,
120 if (!$admin->getFirstName()
121 || !$admin->getLastName()
122 || !$storeInfo->getName()
123 || !$storeInfo->getPhone()
125 || !$this->_scopeConfig->getValue(
127 ScopeInterface::SCOPE_STORE,
130 || !$this->_scopeConfig->getValue(
132 ScopeInterface::SCOPE_STORE,
135 || !$this->_scopeConfig->getValue(
137 ScopeInterface::SCOPE_STORE,
141 throw new LocalizedException(
143 "Shipping labels can't be created. " 144 .
"Verify that the store information and settings are complete and try again." 150 $request = $this->_shipmentRequestFactory->create();
151 $request->setOrderShipment($orderShipment);
160 $request->setBaseCurrencyCode($baseCurrencyCode);
161 $request->setStoreId($shipmentStoreId);
163 return $shipmentCarrier->requestToShipment(
$request);
184 $originStreet2 = $this->_scopeConfig->getValue(
186 ScopeInterface::SCOPE_STORE,
196 $request->setShipperAddressStreet(trim($originStreet .
' ' . $originStreet2));
197 $request->setShipperAddressStreet1($originStreet);
198 $request->setShipperAddressStreet2($originStreet2);
200 $this->_scopeConfig->getValue(
202 ScopeInterface::SCOPE_STORE,
206 $request->setShipperAddressStateOrProvinceCode($regionCode);
207 $request->setShipperAddressPostalCode(
208 $this->_scopeConfig->getValue(
210 ScopeInterface::SCOPE_STORE,
214 $request->setShipperAddressCountryCode(
215 $this->_scopeConfig->getValue(
217 ScopeInterface::SCOPE_STORE,
setShipperDetails(Request $request, User $storeAdmin, DataObject $store, $shipmentStoreId, $regionCode, $originStreet)
const XML_PATH_STORE_COUNTRY_ID
const XML_PATH_STORE_REGION_ID
const XML_PATH_STORE_CITY
__construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Shipping\Model\Config $shippingConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Shipping\Model\CarrierFactory $carrierFactory, \Magento\Shipping\Model\Rate\ResultFactory $rateResultFactory, \Magento\Shipping\Model\Shipment\RequestFactory $shipmentRequestFactory, \Magento\Directory\Model\RegionFactory $regionFactory, \Magento\Framework\Math\Division $mathDivision, \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry, \Magento\Backend\Model\Auth\Session $authSession, Request $request)
const XML_PATH_STORE_ADDRESS1
const XML_PATH_STORE_ADDRESS2
setRecipientDetails(Request $request, Address $address)