Skip to content

Commit 783e115

Browse files
author
Maksym Aposov
committed
MAGETWO-44737: Tax applied twice for configurable product on product and catalog pages
1 parent dc3aee6 commit 783e115

File tree

4 files changed

+91
-11
lines changed

4 files changed

+91
-11
lines changed

app/code/Magento/ConfigurableProduct/Pricing/Price/FinalPriceResolver.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace Magento\ConfigurableProduct\Pricing\Price;
88

9+
use Magento\Catalog\Pricing\Price\FinalPrice as CatalogFinalPrice;
10+
911
class FinalPriceResolver implements PriceResolverInterface
1012
{
1113
/**
@@ -14,7 +16,7 @@ class FinalPriceResolver implements PriceResolverInterface
1416
*/
1517
public function resolvePrice(\Magento\Framework\Pricing\SaleableInterface $product)
1618
{
17-
return $product->getPriceInfo()->getPrice(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE)
18-
->getAmount()->getValue();
19+
return $product->getPriceInfo()->getPrice(CatalogFinalPrice::PRICE_CODE)
20+
->getAmount()->getBaseAmount();
1921
}
2022
}

dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/Type/Configurable/PriceTest.php

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,66 @@
55
*/
66
namespace Magento\ConfigurableProduct\Model\Product\Type\Configurable;
77

8+
/**
9+
* @magentoDbIsolation enabled
10+
* @magentoDataFixture Magento/ConfigurableProduct/_files/tax_rule.php
11+
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
12+
*/
813
class PriceTest extends \PHPUnit_Framework_TestCase
914
{
1015
/**
11-
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
16+
*
1217
*/
1318
public function testGetFinalPrice()
1419
{
20+
$this->validatePrice(10);
21+
}
22+
23+
/**
24+
* @magentoConfigFixture current_store tax/display/type 1
25+
*/
26+
public function testGetFinalPriceExcludingTax()
27+
{
28+
$this->validatePrice(10);
29+
}
30+
31+
/**
32+
* @magentoConfigFixture current_store tax/display/type 2
33+
*/
34+
public function testGetFinalPriceIncludingTax()
35+
{
36+
//lowest price of configurable variation + 10%
37+
$this->validatePrice(11);
38+
}
39+
40+
/**
41+
* @magentoConfigFixture current_store tax/display/type 3
42+
*/
43+
public function testGetFinalPriceIncludingExcludingTax()
44+
{
45+
//lowest price of configurable variation + 10%
46+
$this->validatePrice(11);
47+
}
48+
49+
/**
50+
* Test
51+
*
52+
* @param $expectedPrice
53+
*/
54+
protected function validatePrice($expectedPrice)
55+
{
56+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
57+
1558
/** @var $product \Magento\Catalog\Model\Product */
16-
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
17-
'Magento\Catalog\Model\Product'
18-
);
59+
$product = $objectManager->create('Magento\Catalog\Model\Product');
1960
$product->load(1);
20-
// fixture
2161

2262
/** @var $model \Magento\ConfigurableProduct\Model\Product\Type\Configurable\Price */
23-
$model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
63+
$model = $objectManager->create(
2464
'Magento\ConfigurableProduct\Model\Product\Type\Configurable\Price'
2565
);
2666

2767
// final price is the lowest price of configurable variations
28-
$this->assertEquals(10, $model->getFinalPrice(1, $product));
68+
$this->assertEquals(round($expectedPrice, 2), round($model->getFinalPrice(1, $product), 2));
2969
}
3070
}

dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
->setWebsiteIds([1])
2929
->setName('Configurable Option' . $option->getLabel())
3030
->setSku('simple_' . $productId)
31-
->setPrice(10)
31+
->setPrice($productId)
3232
->setTestConfigurable($option->getValue())
3333
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE)
3434
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
@@ -51,7 +51,6 @@
5151
->setWebsiteIds([1])
5252
->setName('Configurable Product')
5353
->setSku('configurable')
54-
->setPrice(100)
5554
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
5655
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
5756
->setStockData(['use_config_manage_stock' => 1, 'is_in_stock' => 1])
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/** @var $objectManager \Magento\TestFramework\ObjectManager */
8+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
9+
$customerTaxClass = $objectManager->create('Magento\Tax\Model\ClassModel')->load('Retail Customer', 'class_name');
10+
$productTaxClass1 = $objectManager->create('Magento\Tax\Model\ClassModel')->load('Taxable Goods', 'class_name');
11+
12+
13+
$taxRate = [
14+
'tax_country_id' => 'US',
15+
'tax_region_id' => '0',
16+
'tax_postcode' => '*',
17+
'code' => '*',
18+
'rate' => '10',
19+
];
20+
$rate = $objectManager->create('Magento\Tax\Model\Calculation\Rate')->setData($taxRate)->save();
21+
22+
/** @var Magento\Framework\Registry $registry */
23+
$registry = $objectManager->get('Magento\Framework\Registry');
24+
$registry->unregister('_fixture/Magento_Tax_Model_Calculation_Rate');
25+
$registry->register('_fixture/Magento_Tax_Model_Calculation_Rate', $rate);
26+
27+
$ruleData = [
28+
'code' => 'Test Rule',
29+
'priority' => '0',
30+
'position' => '0',
31+
'customer_tax_class_ids' => [$customerTaxClass->getId()],
32+
'product_tax_class_ids' => [$productTaxClass1->getId()],
33+
'tax_rate_ids' => [$rate->getId()],
34+
];
35+
36+
$taxRule = $objectManager->create('Magento\Tax\Model\Calculation\Rule')->setData($ruleData)->save();
37+
38+
$registry->unregister('_fixture/Magento_Tax_Model_Calculation_Rule');
39+
$registry->register('_fixture/Magento_Tax_Model_Calculation_Rule', $taxRule);

0 commit comments

Comments
 (0)