Skip to content

Commit becf50d

Browse files
authored
LYNX-460: Bundle products does not show original price and the final … (#268)
* LYNX-460: Bundle products does not show original price and the final price has no currency * LYNX-460: updated tests * LYNX-460: updated review point
1 parent 88d338f commit becf50d

File tree

3 files changed

+534
-25
lines changed

3 files changed

+534
-25
lines changed

app/code/Magento/BundleGraphQl/Model/Cart/BundleOptionDataProvider.php

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Quote\Model\Quote\Item;
1515
use Magento\Framework\Pricing\Helper\Data;
1616
use Magento\Framework\Serialize\SerializerInterface;
17+
use Magento\Bundle\Model\Product\OriginalPrice;
1718

1819
/**
1920
* Data provider for bundled product options
@@ -25,39 +26,23 @@ class BundleOptionDataProvider
2526
*/
2627
private const OPTION_TYPE = 'bundle';
2728

28-
/**
29-
* @var Data
30-
*/
31-
private $pricingHelper;
32-
33-
/**
34-
* @var SerializerInterface
35-
*/
36-
private $serializer;
37-
38-
/**
39-
* @var Configuration
40-
*/
41-
private $configuration;
42-
4329
/** @var Uid */
4430
private $uidEncoder;
4531

4632
/**
4733
* @param Data $pricingHelper
4834
* @param SerializerInterface $serializer
4935
* @param Configuration $configuration
36+
* @param OriginalPrice $originalPrice
5037
* @param Uid|null $uidEncoder
5138
*/
5239
public function __construct(
53-
Data $pricingHelper,
54-
SerializerInterface $serializer,
55-
Configuration $configuration,
40+
private readonly Data $pricingHelper,
41+
private readonly SerializerInterface $serializer,
42+
private readonly Configuration $configuration,
43+
private readonly OriginalPrice $originalPrice,
5644
Uid $uidEncoder = null
5745
) {
58-
$this->pricingHelper = $pricingHelper;
59-
$this->serializer = $serializer;
60-
$this->configuration = $configuration;
6146
$this->uidEncoder = $uidEncoder ?: ObjectManager::getInstance()
6247
->get(Uid::class);
6348
}
@@ -139,28 +124,34 @@ private function buildBundleOptionValues(array $selections, Item $item): array
139124
$values = [];
140125

141126
$product = $item->getProduct();
127+
$currencyCode = $item->getQuote()->getQuoteCurrencyCode();
142128
foreach ($selections as $selection) {
143129
$qty = (float) $this->configuration->getSelectionQty($product, $selection->getSelectionId());
144130
if (!$qty) {
145131
continue;
146132
}
147-
148133
$selectionPrice = $this->configuration->getSelectionFinalPrice($item, $selection);
149134
$optionDetails = [
150135
self::OPTION_TYPE,
151136
$selection->getData('option_id'),
152137
$selection->getData('selection_id'),
153138
(int) $selection->getData('selection_qty')
154139
];
140+
$price = $this->pricingHelper->currency($selectionPrice, false, false);
155141
$values[] = [
156142
'id' => $selection->getSelectionId(),
157143
'uid' => $this->uidEncoder->encode(implode('/', $optionDetails)),
158144
'label' => $selection->getName(),
159145
'quantity' => $qty,
160-
'price' => $this->pricingHelper->currency($selectionPrice, false, false),
146+
'price' => $price,
147+
'priceV2' => ['currency' => $currencyCode, 'value' => $price],
148+
'original_price' => [
149+
'currency' => $currencyCode,
150+
'value' => $this->originalPrice
151+
->getSelectionOriginalPrice($item->getProduct(), $selection)
152+
],
161153
];
162154
}
163-
164155
return $values;
165156
}
166157
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ type SelectedBundleOptionValue @doc(description: "Contains details about a value
4444
uid: ID! @doc(description: "The unique ID for a `SelectedBundleOptionValue` object")
4545
label: String! @doc(description: "The display name of the value for the selected bundle product option.")
4646
quantity: Float! @doc(description: "The quantity of the value for the selected bundle product option.")
47-
price: Float! @doc(description: "The price of the value for the selected bundle product option.")
47+
price: Float! @deprecated(reason: "Use priceV2 instead.") @doc(description: "The price of the value for the selected bundle product option.")
48+
priceV2: Money! @doc(description: "The price of the value for the selected bundle product option.")
49+
original_price: Money! @doc(description: "The original price of the value for the selected bundle product option.")
4850
}
4951

5052
type PriceDetails @doc(description: "Can be used to retrieve the main price details in case of bundle product") {

0 commit comments

Comments
 (0)