Skip to content

Commit 9c09aac

Browse files
LYNX-411: add custom options price to origin_row_total (#247)
1 parent 642511e commit 9c09aac

File tree

2 files changed

+411
-1
lines changed

2 files changed

+411
-1
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/CartItemPrices.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,29 @@ private function getOriginalRowTotal(Item $cartItem): float
118118
{
119119
$qty = $cartItem->getTotalQty();
120120
// Round unit price before multiplying to prevent losing 1 cent on subtotal
121-
return $this->priceCurrency->round($cartItem->getOriginalPrice()) * $qty;
121+
return $this->priceCurrency->round($cartItem->getOriginalPrice() + $this->getOptionsPrice($cartItem)) * $qty;
122+
}
123+
124+
/**
125+
* Get the product custom options price
126+
*
127+
* @param Item $cartItem
128+
* @return float
129+
*/
130+
private function getOptionsPrice(Item $cartItem): float
131+
{
132+
$price = 0.0;
133+
$optionIds = $cartItem->getProduct()->getCustomOption('option_ids');
134+
if (!$optionIds) {
135+
return $price;
136+
}
137+
foreach (explode(',', $optionIds->getValue() ?? '') as $optionId) {
138+
$option = $cartItem->getProduct()->getOptionById($optionId);
139+
if ($option) {
140+
$price += $option->getRegularPrice();
141+
}
142+
}
143+
144+
return $price;
122145
}
123146
}

0 commit comments

Comments
 (0)