Exemplo n.º 1
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;
 }
Exemplo n.º 2
0
 /**
  * @param Shop $shop
  * @return array
  */
 private function getCalculatedPricesMapping(Shop $shop)
 {
     $prices = [];
     $customerGroups = $this->identifierSelector->getCustomerGroupKeys();
     $currencies = $this->identifierSelector->getShopCurrencyIds($shop->getId());
     foreach ($currencies as $currency) {
         foreach ($customerGroups as $customerGroup) {
             $key = $customerGroup . '_' . $currency;
             $prices[$key] = $this->getPriceMapping();
         }
     }
     return ['properties' => $prices];
 }