Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GetSkuFromOrderItem.php
Go to the documentation of this file.
1 <?php
7 declare(strict_types=1);
8 
10 
16 
18 {
22  private $getSkusByProductIds;
23 
27  private $isSourceItemManagementAllowedForProductType;
28 
33  public function __construct(
34  GetSkusByProductIdsInterface $getSkusByProductIds,
35  IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType
36  ) {
37  $this->getSkusByProductIds = $getSkusByProductIds;
38  $this->isSourceItemManagementAllowedForProductType = $isSourceItemManagementAllowedForProductType;
39  }
40 
44  public function execute(OrderItemInterface $orderItem): string
45  {
46  try {
47  $itemSku = $orderItem->getSku();
48 
49  if ($this->isSourceItemManagementAllowedForProductType->execute($orderItem->getProductType())) {
50  $itemSku = $this->getSkusByProductIds->execute(
51  [$orderItem->getProductId()]
52  )[$orderItem->getProductId()];
53  }
54  } catch (NoSuchEntityException $e) {
55  $itemSku = $orderItem->getSku();
56  }
57 
58  return $itemSku;
59  }
60 }
$orderItem
Definition: order.php:30
__construct(GetSkusByProductIdsInterface $getSkusByProductIds, IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType)