Skip to content

Commit c9a1c29

Browse files
committed
Merge branch 'ACP2E-2151' of https://github.com/magento-l3/magento2ce into PR-10122023
2 parents a051525 + 9f0716a commit c9a1c29

File tree

4 files changed

+170
-15
lines changed

4 files changed

+170
-15
lines changed

app/code/Magento/CatalogCustomerGraphQl/Model/Resolver/PriceTiers.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,6 @@ public function resolve(
125125
return [];
126126
}
127127

128-
if (!$product->getTierPrices()) {
129-
return [];
130-
}
131-
132128
$productId = (int)$product->getId();
133129
$this->tiers->addProductFilter($productId);
134130

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
/************************************************************************
3+
*
4+
* Copyright 2023 Adobe
5+
* All Rights Reserved.
6+
*
7+
* NOTICE: All information contained herein is, and remains
8+
* the property of Adobe and its suppliers, if any. The intellectual
9+
* and technical concepts contained herein are proprietary to Adobe
10+
* and its suppliers and are protected by all applicable intellectual
11+
* property laws, including trade secret and copyright laws.
12+
* Dissemination of this information or reproduction of this material
13+
* is strictly forbidden unless prior written permission is obtained
14+
* from Adobe.
15+
* ************************************************************************
16+
*/
17+
declare(strict_types=1);
18+
19+
namespace Magento\CatalogCustomerGraphQl\Test\Unit\Model\Resolver;
20+
21+
use Magento\CatalogCustomerGraphQl\Model\Resolver\Customer\GetCustomerGroup;
22+
use Magento\CatalogCustomerGraphQl\Model\Resolver\PriceTiers;
23+
use Magento\CatalogCustomerGraphQl\Model\Resolver\Product\Price\Tiers;
24+
use Magento\CatalogCustomerGraphQl\Model\Resolver\Product\Price\TiersFactory;
25+
use Magento\CatalogGraphQl\Model\Resolver\Product\Price\Discount;
26+
use Magento\CatalogGraphQl\Model\Resolver\Product\Price\ProviderPool;
27+
use Magento\Directory\Model\PriceCurrency;
28+
use Magento\Framework\GraphQl\Config\Element\Field;
29+
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
30+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
31+
use Magento\GraphQl\Model\Query\Context;
32+
use PHPUnit\Framework\TestCase;
33+
use PHPUnit\Framework\MockObject\MockObject;
34+
35+
/**
36+
* Test Resolver for PriceTiers
37+
*/
38+
class PriceTiersTest extends TestCase
39+
{
40+
/**
41+
* @var Field|MockObject
42+
*/
43+
private $fieldMock;
44+
45+
/**
46+
* @var ResolveInfo|MockObject
47+
*/
48+
private $resolveInfoMock;
49+
50+
/**
51+
* @var Context|MockObject
52+
*/
53+
private $contextMock;
54+
55+
/**
56+
* @var TiersFactory|MockObject
57+
*/
58+
private $tiersFactory;
59+
60+
/**
61+
* @var PriceTiers
62+
*/
63+
private $priceTiers;
64+
65+
protected function setUp(): void
66+
{
67+
$valueFactory = $this->createMock(ValueFactory::class);
68+
$this->tiersFactory = $this->createMock(TiersFactory::class);
69+
$customerGroup = $this->createMock(GetCustomerGroup::class);
70+
$priceDiscount = $this->createMock(Discount::class);
71+
$providerPool = $this->createMock(ProviderPool::class);
72+
$priceCurrency = $this->createMock(PriceCurrency::class);
73+
$this->priceTiers = new PriceTiers(
74+
$valueFactory,
75+
$this->tiersFactory,
76+
$customerGroup,
77+
$priceDiscount,
78+
$providerPool,
79+
$priceCurrency
80+
);
81+
82+
$this->fieldMock = $this->createMock(Field::class);
83+
$this->resolveInfoMock = $this->createMock(ResolveInfo::class);
84+
$this->contextMock = $this->createMock(Context::class);
85+
}
86+
87+
public function testResolve()
88+
{
89+
$tiers = $this->createMock(Tiers::class);
90+
$tiers->expects($this->once())
91+
->method('addProductFilter')
92+
->willReturnSelf();
93+
94+
$this->tiersFactory->expects($this->once())
95+
->method('create')
96+
->willReturn($tiers);
97+
98+
$productMock = $this->createMock(\Magento\Catalog\Model\Product::class);
99+
$productMock->expects($this->never())
100+
->method('getTierPrices');
101+
102+
$productMock->expects($this->once())
103+
->method('getId')
104+
->willReturn(1);
105+
106+
$valueMock = ['model' => $productMock];
107+
108+
$this->priceTiers->resolve($this->fieldMock, $this->contextMock, $this->resolveInfoMock, $valueMock);
109+
}
110+
}

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

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,68 @@
1717
*/
1818
class Provider implements ProviderInterface
1919
{
20+
/**
21+
* @var array
22+
*/
23+
private $minimalPrice = [
24+
FinalPrice::PRICE_CODE => [],
25+
RegularPrice::PRICE_CODE => []
26+
];
27+
28+
/**
29+
* @var array
30+
*/
31+
private $maximalPrice = [
32+
FinalPrice::PRICE_CODE => [],
33+
RegularPrice::PRICE_CODE => []
34+
];
35+
2036
/**
2137
* @inheritdoc
2238
*/
2339
public function getMinimalFinalPrice(SaleableInterface $product): AmountInterface
2440
{
25-
/** @var FinalPrice $finalPrice */
26-
$finalPrice = $product->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE);
27-
return $finalPrice->getMinimalPrice();
41+
if (!isset($this->minimalPrice[FinalPrice::PRICE_CODE][$product->getId()])) {
42+
/** @var FinalPrice $finalPrice */
43+
$finalPrice = $product->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE);
44+
$this->minimalPrice[FinalPrice::PRICE_CODE][$product->getId()] = $finalPrice->getMinimalPrice();
45+
}
46+
return $this->minimalPrice[FinalPrice::PRICE_CODE][$product->getId()];
2847
}
2948

