Skip to content

Conversation

fballiano
Copy link

@fballiano fballiano commented Aug 1, 2022

Method Mage_Catalog_Model_Product_Attribute_Backend_Groupprice_Abstract::preparePriceData() (which is this one):

    public function preparePriceData(array $priceData, $productTypeId, $websiteId)
    {
        $rates  = $this->_getWebsiteCurrencyRates();
        $data   = [];
        $price  = Mage::getSingleton('catalog/product_type')->priceFactory($productTypeId);
        foreach ($priceData as $v) {
            $key = implode('-', array_merge([$v['cust_group']], $this->_getAdditionalUniqueFields($v)));
            if ($v['website_id'] == $websiteId) {
                $data[$key] = $v;
                $data[$key]['website_price'] = $v['price'];
            } elseif ($v['website_id'] == 0 && !isset($data[$key])) {
                $data[$key] = $v;
                $data[$key]['website_id'] = $websiteId;
                if ($this->_isPriceFixed($price)) {
                    $data[$key]['price'] = $v['price'] * $rates[$websiteId]['rate'];
                    $data[$key]['website_price'] = $v['price'] * $rates[$websiteId]['rate'];
                }
            }
        }

        return $data;
    }

calls $this->_getWebsiteCurrencyRates(), which is:

    protected function _getWebsiteCurrencyRates()
    {
        if (is_null($this->_rates)) {
            $this->_rates = [];
            $baseCurrency = Mage::app()->getBaseCurrencyCode();
            foreach (Mage::app()->getWebsites() as $website) {
                /* @var Mage_Core_Model_Website $website */
                if ($website->getBaseCurrencyCode() != $baseCurrency) {
                    $rate = Mage::getModel('directory/currency')
                        ->load($baseCurrency)
                        ->getRate($website->getBaseCurrencyCode());
                    if (!$rate) {
                        $rate = 1;
                    }
                    $this->_rates[$website->getId()] = [
                        'code' => $website->getBaseCurrencyCode(),
                        'rate' => $rate
                    ];
                } else {
                    $this->_rates[$website->getId()] = [
                        'code' => $baseCurrency,
                        'rate' => 1
                    ];
                }
            }
        }
        return $this->_rates;
    }

as you can see _getWebsiteCurrencyRates() cycles all websites but that's useless when called by preparePriceData(), because preparePriceData only uses a single website (check the variable $websiteId).

This PR adds support for $websiteId to _getWebsiteCurrencyRates() so it only load the current websites and (in multiwebsite environment) can be a good performance benefit when loading products with Mage_Catalog_Model_Product::load().

@github-actions github-actions bot added the Component: Catalog Relates to Mage_Catalog label Aug 1, 2022
@fballiano fballiano requested a review from elidrissidev August 2, 2022 14:38
Copy link
Member

@elidrissidev elidrissidev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fballiano fballiano merged commit 4721a48 into OpenMage:1.9.4.x Aug 2, 2022
@fballiano fballiano deleted the getWebsiteCurrencyRates branch August 2, 2022 15:25
@github-actions
Copy link
Contributor

github-actions bot commented Aug 2, 2022

Unit Test Results

1 files  ±0  1 suites  ±0   0s ⏱️ ±0s
0 tests ±0  0 ✔️ ±0  0 💤 ±0  0 ❌ ±0 
7 runs  ±0  5 ✔️ ±0  2 💤 ±0  0 ❌ ±0 

Results for commit 4721a48. ± Comparison against base commit ee05559.

sreichel added a commit that referenced this pull request Aug 12, 2022
* Merge PR #2342

