Skip to content

Commit f80f0d9

Browse files
🔃 [GraphQL] Partners Acceleration Program Contributions - 2.4-develop
Accepted Community Pull Requests: - #30623: [GraphQL] Fixed exposing special price (by @rogyar) Fixed GitHub Issues: - #29631: [2.3.5-p2] GraphQl Special Price Ignore's special price from to dates. (reported by @Hexmage) has been fixed in #30623 by @rogyar in 2.4-develop branch Related commits: 1. bafb07d 2. 0153d51 3. 5b95b8b 4. 2aca82d 5. dbb47b3 - #30210: Magento 2.4.0 graphql leak data on special price (reported by @thomasb0123) has been fixed in #30623 by @rogyar in 2.4-develop branch Related commits: 1. bafb07d 2. 0153d51 3. 5b95b8b 4. 2aca82d 5. dbb47b3
2 parents b5c918b + e1c9a58 commit f80f0d9

File tree

5 files changed

+116
-2
lines changed

5 files changed

+116
-2
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\CatalogGraphQl\Model\Resolver\Product;
99

10+
use Magento\Framework\Exception\LocalizedException;
1011
use Magento\Framework\GraphQl\Config\Element\Field;
1112
use Magento\Framework\GraphQl\Query\ResolverInterface;
1213
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
@@ -23,8 +24,13 @@ class SpecialPrice implements ResolverInterface
2324
*/
2425
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
2526
{
27+
if (!isset($value['model'])) {
28+
throw new LocalizedException(__('"model" value should be specified'));
29+
}
30+
2631
/** @var ProductInterface $product */
2732
$product = $value['model'];
33+
2834
/** @var PricingSpecialPrice $specialPrice */
2935
$specialPrice = $product->getPriceInfo()->getPrice(PricingSpecialPrice::PRICE_CODE);
3036

app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/Product/CollectionProcessor/RequiredColumnsProcessor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public function process(
3636
ContextInterface $context = null
3737
): Collection {
3838
$collection->addAttributeToSelect('special_price');
39-
$collection->addAttributeToSelect('special_price_from');
40-
$collection->addAttributeToSelect('special_price_to');
39+
$collection->addAttributeToSelect('special_from_date');
40+
$collection->addAttributeToSelect('special_to_date');
4141
$collection->addAttributeToSelect('tax_class_id');
4242

4343
return $collection;

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductPriceTest.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,72 @@ public function testProductWithCatalogDiscount()
945945
}
946946
}
947947

948+
/**
949+
* Check if the special price visible if the current date is in the date range set
950+
* for the special price
951+
*
952+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
953+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/set_simple_product_special_price.php
954+
*/
955+
public function testSpecialPriceVisibleIfInDateRange()
956+
{
957+
$query = <<<QUERY
958+
{
959+
products(filter: {sku: {eq: "simple_product"}}) {
960+
items {
961+
price_range {
962+
minimum_price {
963+
regular_price {
964+
value
965+
}
966+
}
967+
}
968+
special_price
969+
}
970+
}
971+
}
972+
QUERY;
973+
$result = $this->graphQlQuery($query);
974+
$productInformation = $result['products']['items'][0];
975+
$productRegularPrice = $productInformation['price_range']['minimum_price']['regular_price']['value'];
976+
977+
self::assertEquals('10', $productRegularPrice);
978+
self::assertEquals('5.99', $productInformation['special_price']);
979+
}
980+
981+
/**
982+
* Check if the special price is not visible if the current date is not in the date range set
983+
* for the special price
984+
*
985+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
986+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/set_simple_product_special_price_future_date.php
987+
*/
988+
public function testSpecialPriceNotVisibleIfNotInDateRange()
989+
{
990+
$query = <<<QUERY
991+
{
992+
products(filter: {sku: {eq: "simple_product"}}) {
993+
items {
994+
price_range {
995+
minimum_price {
996+
regular_price {
997+
value
998+
}
999+
}
1000+
}
1001+
special_price
1002+
}
1003+
}
1004+
}
1005+
QUERY;
1006+
$result = $this->graphQlQuery($query);
1007+
$productInformation = $result['products']['items'][0];
1008+
$productRegularPrice = $productInformation['price_range']['minimum_price']['regular_price']['value'];
1009+
1010+
self::assertEquals('10', $productRegularPrice);
1011+
self::assertEquals(null, $productInformation['special_price']);
1012+
}
1013+
9481014
/**
9491015
* Get GraphQl query to fetch products by sku
9501016
*
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Catalog\Api\ProductRepositoryInterface;
9+
use Magento\TestFramework\Helper\Bootstrap;
10+
11+
$objectManager = Bootstrap::getObjectManager();
12+
/** @var ProductRepositoryInterface $productRepository */
13+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
14+
15+
$product = $productRepository->get('simple_product');
16+
$product->setSpecialPrice('5.99');
17+
18+
$product->setSpecialFromDate(date('Y-m-d', strtotime('-1 day')));
19+
$product->setSpecialToDate(date('Y-m-d', strtotime('+1 day')));
20+
21+
$productRepository->save($product);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Catalog\Api\ProductRepositoryInterface;
9+
use Magento\TestFramework\Helper\Bootstrap;
10+
11+
$objectManager = Bootstrap::getObjectManager();
12+
/** @var ProductRepositoryInterface $productRepository */
13+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
14+
15+
$product = $productRepository->get('simple_product');
16+
$product->setSpecialPrice('5.99');
17+
18+
$product->setSpecialFromDate(date('Y-m-d', strtotime('+3 day')));
19+
$product->setSpecialToDate(date('Y-m-d', strtotime('+5 day')));
20+
21+
$productRepository->save($product);

0 commit comments

Comments
 (0)