Skip to content

Commit ff43641

Browse files
committed
ACP2E-1417: [GraphQL] Customer cannot proceed with purchase when items in cart get out of stock
- fix
1 parent 6dbb7fc commit ff43641

File tree

1 file changed

+13
-17
lines changed
  • app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/Product/Price

1 file changed

+13
-17
lines changed

app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/Product/Price/Provider.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\CatalogGraphQl\Model\Resolver\Product\Price\ProviderInterface;
1414
use Magento\ConfigurableProduct\Pricing\Price\ConfigurableOptionsProviderInterface;
1515
use Magento\Framework\Pricing\Amount\AmountInterface;
16+
use Magento\Framework\Pricing\Amount\BaseFactory;
1617
use Magento\Framework\Pricing\SaleableInterface;
1718

1819
/**
@@ -25,6 +26,11 @@ class Provider implements ProviderInterface
2526
*/
2627
private $optionsProvider;
2728

29+
/**
30+
* @var BaseFactory
31+
*/
32+
private $amountFactory;
33+
2834
/**
2935
* @var array
3036
*/
@@ -43,11 +49,14 @@ class Provider implements ProviderInterface
4349

4450
/**
4551
* @param ConfigurableOptionsProviderInterface $optionsProvider
52+
* @param BaseFactory $amountFactory
4653
*/
4754
public function __construct(
48-
ConfigurableOptionsProviderInterface $optionsProvider
55+
ConfigurableOptionsProviderInterface $optionsProvider,
56+
BaseFactory $amountFactory
4957
) {
5058
$this->optionsProvider = $optionsProvider;
59+
$this->amountFactory = $amountFactory;
5160
}
5261

5362
/**
@@ -101,7 +110,7 @@ private function getMinimalPrice(SaleableInterface $product, string $code): Amou
101110
{
102111
if (!isset($this->minimalPrice[$code][$product->getId()])) {
103112
$minimumAmount = null;
104-
foreach ($this->filterDisabledProducts($this->optionsProvider->getProducts($product)) as $variant) {
113+
foreach ($this->optionsProvider->getProducts($product) as $variant) {
105114
$variantAmount = $variant->getPriceInfo()->getPrice($code)->getAmount();
106115
if (!$minimumAmount || ($variantAmount->getValue() < $minimumAmount->getValue())) {
107116
$minimumAmount = $variantAmount;
@@ -110,7 +119,7 @@ private function getMinimalPrice(SaleableInterface $product, string $code): Amou
110119
}
111120
}
112121

113-
return $this->minimalPrice[$code][$product->getId()];
122+
return $this->minimalPrice[$code][$product->getId()] ?? $this->amountFactory->create(['amount' => null]);
114123
}
115124

116125
/**
@@ -133,19 +142,6 @@ private function getMaximalPrice(SaleableInterface $product, string $code): Amou
133142
}
134143
}
135144

136-
return $this->maximalPrice[$code][$product->getId()];
137-
}
138-
139-
/**
140-
* Filter out disabled products
141-
*
142-
* @param array $products
143-
* @return array
144-
*/
145-
private function filterDisabledProducts(array $products): array
146-
{
147-
return array_filter($products, function ($product) {
148-
return (int)$product->getStatus() === ProductStatus::STATUS_ENABLED;
149-
});
145+
return $this->maximalPrice[$code][$product->getId()] ?? $this->amountFactory->create(['amount' => null]);
150146
}
151147
}

0 commit comments

Comments
 (0)