Skip to content

[BUG] Incorrect product option price calculation in new orders in the admin console #4778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
massa-man opened this issue Apr 25, 2025 · 1 comment · May be fixed by #4779
Open
1 task done

[BUG] Incorrect product option price calculation in new orders in the admin console #4778

massa-man opened this issue Apr 25, 2025 · 1 comment · May be fixed by #4779
Labels
bug review needed Problem should be verified

Comments

@massa-man
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

When creating a new order in magento admin console for a product that includes custom options, the total product price is incorrectly calculated using the option price for the default store instead of the option price of the new order store.

The product total in the products list is correctly calculated using the correct option price for the order store, but the order totals (the subtotal specifically) is calculated using the product option price for the admin (default) store

Expected Behavior

I would expect the subtotal of the order to match the correct amount calculated using the order store for the option prices

Steps To Reproduce

  1. In a multi-store magento installation
  2. Create a product that has custom options with different FIXED prices in different websites/stores
  3. In the admin console, create a new order in a specific store
  4. Add the product created to the order and configure the product to add the option(s) with specific prices
  5. The product list section shows the correct total for the product and option in the order store
  6. However, the order subtotal in the totals section is calculated with the product price in the order store but the option price in the admin store
Image Image Image

Environment

- OpenMage: 20.12.2
- php: 8.2

Anything else?

No response

@massa-man massa-man added bug review needed Problem should be verified labels Apr 25, 2025
@massa-man
Copy link
Contributor Author

massa-man commented Apr 25, 2025

I have done some investigation on this issue and the problem is the following:

When the quote items are loaded as a collection, it assigns the products to the quote items, but for some reason magento is using the application store when loading the products into the quote items collection, instead of the quote store, loading the incorrect Product option prices and product option value prices (for multi select options)

This is the trace:

  1. When working with the quote items, we use Mage_Sales_Model_Quote::getItemsCollection()
  2. When we iterate the item collection, magento will load the items in the collection and will call Mage_Sales_Model_Resource_Quote_Item_Collection::_afterLoad() as with any other collection object
  3. This method calls $this->_assignProducts() to load and assign the product to each quote item
  4. This method loads a collection of products using the product IDs from the quote items and loads as well the product options for each product, specifically, in line 169, it prepares the product collection and calls Mage_Catalog_Model_Resource_Product_Collection::addOptionsToResult()
  5. The problem is in this method, addOptionsToResult has hardcoded the current magento application store instead of using the store provided by the quote to the Mage_Catalog_Model_Resource_Product_Collection::setStoreId() method

The actual code for this function is:

    public function addOptionsToResult()
    {
        $productIds = [];
        foreach ($this as $product) {
            $productIds[] = $product->getId();
        }
        if (!empty($productIds)) {
            $options = Mage::getModel('catalog/product_option')
                ->getCollection()
                ->addTitleToResult(Mage::app()->getStore()->getId())
                ->addPriceToResult(Mage::app()->getStore()->getId())
                ->addProductToFilter($productIds)
                ->addValuesToResult();

            foreach ($options as $option) {
                if ($this->getItemById($option->getProductId())) {
                    $this->getItemById($option->getProductId())->addOption($option);
                }
            }
        }

        return $this;
    }

The function should be using the store in the collection instance instead of the application store. In the frontend this is not an issue since the quote store is always the same as the application store, but this is not the case in admin, where the application store is the admin store (store ID = 0), and is different from the quote store. In this case the product options are loaded using the admin store and the incorrect price, title, etc.

I will provide a fix for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug review needed Problem should be verified
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant