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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ public function getValue()
$this->product->getId()
);
$this->value = $this->value ? floatval($this->value) : false;
if ($this->value) {
$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.

$this->value = $this->priceCurrency->convertAndRound($this->value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,20 @@ public function testGetValue()

public function testGetValueFromData()
{
$catalogRulePrice = 7.1;
$convertedPrice = 5.84;

$this->priceCurrencyMock->expects($this->any())
->method('convertAndRound')
->with($catalogRulePrice)
->will($this->returnValue($convertedPrice));

$this->saleableItemMock->expects($this->once())->method('hasData')
->with('catalog_rule_price')->willReturn(true);
$this->saleableItemMock->expects($this->once())->method('getData')
->with('catalog_rule_price')->willReturn('7.1');
->with('catalog_rule_price')->willReturn($catalogRulePrice);

$this->assertEquals(7.1, $this->object->getValue());
$this->assertEquals($convertedPrice, $this->object->getValue());
}

public function testGetAmountNoBaseAmount()
Expand Down