/** * @inheritdoc */ public function getList(array $numbers, Struct\ProductContextInterface $context) { $products = $this->productGateway->getList($numbers, $context); $covers = $this->mediaService->getCovers($products, $context); $graduatedPrices = $this->graduatedPricesService->getList($products, $context); $cheapestPrices = $this->cheapestPriceService->getList($products, $context); $voteAverages = $this->voteService->getAverages($products, $context); $result = []; foreach ($numbers as $number) { if (!array_key_exists($number, $products)) { continue; } $product = $products[$number]; if (isset($covers[$number])) { $product->setCover($covers[$number]); } if (isset($graduatedPrices[$number])) { $product->setPriceRules($graduatedPrices[$number]); } if (isset($cheapestPrices[$number])) { $product->setCheapestPriceRule($cheapestPrices[$number]); } if (isset($voteAverages[$number])) { $product->setVoteAverage($voteAverages[$number]); } $product->addAttribute('marketing', $this->marketingService->getProductAttribute($product)); $this->priceCalculationService->calculateProduct($product, $context); if ($this->isProductValid($product, $context)) { $result[$number] = $product; } } return $result; }
/** * @param Struct\ListProduct[] $listProducts * @param Struct\ProductContextInterface $context * @return Struct\Product[] indexed by order number */ private function createFromListProducts(array $listProducts, Struct\ProductContextInterface $context) { $votes = $this->voteService->getList($listProducts, $context); $relatedProducts = $this->relatedProductsService->getList($listProducts, $context); $relatedProductStreams = $this->relatedProductStreamsService->getList($listProducts, $context); $similarProducts = $this->similarProductsService->getList($listProducts, $context); $downloads = $this->downloadService->getList($listProducts, $context); $links = $this->linkService->getList($listProducts, $context); $media = $this->mediaService->getProductsMedia($listProducts, $context); $properties = $this->propertyService->getList($listProducts, $context); $configuration = $this->configuratorService->getProductsConfigurations($listProducts, $context); $products = []; foreach ($listProducts as $listProduct) { $number = $listProduct->getNumber(); $product = Struct\Product::createFromListProduct($listProduct); if (isset($relatedProducts[$number])) { $product->setRelatedProducts($relatedProducts[$number]); } if (isset($relatedProductStreams[$number])) { $product->setRelatedProductStreams($relatedProductStreams[$number]); } if (isset($similarProducts[$number])) { $product->setSimilarProducts($similarProducts[$number]); } if (isset($votes[$number])) { $product->setVotes($votes[$number]); } if (isset($downloads[$number])) { $product->setDownloads($downloads[$number]); } if (isset($links[$number])) { $product->setLinks($links[$number]); } if (isset($media[$number])) { $product->setMedia($media[$number]); } if (isset($properties[$number])) { $product->setPropertySet($properties[$number]); } if (isset($configuration[$number])) { $product->setConfiguration($configuration[$number]); } $products[$number] = $product; } return $products; }
/** * {@inheritdoc} */ public function get(Shop $shop, $numbers) { $context = $this->contextService->createProductContext($shop->getId(), null, ContextService::FALLBACK_CUSTOMER_GROUP); $products = $this->productGateway->getList($numbers, $context); $average = $this->voteService->getAverages($products, $context); $cheapest = $this->getCheapestPrices($products, $shop->getId()); $calculated = $this->getCalculatedPrices($shop, $products, $cheapest); $categories = $this->getCategories($products); $properties = $this->getProperties($products, $context); $result = []; foreach ($products as $listProduct) { $product = Product::createFromListProduct($listProduct); $number = $product->getNumber(); $id = $product->getId(); if (!$product->isMainVariant()) { continue; } if (isset($average[$number])) { $product->setVoteAverage($average[$number]); } if (isset($calculated[$number])) { $product->setCalculatedPrices($calculated[$number]); } if (isset($categories[$id])) { $product->setCategoryIds($categories[$id]); } if (isset($properties[$id])) { $product->setProperties($properties[$id]); } $product->setFormattedCreatedAt($this->formatDate($product->getCreatedAt())); $product->setFormattedReleaseDate($this->formatDate($product->getReleaseDate())); $product->setCreatedAt(null); $product->setReleaseDate(null); $product->setPrices(null); $product->setPriceRules(null); $product->setCheapestPriceRule(null); $product->setCheapestPrice(null); $product->setCheapestUnitPrice(null); $product->resetStates(); if (!$this->isValid($shop, $product)) { continue; } $result[$number] = $product; } return $result; }