Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InvalidSkuProcessor.php
Go to the documentation of this file.
1 <?php
8 
13 {
18  public function __construct(
19  \Magento\Catalog\Model\ProductIdLocatorInterface $productIdLocator,
21  ) {
22  $this->productIdLocator = $productIdLocator;
23  $this->productRepository = $productRepository;
24  }
25 
34  public function retrieveInvalidSkuList(array $skus, array $allowedProductTypes, $allowedPriceTypeValue = null)
35  {
36  $idsBySku = $this->productIdLocator->retrieveProductIdsBySkus($skus);
37  $existingSkus = array_keys($idsBySku);
38  $skuDiff = array_udiff(
39  $skus,
40  $existingSkus,
41  'strcasecmp'
42  );
43 
44  foreach ($idsBySku as $sku => $ids) {
45  foreach ($ids as $type) {
46  $valueTypeIsAllowed = false;
47 
48  if ($allowedPriceTypeValue
49  && $type == \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE
50  && $this->productRepository->get($sku)->getPriceType() != $allowedPriceTypeValue
51  ) {
52  $valueTypeIsAllowed = true;
53  }
54 
55  if (!in_array($type, $allowedProductTypes) || $valueTypeIsAllowed) {
56  $skuDiff[] = $sku;
57  break;
58  }
59  }
60  }
61 
62  return $skuDiff;
63  }
64 
73  public function filterSkuList(array $skus, array $allowedProductTypes, $allowedPriceTypeValue = null)
74  {
75  $failedItems = $this->retrieveInvalidSkuList($skus, $allowedProductTypes, $allowedPriceTypeValue);
76  return array_diff($skus, $failedItems);
77  }
78 }
filterSkuList(array $skus, array $allowedProductTypes, $allowedPriceTypeValue=null)
foreach($websiteCodes as $websiteCode) $skus
$type
Definition: item.phtml:13
retrieveInvalidSkuList(array $skus, array $allowedProductTypes, $allowedPriceTypeValue=null)
__construct(\Magento\Catalog\Model\ProductIdLocatorInterface $productIdLocator, \Magento\Catalog\Api\ProductRepositoryInterface $productRepository)