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->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 getBackgroundImageUrl(): string { $image = ltrim(trim((string) $this->getConfig('background_image')), '/'); if ($image === '') { return ''; } return $this->_storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA) . self::BACKGROUND_MEDIA_PATH . $image; } public function getExploreAllUrl(): string { return trim((string) $this->getConfig('explore_all_url')); } public function getFormattedFinalPrice(Product $product): string { return $this->formatPrice($this->getFinalPriceValue($product)); } public function getFormattedRegularPrice(Product $product): string { return $this->formatPrice($this->getRegularPriceValue($product)); } public function hasRegularPrice(Product $product): bool { return $this->getRegularPriceValue($product) > $this->getFinalPriceValue($product); } public function getCacheKeyInfo(): array { return [ 'ESUN_HOMEPAGE_ACCESSORIES', (int) $this->_storeManager->getStore()->getId(), (int) $this->httpContext->getValue(CustomerContext::CONTEXT_GROUP), sha1(implode('|', $this->getConfiguredSkus())), sha1($this->getBackgroundImageUrl()), sha1($this->getExploreAllUrl()), ]; } 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->getConfig('skus'); $skus = preg_split('/[\s,;]+/', $value, -1, PREG_SPLIT_NO_EMPTY) ?: []; return array_values(array_unique(array_map('trim', $skus))); } private function getConfig(string $field): mixed { return $this->_scopeConfig->getValue( self::XML_PATH . $field, ScopeInterface::SCOPE_STORE ); } private function getFinalPriceValue(Product $product): float { return $this->cardPriceResolver->getFinalPrice($product); } private function getRegularPriceValue(Product $product): float { return $this->cardPriceResolver->getRegularPrice($product); } private function formatPrice(float $price): string { return $this->priceCurrency->format( $price, false, PriceCurrencyInterface::DEFAULT_PRECISION, $this->_storeManager->getStore() ); } }