Skip to content

Commit 134bfa9

Browse files
committed
Merge branch 'MC-43176' of https://github.com/magento-l3/magento2ce into L3-PR-20210908
2 parents 509af9b + 4444b72 commit 134bfa9

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Product/PriceRange.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
*/
2424
class PriceRange implements ResolverInterface
2525
{
26+
private const STORE_FILTER_CACHE_KEY = '_cache_instance_store_filter';
27+
2628
/**
2729
* @var Discount
2830
*/
@@ -62,6 +64,8 @@ public function resolve(
6264
/** @var Product $product */
6365
$product = $value['model'];
6466
$product->unsetData('minimal_price');
67+
// add store filter for the product
68+
$product->setData(self::STORE_FILTER_CACHE_KEY, $store);
6569

6670
if ($context) {
6771
$customerGroupId = $context->getExtensionAttributes()->getCustomerGroupId();

dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogGraphQl/PriceRangeTest.php

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,34 @@ protected function setUp(): void
3434
$this->getCustomerAuthenticationHeader = $this->objectManager->get(GetCustomerAuthenticationHeader::class);
3535
}
3636

37+
/**
38+
* @magentoApiDataFixture Magento/Store/_files/second_website_with_two_stores.php
39+
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable_in_multiple_websites.php
40+
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable_in_multiple_websites_with_special_price.php
41+
*/
42+
public function testMinimalPriceForConfigurableProductWithSpecialPrice() : void
43+
{
44+
$headerMapFirstStore['Store'] = 'default';
45+
$headerMapSecondStore['Store'] = 'fixture_second_store';
46+
$query = $this->getProductsBySkuQuery();
47+
$responseForFirstWebsite = $this->graphQlQuery($query, [], '', $headerMapFirstStore);
48+
$responseForSecondWebsite = $this->graphQlQuery($query, [], '', $headerMapSecondStore);
49+
50+
$this->assertNotEmpty($responseForFirstWebsite['products']);
51+
$priceRange = $responseForFirstWebsite['products']['items'][0]['price_range'];
52+
$this->assertEquals(10, $priceRange['minimum_price']['regular_price']['value']);
53+
$this->assertEquals(10, $priceRange['minimum_price']['final_price']['value']);
54+
$this->assertEquals(10, $priceRange['maximum_price']['regular_price']['value']);
55+
$this->assertEquals(10, $priceRange['maximum_price']['final_price']['value']);
56+
57+
$this->assertNotEmpty($responseForSecondWebsite['products']);
58+
$priceRange = $responseForSecondWebsite['products']['items'][0]['price_range'];
59+
$this->assertEquals(20, $priceRange['minimum_price']['regular_price']['value']);
60+
$this->assertEquals(4, $priceRange['minimum_price']['final_price']['value']);
61+
$this->assertEquals(20, $priceRange['maximum_price']['regular_price']['value']);
62+
$this->assertEquals(4, $priceRange['maximum_price']['final_price']['value']);
63+
}
64+
3765
/**
3866
* Test for checking if catalog rule price has been applied for all customer group
3967
*
@@ -278,6 +306,63 @@ private function getProductSearchQuery(string $productSku): string
278306
}
279307
}
280308
}
309+
QUERY;
310+
}
311+
312+
/**
313+
* Get a query which user filter for product sku and returns price_range
314+
*
315+
* @param string $productSku
316+
* @return string
317+
*/
318+
private function getProductsBySkuQuery() : string
319+
{
320+
return <<<QUERY
321+
query getProductsBySku {
322+
products(filter: { sku: { eq: "configurable" } }) {
323+
items {
324+
sku
325+
name
326+
price_range {
327+
minimum_price {
328+
regular_price {
329+
value
330+
currency
331+
}
332+
discount {
333+
amount_off
334+
percent_off
335+
}
336+
final_price {
337+
value
338+
currency
339+
}
340+
}
341+
maximum_price {
342+
regular_price {
343+
value
344+
currency
345+
}
346+
discount {
347+
amount_off
348+
percent_off
349+
}
350+
final_price {
351+
value
352+
currency
353+
}
354+
}
355+
}
356+
... on ConfigurableProduct {
357+
variants {
358+
product {
359+
sku
360+
}
361+
}
362+
}
363+
}
364+
}
365+
}
281366
QUERY;
282367
}
283368
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\Catalog\Api\ProductRepositoryInterface;
8+
use Magento\Store\Api\WebsiteRepositoryInterface;
9+
use Magento\TestFramework\Helper\Bootstrap;
10+
11+
Bootstrap::getInstance()->reinitialize();
12+
13+
/** @var WebsiteRepositoryInterface $repository */
14+
$repository = Bootstrap::getObjectManager()->get(WebsiteRepositoryInterface::class);
15+
$websiteId = $repository->get('test')->getId();
16+
17+
/** @var ProductRepositoryInterface $productRepository */
18+
$productRepository = Bootstrap::getObjectManager()
19+
->create(ProductRepositoryInterface::class);
20+
21+
$product = $productRepository->get('simple_20', true);
22+
$product->setSpecialPrice('4');
23+
$product->setWebsiteIds([$websiteId]);
24+
$productRepository->save($product);
25+
26+
$product = $productRepository->get('simple_10', true);
27+
$product->setWebsiteIds([1]);
28+
$productRepository->save($product);
29+
30+
$product = $productRepository->get('configurable', true);
31+
$product->setWebsiteIds([1, $websiteId]);
32+
$productRepository->save($product);

0 commit comments

Comments
 (0)