123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\ConfigurableProduct\Pricing\Price;
- use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
- use Magento\Framework\App\ObjectManager;
- use Magento\Framework\Pricing\PriceCurrencyInterface;
- class ConfigurablePriceResolver implements PriceResolverInterface
- {
- /**
- * @var \Magento\ConfigurableProduct\Pricing\Price\PriceResolverInterface
- */
- protected $priceResolver;
- /**
- * @var PriceCurrencyInterface
- * @deprecated 100.0.2
- */
- protected $priceCurrency;
- /**
- * @var Configurable
- * @deprecated 100.0.2
- */
- protected $configurable;
- /**
- * @var LowestPriceOptionsProviderInterface
- */
- private $lowestPriceOptionsProvider;
- /**
- * @param PriceResolverInterface $priceResolver
- * @param Configurable $configurable
- * @param PriceCurrencyInterface $priceCurrency
- * @param LowestPriceOptionsProviderInterface $lowestPriceOptionsProvider
- */
- public function __construct(
- PriceResolverInterface $priceResolver,
- Configurable $configurable,
- PriceCurrencyInterface $priceCurrency,
- LowestPriceOptionsProviderInterface $lowestPriceOptionsProvider = null
- ) {
- $this->priceResolver = $priceResolver;
- $this->configurable = $configurable;
- $this->priceCurrency = $priceCurrency;
- $this->lowestPriceOptionsProvider = $lowestPriceOptionsProvider ?:
- ObjectManager::getInstance()->get(LowestPriceOptionsProviderInterface::class);
- }
- /**
- * @param \Magento\Framework\Pricing\SaleableInterface|\Magento\Catalog\Model\Product $product
- * @return float
- * @throws \Magento\Framework\Exception\LocalizedException
- */
- public function resolvePrice(\Magento\Framework\Pricing\SaleableInterface $product)
- {
- $price = null;
- foreach ($this->lowestPriceOptionsProvider->getProducts($product) as $subProduct) {
- $productPrice = $this->priceResolver->resolvePrice($subProduct);
- $price = isset($price) ? min($price, $productPrice) : $productPrice;
- }
- return (float)$price;
- }
- }
|