Skip to content
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

Fix #7371 #8593

Merged
merged 3 commits into from
Feb 25, 2017
Merged

Fix #7371 #8593

merged 3 commits into from
Feb 25, 2017

Conversation

rossluk
Copy link
Contributor

@rossluk rossluk commented Feb 17, 2017

'catalog_rule_price' is added to products only before load of the Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\Collection and it is used only for detecting the minimal price here - Magento\Catalog\Pricing\Price\BasePrice. Due to it the price has never converted to the site currency.

 'catalog_rule_price' is added to products only before load of the Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\Collection and it is used only for detecting the minimal price here - Magento\Catalog\Pricing\Price\BasePrice. Due to it the price has never converted to the site currency.
@okorshenko okorshenko self-assigned this Feb 18, 2017
@okorshenko okorshenko added this to the February 2017 milestone Feb 18, 2017
@okorshenko
Copy link
Contributor

@rossluk could you please provide clear test cases? what is the issue and how to reproduce it. And how we can test your solution.

Thank you

@rossluk
Copy link
Contributor Author

rossluk commented Feb 22, 2017

@okorshenko

  1. Install Magento;
  2. Add new currency to your website (By default there is USD only, leave USD as base currency and add Euro, then update rates to see the difference between product prices in different currency);
  3. Create configurable product with some modifications (more then one);
  4. Create Catalog Rule with some discount (for instance 50% for Default Category);
  5. Go to product page (which was created on step 3);
  6. Change site currency from base to Euro;
  7. You should see the normal base price in Euro and it's ok, but if you change product option you'll see product price changed. It will have Euro sign but price value will be in USD. Option prices are received from server (swatches json config) and always have Base and Final price in main site currency (these prices for product options are loaded from \Magento\CatalogRule\Pricing\Price\CatalogRulePrice through the price resolver and it's a problem);

@orlangur
Copy link
Contributor

@okorshenko, steps are described in #7371, you know :)

@rossluk, fix looks incorrect to me. Check the logic in e3cecaf#diff-ca5d201faa2fc6d81caa299b64589a3bR91
From what I can understand here, value stored in product must be already converted.

So, if the issue is relevant for develop branch, you should find a place where incorrect value is stored to product and make this place multi-currency-aware. Sorry, didn't play with the code, thus, I may oversee the whole picture.

$this->value = $this->priceCurrency->convertAndRound($this->value);
}
}
if ($this->value) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@orlangur Sorry, I can't understand what I should see in diff. Problem is 'catalog_rule_price' which is added to join in Magento\CatalogRuleConfigurable\Plugin\ConfigurableProduct\Model\ResourceModel\AddCatalogRulePrice. I didn't see any mention about current currency (if value from db already in current currency we should see something about it) or conversion of the value in this file, and I didn't see any places where 'catalog_rule_price' or 'rule_price' converts to current currency after. Maybe I miss something?

Copy link
Contributor

Choose a reason for hiding this comment

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

if ($this->product->hasData(self::PRICE_CODE)) {
    $this->value = floatval($this->product->getData(self::PRICE_CODE)) ?: false;

Where this value is stored? I believe currency conversion is missed there.

So, it's better to store totally prepared value than convert it after.

However, if the value stored in product is not store-aware by design, fix looks ok to me. To avoid regression it's better to create proper integration test, with catalog rule and multiple currencies, as change of started to fail unit test does not enforce anything (i.e. somebody doing next changes will just do the same - change hardcoded expectations - as test case is not sticked to any concrete scenario).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if ($this->product->hasData(self::PRICE_CODE)) {
    $this->value = floatval($this->product->getData(self::PRICE_CODE)) ?: false;

This value is stored in the 'catalogrule_product_price' table. As I know all prices in Magento is converted after (from base currency to selected on site) and it's too much work to store prepared value because there is should be added a new dimension by currency per store. Value which is stored in product is website-aware, but currency is another dimension (you can have many currencies for one store view).

Copy link
Contributor

Choose a reason for hiding this comment

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

I see... Thanks, that's exactly what I was asking.

Then

fix looks ok to me

Integration test would be really valuable to not ever break this place again, but it's up to you, of course, whether invest time in it or not.

@mmansoor-magento mmansoor-magento merged commit 92a6e89 into magento:develop Feb 25, 2017
@okorshenko
Copy link
Contributor

@rossluk thank you for your contribution! PR has been merged to develop branch!
@orlangur thank you for review and your feedback.
@sdzhepa great job on testing of this solution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants