예제 #1
0
 /**
  * @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;
 }
예제 #2
0
 /**
  * @param Shop $shop
  * @param ListProduct[] $products
  * @param $priceRules
  * @return array
  */
 private function getCalculatedPrices($shop, $products, $priceRules)
 {
     $currencies = $this->identifierSelector->getShopCurrencyIds($shop->getId());
     if (!$shop->isMain()) {
         $currencies = $this->identifierSelector->getShopCurrencyIds($shop->getParentId());
     }
     $customerGroups = $this->identifierSelector->getCustomerGroupKeys();
     $contexts = $this->getContexts($shop->getId(), $customerGroups, $currencies);
     $prices = [];
     foreach ($products as $product) {
         $number = $product->getNumber();
         if (!isset($priceRules[$number])) {
             continue;
         }
         $rules = $priceRules[$number];
         /**@var $context ProductContextInterface*/
         foreach ($contexts as $context) {
             $customerGroup = $context->getCurrentCustomerGroup()->getKey();
             $key = $customerGroup . '_' . $context->getCurrency()->getId();
             $product->setCheapestPriceRule($rules[$customerGroup]);
             $this->priceCalculationService->calculateProduct($product, $context);
             if ($product->getCheapestPrice()) {
                 $prices[$number][$key] = $product->getCheapestPrice();
             }
         }
     }
     return $prices;
 }