* Revert "Add basic text for Ukraine (#2074)" (#2325)

This reverts commit 33dfa26.

* Mage_Catalog_Model_Product_Attribute_Backend_Groupprice_Abstract: avoid loading all websites when using only the current one (#2351)

* Added support for HTTP2 to Mage_HTTP_Client_Curl (#1137)

* Blocked access to all dot files (#2349)

* Capitalization Adjustment Regarding CamelCase in Method Names (#2365)

* refactor: Adjusted capitalization of two public methods.

* refactor: Adjusted capitalization of one protected method.

* refactor: Adjusted capitalization of where call.

* chore: Removed fixed error from phpstan baseline.

* Some microoptimization (#2335)

* Avoid duplicate method calls

* Replaced array_push()

* Changed substr() third parameter

* Use array_key_exists()

* php7 opcode - internal functions

* Enclosed error with <pre> tag for prettier error print (if developer mode is enabled). (#2368)

* Updated phpstan to 1.8.2 (#2367)

* Escape product titles in MSRP JavaScript (#2366)

* Product names were not escaped. If contained a double quote, would break the JavaScript for MSRP/MAP

* update contribution list

* Update boxes.css (#2330)

* Force describeTable() to use read DB adapter (#2371)

* Do not install n98/n98_layouthelper (#2373)

* Add apt update to XML validation workflow (#2376)

* Merged PR #2375

* Replace remaining "sizeof" calls with "count" (#2369)

* Remove DISCLAIMER and change Magento -> OpenMage in header (#2297)

* Added label for phpstan cosmetic changes (#2384)

* Added weight to salesOrderShipmentAddTrack API (#1377)

* PHPStan/DOCBlock fixes (#2336)

* Updated docs for email addTo() (#2382)

* Updated phpstan experimental (#2386)

* Cosmetic changes to Mage_Payment_Model_Method_Abstract::validate() (#2388)

* Replaced join() calls with implode() (#2389)

* Hidden empty sub menu from backend (#2391)

* Remove Thumbs.db file (#2394)

* Support PHP 8.1 in composer.json (#2378)

* php condition in composer.json

This solves the issue related to php versions > 8.1

* Reduced condition for PHP requirement

* Changed PHP requirement

* Updated version in Ubuntu 22.04 based on PHP 8.1.2

* Composer.lock updated in Ubuntu 20.04 (PHP 8.1.2)

* Update composer.lock

* Update composer.lock

* Blocked various file types in .htaccess (#2359)

* Color swatches work with disparate product IDs (#2390)

* Move Credit Memo at the end of the buttons list (#2392)

* Version bump (#2387)

* Minor fixes on 'filter_condition_callback' method _filterStoreCondition() (#2362)

* add ReturnTypeWillChange to various Files catched by code style checker #2302

* Phpstan fixes (#2396)

* Fixed addCrumb()

* Fixed initForm() and _needToAddDummy()

* Fixed addLink()

* Fixed addLinkRel()

* Fixed canUseCanonicalTag()

* Fixed getAddUrl...()

* Fixed rollBack() camelCase error reported by phpstan (#2403)

* Changes default root dir in composer.json (#2401)

* Fixed targetNamespace for WS-I Compliant SOAP APIs (#2405)

* Updated phpstan baseline

Co-authored-by: sv3n <github-sr@hotmail.com>
Co-authored-by: Fabian Blechschmidt <github@fabian-blechschmidt.de>
Co-authored-by: Colin Mollenhour <colin@mollenhour.com>
Co-authored-by: Kevin Jakob <kevin-jakob@web.de>
Co-authored-by: Ng Kiat Siong <kiatsiong.ng@gmail.com>
Co-authored-by: Scott Moore <scott.moore@dfsupplyinc.com>
Co-authored-by: ADDISON <8360474+ADDISON74@users.noreply.github.com>
Co-authored-by: Justin Beaty <51970393+justinbeaty@users.noreply.github.com>
Co-authored-by: luigifab <31816829+luigifab@users.noreply.github.com>
Co-authored-by: Daniel Fahlke <flyingmana@googlemail.com>
Co-authored-by: leissbua <68073221+leissbua@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Catalog Relates to Mage_Catalog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants