Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.4-develop' into ACP2E-3127
Browse files Browse the repository at this point in the history
  • Loading branch information
Chhandak.Barua authored and Chhandak.Barua committed Jul 19, 2024
2 parents ce05b97 + 11e7d89 commit 2da165c
Show file tree
Hide file tree
Showing 11 changed files with 752 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Magento\Quote\Model\Quote\Item;
use Magento\Framework\Pricing\Helper\Data;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Bundle\Model\Product\OriginalPrice;

/**
* Data provider for bundled product options
Expand All @@ -25,39 +26,23 @@ class BundleOptionDataProvider
*/
private const OPTION_TYPE = 'bundle';

/**
* @var Data
*/
private $pricingHelper;

/**
* @var SerializerInterface
*/
private $serializer;

/**
* @var Configuration
*/
private $configuration;

/** @var Uid */
private $uidEncoder;

/**
* @param Data $pricingHelper
* @param SerializerInterface $serializer
* @param Configuration $configuration
* @param OriginalPrice $originalPrice
* @param Uid|null $uidEncoder
*/
public function __construct(
Data $pricingHelper,
SerializerInterface $serializer,
Configuration $configuration,
private readonly Data $pricingHelper,
private readonly SerializerInterface $serializer,
private readonly Configuration $configuration,
private readonly OriginalPrice $originalPrice,
Uid $uidEncoder = null
) {
$this->pricingHelper = $pricingHelper;
$this->serializer = $serializer;
$this->configuration = $configuration;
$this->uidEncoder = $uidEncoder ?: ObjectManager::getInstance()
->get(Uid::class);
}
Expand Down Expand Up @@ -139,28 +124,34 @@ private function buildBundleOptionValues(array $selections, Item $item): array
$values = [];

$product = $item->getProduct();
$currencyCode = $item->getQuote()->getQuoteCurrencyCode();
foreach ($selections as $selection) {
$qty = (float) $this->configuration->getSelectionQty($product, $selection->getSelectionId());
if (!$qty) {
continue;
}

$selectionPrice = $this->configuration->getSelectionFinalPrice($item, $selection);
$optionDetails = [
self::OPTION_TYPE,
$selection->getData('option_id'),
$selection->getData('selection_id'),
(int) $selection->getData('selection_qty')
];
$price = $this->pricingHelper->currency($selectionPrice, false, false);
$values[] = [
'id' => $selection->getSelectionId(),
'uid' => $this->uidEncoder->encode(implode('/', $optionDetails)),
'label' => $selection->getName(),
'quantity' => $qty,
'price' => $this->pricingHelper->currency($selectionPrice, false, false),
'price' => $price,
'priceV2' => ['currency' => $currencyCode, 'value' => $price],
'original_price' => [
'currency' => $currencyCode,
'value' => $this->originalPrice
->getSelectionOriginalPrice($item->getProduct(), $selection)
],
];
}

return $values;
}
}
4 changes: 3 additions & 1 deletion app/code/Magento/BundleGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ type SelectedBundleOptionValue @doc(description: "Contains details about a value
uid: ID! @doc(description: "The unique ID for a `SelectedBundleOptionValue` object")
label: String! @doc(description: "The display name of the value for the selected bundle product option.")
quantity: Float! @doc(description: "The quantity of the value for the selected bundle product option.")
price: Float! @doc(description: "The price of the value for the selected bundle product option.")
price: Float! @deprecated(reason: "Use priceV2 instead.") @doc(description: "The price of the value for the selected bundle product option.")
priceV2: Money! @doc(description: "The price of the value for the selected bundle product option.")
original_price: Money! @doc(description: "The original price of the value for the selected bundle product option.")
}

type PriceDetails @doc(description: "Can be used to retrieve the main price details in case of bundle product") {
Expand Down
4 changes: 3 additions & 1 deletion app/code/Magento/GraphQl/Model/Query/Resolver/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
* @deprecated 100.3.3
* @see \Magento\GraphQl\Model\Query\Context
*/
class Context extends \Magento\Framework\Model\AbstractExtensibleModel implements ContextInterface
class Context extends \Magento\Framework\Model\AbstractExtensibleModel implements
ContextInterface,
ResetAfterRequestInterface
{
/**#@+
* Constants defined for type of context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Client
public const GRAPHQL_METHOD_POST = 'POST';
/**#@-*/

private const SET_COOKIE_HEADER_NAME = 'Set-Cookie';

/** @var CurlClient */
private $curlClient;

Expand Down Expand Up @@ -264,7 +266,15 @@ private function processResponseHeaders(string $headers): array
foreach ($headerLines as $headerLine) {
$headerParts = preg_split('/: /', $headerLine, 2);
if (count($headerParts) == 2) {
$headersArray[trim($headerParts[0])] = trim($headerParts[1]);
$headerName = trim($headerParts[0]);
if ($headerName === self::SET_COOKIE_HEADER_NAME) {
if (!isset($headersArray[self::SET_COOKIE_HEADER_NAME])) {
$headersArray[self::SET_COOKIE_HEADER_NAME] = [];
}
$headersArray[self::SET_COOKIE_HEADER_NAME][] = trim($headerParts[1]);
} else {
$headersArray[$headerName] = trim($headerParts[1]);
}
} elseif (preg_match('/HTTP\/[\.0-9]+/', $headerLine)) {
$headersArray[trim('Status-Line')] = trim($headerLine);
}
Expand Down
Loading

0 comments on commit 2da165c

Please sign in to comment.