Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GetProductIdsBySkus.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
13 
18 {
22  private $productResource;
23 
27  public function __construct(
28  ProductResourceModel $productResource
29  ) {
30  $this->productResource = $productResource;
31  }
32 
36  public function execute(array $skus): array
37  {
38  $idsBySkus = $this->productResource->getProductsIdsBySkus($skus);
39  $notFoundedSkus = array_diff($skus, array_keys($idsBySkus));
40 
41  if (!empty($notFoundedSkus)) {
42  throw new NoSuchEntityException(
43  __('Following products with requested skus were not found: %1', implode($notFoundedSkus, ', '))
44  );
45  }
46 
47  return $idsBySkus;
48  }
49 }
__construct(ProductResourceModel $productResource)
__()
Definition: __.php:13
foreach($websiteCodes as $websiteCode) $skus