Skip to content

Commit

Permalink
LYNX-411: add custom options price to origin_row_total (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
eliseacornejo authored May 21, 2024
1 parent 642511e commit 9c09aac
Show file tree
Hide file tree
Showing 2 changed files with 411 additions and 1 deletion.
25 changes: 24 additions & 1 deletion app/code/Magento/QuoteGraphQl/Model/Resolver/CartItemPrices.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,29 @@ private function getOriginalRowTotal(Item $cartItem): float
{
$qty = $cartItem->getTotalQty();
// Round unit price before multiplying to prevent losing 1 cent on subtotal
return $this->priceCurrency->round($cartItem->getOriginalPrice()) * $qty;
return $this->priceCurrency->round($cartItem->getOriginalPrice() + $this->getOptionsPrice($cartItem)) * $qty;
}

/**
* Get the product custom options price
*
* @param Item $cartItem
* @return float
*/
private function getOptionsPrice(Item $cartItem): float
{
$price = 0.0;
$optionIds = $cartItem->getProduct()->getCustomOption('option_ids');
if (!$optionIds) {
return $price;
}
foreach (explode(',', $optionIds->getValue() ?? '') as $optionId) {
$option = $cartItem->getProduct()->getOptionById($optionId);
if ($option) {
$price += $option->getRegularPrice();
}
}

return $price;
}
}
Loading

0 comments on commit 9c09aac

Please sign in to comment.