Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GetSkusByProductIds.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
14 
19 {
23  private $productResource;
24 
28  public function __construct(
29  ProductResourceModel $productResource
30  ) {
31  $this->productResource = $productResource;
32  }
33 
37  public function execute(array $productIds): array
38  {
39  $skuByIds = array_column(
40  $this->productResource->getProductsSku($productIds),
42  'entity_id'
43  );
44  $notFoundedIds = array_diff($productIds, array_keys($skuByIds));
45 
46  if (!empty($notFoundedIds)) {
47  throw new NoSuchEntityException(
48  __('Following products with requested ids were not found: %1', implode($notFoundedIds, ', '))
49  );
50  }
51 
52  $skuByIds = array_map('strval', $skuByIds);
53  return $skuByIds;
54  }
55 }
__()
Definition: __.php:13
__construct(ProductResourceModel $productResource)