magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.36k stars 9.28k forks source link

Catalog Products List widget - prices are loaded from wrong source #21581

Open snowcore opened 5 years ago

snowcore commented 5 years ago

Preconditions (*)

  1. Magento 2.2.7 (2.3) - both Open Source and Commerce editions
  2. Flat catalog enabled

Steps to reproduce (*)

Create widget "Catalog Products List", add some random products to it.

Expected result (*)

Product prices are loaded from price index table catalog_product_index_price

Actual result (*)

In the resulting product collection prices are taken from flat table instead of price index table (or from EAV if flat catalog is disabled).

Technical details

This affects Magento\CatalogWidget\Block\Product\ProductsList block and some others. The problem is in \Magento\Catalog\Block\Product\AbstractProduct::_addProductAttributesAndPrices() method. addAttributeToSelect() method is called later than addFinalPrice() and it overrides price column

protected function _addProductAttributesAndPrices(
        \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
    ) {
        return $collection
            ->addMinimalPrice()
            ->addFinalPrice()
            ->addTaxPercents()
            ->addAttributeToSelect($this->_catalogConfig->getProductAttributes())
            ->addUrlRewrite();
    }

\Magento\Catalog\Model\ResourceModel\Product\Collection::_productLimitationPrice() already handles price override, but it is not called in the right order.

// Preventing overriding price loaded from EAV because we want to use the one from index
$this->removeAttributeToSelect('price');

Other notes

  1. There is no need to call both addMinimalPrice() and addFinalPrice(), as they call the same method addPriceData()
  2. Potentially, the same problem is in \Magento\AdvancedCheckout\Helper\Data::getFailedItems()
  3. Ideally, there should be no dependency on methods call order (or we can combine addAttributeToSelect() with addFinalPrice() in some new method).

P.S.: will submit PR a bit later.

magento-engcom-team commented 5 years ago

Hi @snowcore. Thank you for your report. To help us process this issue please make sure that you provided the following information:

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

@snowcore do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

m2-assistant[bot] commented 4 years ago

Hi @engcom-Delta. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

magento-engcom-team commented 4 years ago

:white_check_mark: Confirmed by @engcom-Delta Thank you for verifying the issue. Based on the provided information internal tickets MC-18667 were created

Issue Available: @engcom-Delta, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

m2-assistant[bot] commented 1 month ago

Hi @engcom-Delta. Thank you for working on this issue. Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction: