getContextRanges($preorder); foreach ($ranges as $contexts) { $dynamicProducts = $this->contextManager->activateContexts($contexts, fn () => $from->getProducts()); foreach ($dynamicProducts as /* @var \Product $product */ $product) { if ($product instanceof \Variation) { $current = $into[$product->id]->variations[$product->variationId][$outKey] ?? []; $current[] = array_merge([], ['price' => $product->getProductPrice()]); $into[$product->id]->variations[$product->variationId][$outKey] = $current; continue; } $current = $into[$product->id][$outKey] ?? []; $current[] = array_merge([], ['price' => $product->getProductPrice()]); $into[$product->id][$outKey] = $current; } } } private function getContextRanges(Preorder $preorder, array $additional = []): array { $ranges = $preorder->getSettings()['dynamic_prices'] ?? []; array_unshift($ranges, $preorder); $resultingRanges = []; foreach ($ranges as $range) { $contexts = $additional; $priceLevel = match (true) { PreorderUtil::fieldIsComposedOfDigits($range, 'id_price_level') => (int) $range['id_price_level'], PreorderUtil::fieldIsComposedOfDigits($preorder, 'id_price_level') => (int) $preorder['id_price_level'], default => ContextManager::FORCE_EMPTY, }; $pricelist = match (true) { PreorderUtil::fieldIsComposedOfDigits($range, 'id_pricelist') => (int) $range['id_pricelist'], PreorderUtil::fieldIsComposedOfDigits($preorder, 'id_pricelist') => (int) $preorder['id_pricelist'], default => ContextManager::FORCE_EMPTY, }; $contexts += [ PriceLevelContext::class => $priceLevel, PricelistContext::class => $pricelist, ]; $resultingRanges[] = $contexts; } return $resultingRanges; } }