3049
/**
3150
* @inheritdoc
3251
*/
3352
public function getMinimalRegularPrice(SaleableInterface $product): AmountInterface
3453
{
35-
return $this->getRegularPrice($product);
54+
if (!isset($this->minimalPrice[RegularPrice::PRICE_CODE][$product->getId()])) {
55+
$this->minimalPrice[RegularPrice::PRICE_CODE][$product->getId()] = $this->getRegularPrice($product);
56+
}
57+
return $this->minimalPrice[RegularPrice::PRICE_CODE][$product->getId()];
3658
}
3759

3860
/**
3961
* @inheritdoc
4062
*/
4163
public function getMaximalFinalPrice(SaleableInterface $product): AmountInterface
4264
{
43-
/** @var FinalPrice $finalPrice */
44-
$finalPrice = $product->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE);
45-
return $finalPrice->getMaximalPrice();
65+
if (!isset($this->maximalPrice[FinalPrice::PRICE_CODE][$product->getId()])) {
66+
/** @var FinalPrice $finalPrice */
67+
$finalPrice = $product->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE);
68+
$this->maximalPrice[FinalPrice::PRICE_CODE][$product->getId()] = $finalPrice->getMaximalPrice();
69+
}
70+
return $this->maximalPrice[FinalPrice::PRICE_CODE][$product->getId()];
4671
}
4772

4873
/**
4974
* @inheritdoc
5075
*/
5176
public function getMaximalRegularPrice(SaleableInterface $product): AmountInterface
5277
{
53-
return $this->getRegularPrice($product);
78+
if (!isset($this->maximalPrice[RegularPrice::PRICE_CODE][$product->getId()])) {
79+
$this->maximalPrice[RegularPrice::PRICE_CODE][$product->getId()] = $this->getRegularPrice($product);
80+
}
81+
return $this->maximalPrice[RegularPrice::PRICE_CODE][$product->getId()];
5482
}
5583

5684
/**

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Catalog\Pricing\Price\FinalPrice;
1111
use Magento\Catalog\Pricing\Price\RegularPrice;
12+
use Magento\CatalogGraphQl\Model\Resolver\Product\Price\Provider as CatalogPriceProvider;
1213
use Magento\CatalogGraphQl\Model\Resolver\Product\Price\ProviderInterface;
1314
use Magento\ConfigurableProduct\Pricing\Price\ConfigurableOptionsProviderInterfaceFactory;
1415
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
@@ -52,17 +53,25 @@ class Provider implements ProviderInterface, ResetAfterRequestInterface
5253
RegularPrice::PRICE_CODE => []
5354
];
5455

56+
/**
57+
* @var CatalogPriceProvider
58+
*/
59+
private $catalogPriceProvider;
60+
5561
/**
5662
* @param ConfigurableOptionsProviderInterfaceFactory $optionsProviderFactory
5763
* @param BaseFactory $amountFactory
64+
* @param CatalogPriceProvider $catalogPriceProvider
5865
*/
5966
public function __construct(
6067
ConfigurableOptionsProviderInterfaceFactory $optionsProviderFactory,
61-
BaseFactory $amountFactory
68+
BaseFactory $amountFactory,
69+
CatalogPriceProvider $catalogPriceProvider
6270
) {
6371
$this->optionsProvider = $optionsProviderFactory->create();
6472
$this->optionsProviderFactory = $optionsProviderFactory;
6573
$this->amountFactory = $amountFactory;
74+
$this->catalogPriceProvider = $catalogPriceProvider;
6675
}
6776

6877
/**
@@ -117,7 +126,13 @@ private function getMinimalPrice(SaleableInterface $product, string $code): Amou
117126
if (!isset($this->minimalPrice[$code][$product->getId()])) {
118127
$minimumAmount = null;
119128
foreach ($this->optionsProvider->getProducts($product) as $variant) {
120-
$variantAmount = $variant->getPriceInfo()->getPrice($code)->getAmount();
129+
$variantAmount = null;
130+
if ($code === FinalPrice::PRICE_CODE) {
131+
$variantAmount = $this->catalogPriceProvider->getMinimalFinalPrice($variant);
132+
} elseif ($code === RegularPrice::PRICE_CODE) {
133+
$variantAmount = $this->catalogPriceProvider->getMinimalRegularPrice($variant);
134+
}
135+
121136
if (!$minimumAmount || ($variantAmount->getValue() < $minimumAmount->getValue())) {
122137
$minimumAmount = $variantAmount;
123138
$this->minimalPrice[$code][$product->getId()] = $variantAmount;
@@ -140,7 +155,13 @@ private function getMaximalPrice(SaleableInterface $product, string $code): Amou
140155
if (!isset($this->maximalPrice[$code][$product->getId()])) {
141156
$maximumAmount = null;
142157
foreach ($this->optionsProvider->getProducts($product) as $variant) {
143-
$variantAmount = $variant->getPriceInfo()->getPrice($code)->getAmount();
158+
$variantAmount = null;
159+
if ($code === FinalPrice::PRICE_CODE) {
160+
$variantAmount = $this->catalogPriceProvider->getMaximalFinalPrice($variant);
161+
} elseif ($code === RegularPrice::PRICE_CODE) {
162+
$variantAmount = $this->catalogPriceProvider->getMaximalRegularPrice($variant);
163+
}
164+
144165
if (!$maximumAmount || ($variantAmount->getValue() > $maximumAmount->getValue())) {
145166
$maximumAmount = $variantAmount;
146167
$this->maximalPrice[$code][$product->getId()] = $variantAmount;

0 commit comments

Comments
 (0)