72 $carrier = $this->carrierFactory->create(
$order->getShippingMethod(
true)->getCarrierCode());
73 if (!$carrier->isShippingLabelsAvailable()) {
74 throw new \Magento\Framework\Exception\LocalizedException(
__(
'Shipping labels is not available.'));
79 throw new \Magento\Framework\Exception\LocalizedException(
__(
$response->getErrors()));
82 throw new \Magento\Framework\Exception\LocalizedException(
__(
'Response info is not exist.'));
85 $trackingNumbers = [];
87 foreach (
$info as $inf) {
88 if (!empty($inf[
'tracking_number']) && !empty($inf[
'label_content'])) {
89 $labelsContent[] = $inf[
'label_content'];
90 $trackingNumbers[] = $inf[
'tracking_number'];
94 $shipment->setShippingLabel($outputPdf->render());
95 $carrierCode = $carrier->getCarrierCode();
96 $carrierTitle = $this->scopeConfig->getValue(
97 'carriers/' . $carrierCode .
'/title',
101 if (!empty($trackingNumbers)) {
102 $this->addTrackingNumbersToShipment(
$shipment, $trackingNumbers, $carrierCode, $carrierTitle);
114 private function addTrackingNumbersToShipment(
120 foreach ($trackingNumbers as
$number) {
122 $this->addTrackingNumbersToShipment(
$shipment,
$number, $carrierCode, $carrierTitle);
125 $this->trackFactory->create()
127 ->setCarrierCode($carrierCode)
128 ->setTitle($carrierTitle)
142 $outputPdf = new \Zend_Pdf();
143 foreach ($labelsContent as
$content) {
144 if (stripos(
$content,
'%PDF-') !==
false) {
146 foreach ($pdfLabel->pages as
$page) {
147 $outputPdf->pages[] = clone
$page;
152 $outputPdf->pages[] =
$page;
165 public function createPdfPageFromImageString($imageString)
168 $directory = $this->filesystem->getDirectoryWrite(
171 $directory->create();
172 $image = @imagecreatefromstring($imageString);
179 $page = new \Zend_Pdf_Page($xSize, $ySize);
181 imageinterlace(
$image, 0);
182 $tmpFileName = $directory->getAbsolutePath(
183 'shipping_labels_' . uniqid(\
Magento\Framework\Math\Random::getRandomNumber()) .
time() .
'.png' 185 imagepng(
$image, $tmpFileName);
187 $page->drawImage($pdfImage, 0, 0, $xSize, $ySize);
188 $directory->delete($directory->getRelativePath($tmpFileName));
create(\Magento\Sales\Model\Order\Shipment $shipment, RequestInterface $request)
combineLabelsPdf(array $labelsContent)
static parse(&$source=null, $revision=null)
static imageWithPath($filePath)
__construct(\Magento\Shipping\Model\CarrierFactory $carrierFactory, \Magento\Shipping\Model\Shipping\LabelsFactory $labelFactory, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Sales\Model\Order\Shipment\TrackFactory $trackFactory, \Magento\Framework\Filesystem $filesystem)
foreach( $_productCollection as $_product)() ?>" class $info
foreach($order->getItems() as $orderItem) $shipment