Skip to content

Commit 11e7d89

Browse files
authored
Merge pull request #9059 from magento-lynx/2.4.8-graphql-api-enhancements
[LYNX] Delivery PR
2 parents 1b99b6d + f3294e9 commit 11e7d89

File tree

6 files changed

+584
-39
lines changed

6 files changed

+584
-39
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") {

dev/tests/api-functional/framework/Magento/TestFramework/TestCase/GraphQl/Client.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class Client
2222
public const GRAPHQL_METHOD_POST = 'POST';
2323
/**#@-*/
2424

25+
private const SET_COOKIE_HEADER_NAME = 'Set-Cookie';
26+
2527
/** @var CurlClient */
2628
private $curlClient;
2729

@@ -264,7 +266,15 @@ private function processResponseHeaders(string $headers): array
264266
foreach ($headerLines as $headerLine) {
265267
$headerParts = preg_split('/: /', $headerLine, 2);
266268
if (count($headerParts) == 2) {
267-
$headersArray[trim($headerParts[0])] = trim($headerParts[1]);
269+
$headerName = trim($headerParts[0]);
270+
if ($headerName === self::SET_COOKIE_HEADER_NAME) {
271+
if (!isset($headersArray[self::SET_COOKIE_HEADER_NAME])) {
272+
$headersArray[self::SET_COOKIE_HEADER_NAME] = [];
273+
}
274+
$headersArray[self::SET_COOKIE_HEADER_NAME][] = trim($headerParts[1]);
275+
} else {
276+
$headersArray[$headerName] = trim($headerParts[1]);
277+
}
268278
} elseif (preg_match('/HTTP\/[\.0-9]+/', $headerLine)) {
269279
$headersArray[trim('Status-Line')] = trim($headerLine);
270280
}

0 commit comments

Comments
 (0)