products !== null) { return $this->products; } $skus = $this->getConfiguredSkus(); if (!$skus) { return $this->products = []; } $collection = $this->productCollectionFactory->create(); $collection->setStoreId((int) $this->_storeManager->getStore()->getId()); $this->_addProductAttributesAndPrices($collection); $collection->addAttributeToSelect([self::FEATURE_ATTRIBUTE, self::GALLERY_ATTRIBUTE]); $collection->addStoreFilter(); $collection->addAttributeToFilter('sku', ['in' => $skus]); $collection->addAttributeToFilter( 'visibility', ['in' => $this->productVisibility->getVisibleInSiteIds()] ); $collection->addAttributeToFilter( 'status', Product\Attribute\Source\Status::STATUS_ENABLED ); $productsBySku = []; foreach ($collection as $product) { $productsBySku[strtolower((string) $product->getSku())] = $product; } $this->products = []; foreach ($skus as $sku) { $key = strtolower($sku); if (isset($productsBySku[$key])) { $this->products[] = $productsBySku[$key]; } } return $this->products; } public function getFeatureContent(Product $product): string { return $this->filterContent((string) $product->getData(self::FEATURE_ATTRIBUTE)); } public function getGalleryContent(Product $product): string { return $this->filterContent((string) $product->getData(self::GALLERY_ATTRIBUTE)); } public function getIdentities(): array { $identities = []; foreach ($this->getProducts() as $product) { $identities = array_merge($identities, $product->getIdentities()); } return array_values(array_unique($identities)); } private function getConfiguredSkus(): array { $value = (string) $this->_scopeConfig->getValue( self::XML_PATH_SKUS, ScopeInterface::SCOPE_STORE ); $skus = preg_split('/[\s,;]+/', $value, -1, PREG_SPLIT_NO_EMPTY) ?: []; return array_values(array_unique(array_map('trim', $skus))); } private function filterContent(string $content): string { if (trim($content) === '') { return ''; } return $this->filterProvider->getPageFilter()->filter($content); } }