OpenMage / magento-lts

Official OpenMage LTS codebase | Migrate easily from Magento Community Edition in minutes! Download the source code for free or contribute to OpenMage LTS | Security vulnerability patches, bug fixes, performance improvements and more.
https://www.openmage.org
Open Software License 3.0
861 stars 438 forks source link

Warning: Undefined array key 5 Group Price #3125

Open m-overlund opened 1 year ago

m-overlund commented 1 year ago

I am getting this warning

Warning: Undefined array key 5  in[ /app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Groupprice/Abstract.php on line 208](https://github.com/OpenMage/magento-lts/blob/1.9.4.x/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Groupprice/Abstract.php#L208)

Warning: Trying to access array offset on value of type null  in [/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Groupprice/Abstract.php on line 207](https://github.com/OpenMage/magento-lts/blob/1.9.4.x/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Groupprice/Abstract.php#L207)

I suspect it could be related to products having a group price set for a specific website.

Afterwards the website is unassigned on that product and website id is no longer set.

ADDISON74 commented 1 year ago

How can we reproduce this issue as steps?

lc-excell commented 1 month ago

I have encountered this issue. In my case we have 2 stores for example store_id 1 and store_id 2. we have a code that will get all visible items from quote in both stores (this code runs in cron).

foreach ($objects['quote']->getAllVisibleItems() as $item) {
         $product = Mage::getModel('catalog/product')->setStoreId($item->getStoreId());
         $product->load($item->getProductId());
        // ....
 }

Stacktrace:

Abstract.php:82, Mage_Catalog_Model_Product_Attribute_Backend_Groupprice_Abstract->_getWebsiteCurrencyRates()
Abstract.php:188, Mage_Catalog_Model_Product_Attribute_Backend_Groupprice_Abstract->preparePriceData()
Abstract.php:235, Mage_Catalog_Model_Product_Attribute_Backend_Groupprice_Abstract->afterLoad()
Abstract.php:640, Mage_Eav_Model_Entity_Abstract->walkAttributes()
Abstract.php:1616, Mage_Eav_Model_Entity_Abstract->_afterLoad()
Abstract.php:943, Mage_Eav_Model_Entity_Abstract->load()
Abstract.php:739, Mage_Catalog_Model_Resource_Abstract->load()
Abstract.php:285, Mage_Core_Model_Abstract->load()

Issue: The value of $this->_rates remains the same throughout the loop (code above).

I temporarily fixed it by modifying Mage_Catalog_Model_Product_Attribute_Backend_Groupprice_Abstract::_getWebsiteCurrencyRates()

if (is_null($this->_rates)) {
      $this->_rates = [];
}

if (! isset($this->_rates[$websiteId])) {
      $baseCurrency = Mage::app()->getBaseCurrencyCode();
      //....
}