diff --git a/app/code/Magento/Bundle/Model/Product/Price.php b/app/code/Magento/Bundle/Model/Product/Price.php index 83bfcbbabc2536ab0ee2f84525dcb4cca12aa883..d0aee24945f9d21df7c3d73350093206065b0429 100644 --- a/app/code/Magento/Bundle/Model/Product/Price.php +++ b/app/code/Magento/Bundle/Model/Product/Price.php @@ -533,6 +533,10 @@ class Price extends \Magento\Catalog\Model\Product\Type\Price $prevGroup = $allCustomersGroupId; foreach ($prices as $price) { + if (empty($price['percentage_value'])) { + // can use only percentage tier price + continue; + } if ($price['cust_group'] != $custGroup && $price['cust_group'] != $allCustomersGroupId) { // tier not for current customer group nor is for all groups continue; @@ -553,8 +557,8 @@ class Price extends \Magento\Catalog\Model\Product\Type\Price continue; } - if ($price['website_price'] > $prevPrice) { - $prevPrice = $price['website_price']; + if ($price['percentage_value'] > $prevPrice) { + $prevPrice = $price['percentage_value']; $prevQty = $price['price_qty']; $prevGroup = $price['cust_group']; } diff --git a/app/code/Magento/Bundle/Pricing/Price/TierPrice.php b/app/code/Magento/Bundle/Pricing/Price/TierPrice.php index cbbf45e2dbb5f01187760b73f96c251fae49c1c5..fab49292d9bdea9f2ee02e1762385b979e15bdb0 100644 --- a/app/code/Magento/Bundle/Pricing/Price/TierPrice.php +++ b/app/code/Magento/Bundle/Pricing/Price/TierPrice.php @@ -8,6 +8,7 @@ namespace Magento\Bundle\Pricing\Price; use Magento\Catalog\Pricing\Price\RegularPrice; use Magento\Framework\Pricing\Amount\AmountInterface; +use Magento\Framework\Pricing\PriceInfoInterface; /** * Bundle tier prices model @@ -32,8 +33,25 @@ class TierPrice extends \Magento\Catalog\Pricing\Price\TierPrice implements Disc public function getDiscountPercent() { if ($this->percent === null) { - $percent = parent::getValue(); - $this->percent = ($percent) ? max(0, min(100, 100 - $percent)) : null; + $prices = $this->getStoredTierPrices(); + $prevQty = PriceInfoInterface::PRODUCT_QUANTITY_DEFAULT; + $this->value = $prevPrice = false; + $priceGroup = $this->groupManagement->getAllCustomersGroup()->getId(); + + foreach ($prices as $price) { + if (!$this->canApplyTierPrice($price, $priceGroup, $prevQty) + || !isset($price['percentage_value']) + || !is_numeric($price['percentage_value']) + ) { + continue; + } + if (false === $prevPrice || $this->isFirstPriceBetter($price['website_price'], $prevPrice)) { + $prevPrice = $price['website_price']; + $prevQty = $price['price_qty']; + $priceGroup = $price['cust_group']; + $this->percent = max(0, min(100, 100 - $price['percentage_value'])); + } + } } return $this->percent; } @@ -90,13 +108,4 @@ class TierPrice extends \Magento\Catalog\Pricing\Price\TierPrice implements Disc { return true; } - - /** - * @param AmountInterface $amount - * @return float - */ - public function getSavePercent(AmountInterface $amount) - { - return round($amount->getBaseAmount()); - } } diff --git a/app/code/Magento/Bundle/Test/Unit/Model/Product/PriceTest.php b/app/code/Magento/Bundle/Test/Unit/Model/Product/PriceTest.php index e97f0bbc1558dc3c63e02ef2c894b0d4423a61b2..9f7952e7ae8c882a5b747f9fd24855feea7c380e 100644 --- a/app/code/Magento/Bundle/Test/Unit/Model/Product/PriceTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Model/Product/PriceTest.php @@ -90,7 +90,6 @@ class PriceTest extends \PHPUnit_Framework_TestCase false ); $scopeConfig = $this->getMock(\Magento\Framework\App\Config\ScopeConfigInterface::class); - $objectManagerHelper = new ObjectManagerHelper($this); $this->model = $objectManagerHelper->getObject( \Magento\Bundle\Model\Product\Price::class, @@ -191,7 +190,6 @@ class PriceTest extends \PHPUnit_Framework_TestCase $dataObjectMock->expects($this->once()) ->method('getValue') ->willReturn($value); - $this->assertEquals(0, $this->model->getTotalBundleItemsPrice($productMock)); } @@ -245,7 +243,6 @@ class PriceTest extends \PHPUnit_Framework_TestCase $dataObjectMock->expects($this->once()) ->method('getValue') ->willReturn('a:1:{i:0;s:1:"1";}'); - $productTypeMock->expects($this->once()) ->method('getSelectionsByIds') ->with([1], $productMock) diff --git a/app/code/Magento/Bundle/Test/Unit/Pricing/Price/TierPriceTest.php b/app/code/Magento/Bundle/Test/Unit/Pricing/Price/TierPriceTest.php index 7b1f6181bb6f8ddc5951ce69e7564b7e2d1b1536..15bc06c2c6437d450ca480479b08a2cf1900d0de 100644 --- a/app/code/Magento/Bundle/Test/Unit/Pricing/Price/TierPriceTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Pricing/Price/TierPriceTest.php @@ -188,9 +188,17 @@ class TierPriceTest extends \PHPUnit_Framework_TestCase */ public function testGetSavePercent($baseAmount, $savePercent) { + $basePrice = 10.; $amount = $this->getMockForAbstractClass(\Magento\Framework\Pricing\Amount\AmountInterface::class); $amount->expects($this->once())->method('getBaseAmount')->willReturn($baseAmount); + $price = $this->getMock(\Magento\Framework\Pricing\Price\PriceInterface::class); + $price->expects($this->any()) + ->method('getValue') + ->will($this->returnValue($basePrice)); + $this->priceInfo->expects($this->any()) + ->method('getPrice') + ->will($this->returnValue($price)); $this->assertEquals($savePercent, $this->model->getSavePercent($amount)); } @@ -200,10 +208,8 @@ class TierPriceTest extends \PHPUnit_Framework_TestCase public function providerForTestGetSavePercent() { return [ - 'no fraction' => [10.0000, 10], - 'lower half' => [10.1234, 10], - 'half way' => [10.5000, 11], - 'upper half' => [10.6789, 11], + 'no fraction' => [9.0000, 10], + 'lower half' => [9.1234, 9], ]; } } diff --git a/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/DynamicBundleWithTierPriceCalculatorTest.php b/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/DynamicBundleWithTierPriceCalculatorTest.php index 0be5adcb304f772218e588795f3f6ef26ce0721c..c2c62aa2ce093e3b52502ec5c234d3932cdbe3b4 100644 --- a/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/DynamicBundleWithTierPriceCalculatorTest.php +++ b/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/DynamicBundleWithTierPriceCalculatorTest.php @@ -201,7 +201,8 @@ class DynamicBundleWithTierPriceCalculatorTest extends BundlePriceAbstract $tierPriceData = [ 'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID, 'qty' => 1, - 'value' => 50 + 'value' => 50, + 'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50]) ]; return [ @@ -239,7 +240,8 @@ class DynamicBundleWithTierPriceCalculatorTest extends BundlePriceAbstract $tierPriceData = [ 'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID, 'qty' => 1, - 'value' => 50 + 'value' => 50, + 'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50]) ]; return [ @@ -281,7 +283,8 @@ class DynamicBundleWithTierPriceCalculatorTest extends BundlePriceAbstract $tierPriceData = [ 'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID, 'qty' => 1, - 'value' => 50 + 'value' => 50, + 'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50]) ]; return [ @@ -323,7 +326,8 @@ class DynamicBundleWithTierPriceCalculatorTest extends BundlePriceAbstract $tierPriceData = [ 'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID, 'qty' => 1, - 'value' => 50 + 'value' => 50, + 'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50]) ]; return [ @@ -365,7 +369,8 @@ class DynamicBundleWithTierPriceCalculatorTest extends BundlePriceAbstract $tierPriceData = [ 'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID, 'qty' => 1, - 'value' => 50 + 'value' => 50, + 'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50]) ]; return [ @@ -422,7 +427,8 @@ class DynamicBundleWithTierPriceCalculatorTest extends BundlePriceAbstract $tierPriceData = [ 'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID, 'qty' => 1, - 'value' => 50 + 'value' => 50, + 'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50]) ]; return [ @@ -479,7 +485,8 @@ class DynamicBundleWithTierPriceCalculatorTest extends BundlePriceAbstract $tierPriceData = [ 'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID, 'qty' => 1, - 'value' => 50 + 'value' => 50, + 'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50]) ]; return [ @@ -536,7 +543,8 @@ class DynamicBundleWithTierPriceCalculatorTest extends BundlePriceAbstract $tierPriceData = [ 'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID, 'qty' => 1, - 'value' => 50 + 'value' => 50, + 'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50]) ]; return [ @@ -578,7 +586,8 @@ class DynamicBundleWithTierPriceCalculatorTest extends BundlePriceAbstract $tierPriceData = [ 'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID, 'qty' => 1, - 'value' => 50 + 'value' => 50, + 'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50]) ]; $tierPriceSimpleProductData = [ diff --git a/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/FixedBundleWithTierPriceCalculatorTest.php b/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/FixedBundleWithTierPriceCalculatorTest.php index bd148080631aea892cccb0fab6fd0321d08c231b..aa020fe1f5a2b89e6d1e1eb922c0dee8412f4de7 100644 --- a/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/FixedBundleWithTierPriceCalculatorTest.php +++ b/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/FixedBundleWithTierPriceCalculatorTest.php @@ -495,7 +495,8 @@ class FixedBundleWithTierPriceCalculatorTest extends BundlePriceAbstract $tierPriceData = [ 'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID, 'qty' => 1, - 'value' => 50 + 'value' => 50, + 'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50]) ]; return [ @@ -544,7 +545,8 @@ class FixedBundleWithTierPriceCalculatorTest extends BundlePriceAbstract $tierPriceData = [ 'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID, 'qty' => 1, - 'value' => 50 + 'value' => 50, + 'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50]) ]; return [ @@ -601,7 +603,8 @@ class FixedBundleWithTierPriceCalculatorTest extends BundlePriceAbstract $tierPriceData = [ 'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID, 'qty' => 1, - 'value' => 50 + 'value' => 50, + 'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50]) ]; return [ @@ -664,7 +667,8 @@ class FixedBundleWithTierPriceCalculatorTest extends BundlePriceAbstract $tierPriceData = [ 'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID, 'qty' => 1, - 'value' => 50 + 'value' => 50, + 'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50]) ]; return [ @@ -727,7 +731,8 @@ class FixedBundleWithTierPriceCalculatorTest extends BundlePriceAbstract $tierPriceData = [ 'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID, 'qty' => 1, - 'value' => 50 + 'value' => 50, + 'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50]) ]; return [ @@ -790,7 +795,8 @@ class FixedBundleWithTierPriceCalculatorTest extends BundlePriceAbstract $tierPriceData = [ 'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID, 'qty' => 1, - 'value' => 50 + 'value' => 50, + 'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50]) ]; return [ @@ -872,7 +878,8 @@ class FixedBundleWithTierPriceCalculatorTest extends BundlePriceAbstract $tierPriceData = [ 'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID, 'qty' => 1, - 'value' => 50 + 'value' => 50, + 'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50]) ]; return [ diff --git a/dev/tests/integration/testsuite/Magento/Bundle/_files/product_with_tier_pricing.php b/dev/tests/integration/testsuite/Magento/Bundle/_files/product_with_tier_pricing.php index 6d6d10ce4d220fc45047d140621a784ea44413c6..9574948dae900e292e38d55a306d4a7fe8706955 100644 --- a/dev/tests/integration/testsuite/Magento/Bundle/_files/product_with_tier_pricing.php +++ b/dev/tests/integration/testsuite/Magento/Bundle/_files/product_with_tier_pricing.php @@ -41,18 +41,21 @@ $product->setTypeId('bundle') 'cust_group' => \Magento\Customer\Model\GroupManagement::CUST_GROUP_ALL, 'price_qty' => 2, 'price' => 8, + 'percentage_value' => 8 ], [ 'website_id' => 0, 'cust_group' => \Magento\Customer\Model\GroupManagement::CUST_GROUP_ALL, 'price_qty' => 5, 'price' => 30, + 'percentage_value' => 30 ], [ 'website_id' => 0, 'cust_group' => \Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID, 'price_qty' => 3, 'price' => 20, + 'percentage_value' => 20 ], ] )