/** * @inheritdoc */ public function getList($products, Struct\ProductContextInterface $context) { $group = $context->getCurrentCustomerGroup(); $specify = $this->graduatedPricesGateway->getList($products, $group); //iterates the passed prices and products and assign the product unit to the prices and the passed customer group $prices = $this->buildPrices($products, $specify, $group); //check if one of the products have no assigned price within the prices variable. $fallbackProducts = array_filter($products, function (Struct\ListProduct $product) use($prices) { return !array_key_exists($product->getNumber(), $prices); }); if (!empty($fallbackProducts)) { //if some product has no price, we have to load the fallback customer group prices for the fallbackProducts. $fallbackPrices = $this->graduatedPricesGateway->getList($fallbackProducts, $context->getFallbackCustomerGroup()); $fallbackPrices = $this->buildPrices($fallbackProducts, $fallbackPrices, $context->getFallbackCustomerGroup()); $prices = $prices + $fallbackPrices; } $priceGroups = $context->getPriceGroups(); /** * If one of the products has a configured price group, * the graduated prices has to be build over the defined price group graduations. * * The price group discounts are defined with a percentage discount, which calculated * on the first graduated price of the product. */ foreach ($products as $product) { if (!$product->isPriceGroupActive() || !$product->getPriceGroup()) { continue; } if (!isset($prices[$product->getNumber()])) { continue; } $priceGroupId = $product->getPriceGroup()->getId(); if (!isset($priceGroups[$priceGroupId])) { continue; } $priceGroup = $priceGroups[$priceGroupId]; $firstGraduation = array_shift($prices[$product->getNumber()]); $prices[$product->getNumber()] = $this->buildDiscountGraduations($firstGraduation, $context->getCurrentCustomerGroup(), $priceGroup->getDiscounts()); } return $prices; }
/** * @inheritdoc */ public function getSelection(Struct\ProductContextInterface $context) { $fallback = $context->getFallbackCustomerGroup(); $current = $context->getCurrentCustomerGroup(); $currency = $context->getCurrency(); $priceField = 'defaultPrice.price'; if ($fallback->getId() != $current->getId()) { $priceField = 'IFNULL(customerPrice.price, defaultPrice.price)'; } $discount = $current->useDiscount() ? $current->getPercentageDiscount() : 0; $considerMinPurchase = $this->config->get('calculateCheapestPriceWithMinPurchase'); $taxCase = $this->buildTaxCase($context); //rounded to filter this value correctly // => 2,99999999 displayed as 3,- € but won't be displayed with a filter on price >= 3,- € return 'ROUND(' . $priceField . ($considerMinPurchase ? ' * availableVariant.minpurchase' : '') . ' * ((100 - IFNULL(priceGroup.discount, 0)) / 100)' . ($current->displayGrossPrices() ? " * (( " . $taxCase . " + 100) / 100)" : '') . ($discount ? " * " . (100 - (double) $discount) / 100 : '') . ($currency->getFactor() ? " * " . $currency->getFactor() : '') . ', 2)'; }