Skip to content

Commit f99a581

Browse files
authored
LYNX-703 Bundle product does not return the correct discount percentage and amount
1 parent 1b8236a commit f99a581

File tree

5 files changed

+486
-1
lines changed

5 files changed

+486
-1
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\QuoteGraphQl\Model\Resolver;
9+
10+
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\Framework\GraphQl\Config\Element\Field;
12+
use Magento\Framework\GraphQl\Query\ResolverInterface;
13+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
14+
use Magento\CatalogGraphQl\Model\Resolver\Product\Price\Discount;
15+
use Magento\Quote\Api\Data\CartItemInterface;
16+
17+
class CatalogDiscount implements ResolverInterface
18+
{
19+
/**
20+
* CatalogDiscount constructor
21+
*
22+
* @param Discount $discount
23+
*/
24+
public function __construct(
25+
private readonly Discount $discount
26+
) {
27+
}
28+
29+
/**
30+
* @inheritdoc
31+
*/
32+
public function resolve(
33+
Field $field,
34+
$context,
35+
ResolveInfo $info,
36+
?array $value = null,
37+
?array $args = null
38+
):array {
39+
if (!(($value['model'] ?? null) instanceof CartItemInterface) ||
40+
empty($value['original_item_price']) ||
41+
empty($value['price'])
42+
) {
43+
throw new LocalizedException(__('The "model" value or pricing details are missing or invalid.'));
44+
}
45+
46+
return $this->discount->getDiscountByDifference(
47+
$value['original_item_price']['value'],
48+
$value['price']['value']
49+
);
50+
}
51+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\QuoteGraphQl\Model\Resolver;
9+
10+
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\Framework\GraphQl\Config\Element\Field;
12+
use Magento\Framework\GraphQl\Query\ResolverInterface;
13+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
14+
use Magento\CatalogGraphQl\Model\Resolver\Product\Price\Discount;
15+
use Magento\Quote\Api\Data\CartItemInterface;
16+
17+
class RowCatalogDiscount implements ResolverInterface
18+
{
19+
/**
20+
* RowCatalogDiscount constructor
21+
*
22+
* @param Discount $discount
23+
*/
24+
public function __construct(
25+
private readonly Discount $discount
26+
) {
27+
}
28+
29+
/**
30+
* @inheritdoc
31+
*/
32+
public function resolve(
33+
Field $field,
34+
$context,
35+
ResolveInfo $info,
36+
?array $value = null,
37+
?array $args = null
38+
):array {
39+
if (!(($value['model'] ?? null) instanceof CartItemInterface) ||
40+
empty($value['original_item_price']) ||
41+
empty($value['price'])
42+
) {
43+
throw new LocalizedException(__('The "model" value or pricing details are missing or invalid.'));
44+
}
45+
46+
/** @var CartItemInterface $item */
47+
$item = $value['model'];
48+
49+
return $this->discount->getDiscountByDifference(
50+
$value['original_item_price']['value'] * $item->getTotalQty(),
51+
$value['price']['value'] * $item->getTotalQty()
52+
);
53+
}
54+
}

app/code/Magento/QuoteGraphQl/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"magento/module-gift-message-graph-ql": "*",
2020
"magento/module-catalog-inventory": "*",
2121
"magento/module-eav-graph-ql": "*",
22-
"magento/module-downloadable": "*"
22+
"magento/module-downloadable": "*",
23+
"magento/module-catalog-graph-ql": "*"
2324
},
2425
"suggest": {
2526
"magento/module-graph-ql-cache": "*",

app/code/Magento/QuoteGraphQl/etc/schema.graphqls

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,8 @@ type CartItemPrices @doc(description: "Contains details about the price of the i
458458
total_item_discount: Money @doc(description: "The total of all discounts applied to the item.")
459459
original_item_price: Money! @doc(description: "The value of the original unit price for the item, including discounts.")
460460
original_row_total: Money! @doc(description: "The value of the original price multiplied by the quantity of the item.")
461+
catalog_discount: ProductDiscount @doc(description: "The price discount for the unit price of the item represents the difference between its regular price and final price.") @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\CatalogDiscount")
462+
row_catalog_discount: ProductDiscount @doc(description: "The price discount multiplied by the item quantity represents the total difference between the regular price and the final price for the entire quote item.") @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\RowCatalogDiscount")
461463
}
462464

463465
type SelectedCustomizableOption @doc(description: "Identifies a customized product that has been placed in a cart.") {

0 commit comments

Comments
 (0)