Magento: edit quantity and update price of bundle option in quote item

Magento: edit quantity and update price of bundle option in quote item

September 1, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento: edit quantity and update price of bundle option in quote item

Magento: Programmatically Updating Bundle Option Quantities and Prices

As you’re working with Magento bundle products, updating quantities for hidden options programmatically can be quite challenging, especially when it comes to ensuring the price reflects the changes accurately. Let’s dive into your issue and provide a solution that addresses both updating the quantity of a bundle option and recalculating the price accordingly.

Understanding the Current Issue

You’ve already implemented a button to submit the bundle quote item to an updateLineItemAction() method in your custom CartController, correctly assigning the updated quantities to the “selection_qty_X” and “product_qty_X” properties. The hidden option’s quantity is being updated successfully.

However, the price isn’t recalculated automatically when you save the quote item, despite attempts at saving the cart again afterward. This discrepancy arises because Magento doesn’t trigger the price calculation after a manual update to the bundle options’ quantities.

The Solution: Recalculating Prices for Bundle Items

To tackle this issue, we need to manually force a recalculation of prices for the updated bundle item:

  1. Collect Price Data: Before updating your quote item and saving it, collect all necessary price data related to the updated options. This includes getting the product’s final price, tax calculation data, and any applicable discounts.

  2. Calculate the New Total: Multiply the new quantity of each option by its respective price (after applying any discounts) and sum these values up to get the new subtotal for the bundle item.

  3. Update Quote Item Prices: Assign the newly calculated total as the “price” property of your quote item.

Here’s a code snippet demonstrating this approach:

$bundleItem = $quote->getItemById($itemId);
$newQuantity = 5; // Updated quantity

// Calculate new subtotal for bundle item
$optionSubtotal = 0;
foreach ($bundleItem->getProduct()->getTypeInstance()->getSelectionsCollection() as $selection) {
    if ($selection->getSelectionId() == 'X') { // Find the updated option ID
        $price = $selection->getPrice();
        $newOptionTotal = $newQuantity * $price;
        $optionSubtotal += $newOptionTotal;
    }
}

$bundleItem->setRowTotal($optionSubtotal);
$quote->collectTotals();

Conclusion

Updating the quantity of a hidden bundle option within a quote item requires careful handling to ensure the price is recalculated correctly. By manually collecting price data for each affected option, calculating the new total, and updating the quote item’s “price” property before saving it again, you can successfully update both the quantity and price.

Remember that Magento provides extensive documentation on working with prices and discounts, which can be found in the official Magento Developer Documentation: https://laravelcompany.com/magento-developer-documentation/working-with-prices-and-discounts.

In your specific case, focusing on recalculating the bundle item’s total based on the updated option quantities before saving the quote will resolve the pricing discrepancy. This approach ensures that your custom CartController handles both quantity and price updates accurately for Magento bundle products.

Don’t hesitate to reach out if you have any further questions or need more detailed assistance with Magento development tasks like this one!

Checkout Catalog Pricing Errors

Our network