Skip to content

Commit 3af1d10

Browse files
committed
MAGETWO-61557: Tier Price Management fix
1 parent 4f38525 commit 3af1d10

File tree

7 files changed

+71
-36
lines changed

7 files changed

+71
-36
lines changed

app/code/Magento/Bundle/Model/Product/Price.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,10 @@ public function getTierPrice($qty, $product)
533533
$prevGroup = $allCustomersGroupId;
534534

535535
foreach ($prices as $price) {
536+
if (empty($price['percentage_value'])) {
537+
// can use only percentage tier price
538+
continue;
539+
}
536540
if ($price['cust_group'] != $custGroup && $price['cust_group'] != $allCustomersGroupId) {
537541
// tier not for current customer group nor is for all groups
538542
continue;
@@ -553,8 +557,8 @@ public function getTierPrice($qty, $product)
553557
continue;
554558
}
555559

556-
if ($price['website_price'] > $prevPrice) {
557-
$prevPrice = $price['website_price'];
560+
if ($price['percentage_value'] > $prevPrice) {
561+
$prevPrice = $price['percentage_value'];
558562
$prevQty = $price['price_qty'];
559563
$prevGroup = $price['cust_group'];
560564
}

app/code/Magento/Bundle/Pricing/Price/TierPrice.php

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Magento\Catalog\Pricing\Price\RegularPrice;
1010
use Magento\Framework\Pricing\Amount\AmountInterface;
11+
use Magento\Framework\Pricing\PriceInfoInterface;
1112

1213
/**
1314
* Bundle tier prices model
@@ -32,8 +33,25 @@ class TierPrice extends \Magento\Catalog\Pricing\Price\TierPrice implements Disc
3233
public function getDiscountPercent()
3334
{
3435
if ($this->percent === null) {
35-
$percent = parent::getValue();
36-
$this->percent = ($percent) ? max(0, min(100, 100 - $percent)) : null;
36+
$prices = $this->getStoredTierPrices();
37+
$prevQty = PriceInfoInterface::PRODUCT_QUANTITY_DEFAULT;
38+
$this->value = $prevPrice = false;
39+
$priceGroup = $this->groupManagement->getAllCustomersGroup()->getId();
40+
41+
foreach ($prices as $price) {
42+
if (!$this->canApplyTierPrice($price, $priceGroup, $prevQty)
43+
|| !isset($price['percentage_value'])
44+
|| !is_numeric($price['percentage_value'])
45+
) {
46+
continue;
47+
}
48+
if (false === $prevPrice || $this->isFirstPriceBetter($price['website_price'], $prevPrice)) {
49+
$prevPrice = $price['website_price'];
50+
$prevQty = $price['price_qty'];
51+
$priceGroup = $price['cust_group'];
52+
$this->percent = max(0, min(100, 100 - $price['percentage_value']));
53+
}
54+
}
3755
}
3856
return $this->percent;
3957
}
@@ -90,13 +108,4 @@ public function isPercentageDiscount()
90108
{
91109
return true;
92110
}
93-
94-
/**
95-
* @param AmountInterface $amount
96-
* @return float
97-
*/
98-
public function getSavePercent(AmountInterface $amount)
99-
{
100-
return round($amount->getBaseAmount());
101-
}
102111
}

app/code/Magento/Bundle/Test/Unit/Model/Product/PriceTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ protected function setUp()
9090
false
9191
);
9292
$scopeConfig = $this->getMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
93-
9493
$objectManagerHelper = new ObjectManagerHelper($this);
9594
$this->model = $objectManagerHelper->getObject(
9695
\Magento\Bundle\Model\Product\Price::class,
@@ -191,7 +190,6 @@ public function testGetTotalBundleItemsPriceWithEmptyOptions($value)
191190
$dataObjectMock->expects($this->once())
192191
->method('getValue')
193192
->willReturn($value);
194-
195193
$this->assertEquals(0, $this->model->getTotalBundleItemsPrice($productMock));
196194
}
197195

@@ -245,7 +243,6 @@ public function testGetTotalBundleItemsPriceWithNoItems()
245243
$dataObjectMock->expects($this->once())
246244
->method('getValue')
247245
->willReturn('a:1:{i:0;s:1:"1";}');
248-
249246
$productTypeMock->expects($this->once())
250247
->method('getSelectionsByIds')
251248
->with([1], $productMock)

app/code/Magento/Bundle/Test/Unit/Pricing/Price/TierPriceTest.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,17 @@ public function providerForGetterTierPriceList()
188188
*/
189189
public function testGetSavePercent($baseAmount, $savePercent)
190190
{
191+
$basePrice = 10.;
191192
$amount = $this->getMockForAbstractClass(\Magento\Framework\Pricing\Amount\AmountInterface::class);
192193
$amount->expects($this->once())->method('getBaseAmount')->willReturn($baseAmount);
194+
$price = $this->getMock(\Magento\Framework\Pricing\Price\PriceInterface::class);
195+
$price->expects($this->any())
196+
->method('getValue')
197+
->will($this->returnValue($basePrice));
193198

199+
$this->priceInfo->expects($this->any())
200+
->method('getPrice')
201+
->will($this->returnValue($price));
194202
$this->assertEquals($savePercent, $this->model->getSavePercent($amount));
195203
}
196204

@@ -200,10 +208,8 @@ public function testGetSavePercent($baseAmount, $savePercent)
200208
public function providerForTestGetSavePercent()
201209
{
202210
return [
203-
'no fraction' => [10.0000, 10],
204-
'lower half' => [10.1234, 10],
205-
'half way' => [10.5000, 11],
206-
'upper half' => [10.6789, 11],
211+
'no fraction' => [9.0000, 10],
212+
'lower half' => [9.1234, 9],
207213
];
208214
}
209215
}

dev/tests/integration/testsuite/Magento/Bundle/Model/Product/DynamicBundleWithTierPriceCalculatorTest.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ private function getBundleConfiguration1()
201201
$tierPriceData = [
202202
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
203203
'qty' => 1,
204-
'value' => 50
204+
'value' => 50,
205+
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
205206
];
206207

207208
return [
@@ -239,7 +240,8 @@ private function getBundleConfiguration2()
239240
$tierPriceData = [
240241
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
241242
'qty' => 1,
242-
'value' => 50
243+
'value' => 50,
244+
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
243245
];
244246

245247
return [
@@ -281,7 +283,8 @@ private function getBundleConfiguration3()
281283
$tierPriceData = [
282284
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
283285
'qty' => 1,
284-
'value' => 50
286+
'value' => 50,
287+
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
285288
];
286289

287290
return [
@@ -323,7 +326,8 @@ private function getBundleConfiguration4()
323326
$tierPriceData = [
324327
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
325328
'qty' => 1,
326-
'value' => 50
329+
'value' => 50,
330+
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
327331
];
328332

329333
return [
@@ -365,7 +369,8 @@ private function getBundleConfiguration5()
365369
$tierPriceData = [
366370
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
367371
'qty' => 1,
368-
'value' => 50
372+
'value' => 50,
373+
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
369374
];
370375

371376
return [
@@ -422,7 +427,8 @@ private function getBundleConfiguration6()
422427
$tierPriceData = [
423428
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
424429
'qty' => 1,
425-
'value' => 50
430+
'value' => 50,
431+
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
426432
];
427433

428434
return [
@@ -479,7 +485,8 @@ private function getBundleConfiguration7()
479485
$tierPriceData = [
480486
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
481487
'qty' => 1,
482-
'value' => 50
488+
'value' => 50,
489+
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
483490
];
484491

485492
return [
@@ -536,7 +543,8 @@ private function getBundleConfiguration8()
536543
$tierPriceData = [
537544
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
538545
'qty' => 1,
539-
'value' => 50
546+
'value' => 50,
547+
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
540548
];
541549

542550
return [
@@ -578,7 +586,8 @@ private function getBundleConfiguration9()
578586
$tierPriceData = [
579587
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
580588
'qty' => 1,
581-
'value' => 50
589+
'value' => 50,
590+
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
582591
];
583592

584593
$tierPriceSimpleProductData = [

dev/tests/integration/testsuite/Magento/Bundle/Model/Product/FixedBundleWithTierPriceCalculatorTest.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,8 @@ private function getBundleConfiguration1()
495495
$tierPriceData = [
496496
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
497497
'qty' => 1,
498-
'value' => 50
498+
'value' => 50,
499+
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
499500
];
500501

501502
return [
@@ -544,7 +545,8 @@ private function getProductConfiguration2($selectionsPriceType, $customOptionsPr
544545
$tierPriceData = [
545546
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
546547
'qty' => 1,
547-
'value' => 50
548+
'value' => 50,
549+
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
548550
];
549551

550552
return [
@@ -601,7 +603,8 @@ private function getProductConfiguration3($selectionsPriceType, $customOptionsPr
601603
$tierPriceData = [
602604
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
603605
'qty' => 1,
604-
'value' => 50
606+
'value' => 50,
607+
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
605608
];
606609

607610
return [
@@ -664,7 +667,8 @@ private function getProductConfiguration4($selectionsPriceType, $customOptionsPr
664667
$tierPriceData = [
665668
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
666669
'qty' => 1,
667-
'value' => 50
670+
'value' => 50,
671+
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
668672
];
669673

670674
return [
@@ -727,7 +731,8 @@ private function getProductConfiguration5($selectionsPriceType, $customOptionsPr
727731
$tierPriceData = [
728732
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
729733
'qty' => 1,
730-
'value' => 50
734+
'value' => 50,
735+
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
731736
];
732737

733738
return [
@@ -790,7 +795,8 @@ private function getProductConfiguration6($selectionsPriceType, $customOptionsPr
790795
$tierPriceData = [
791796
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
792797
'qty' => 1,
793-
'value' => 50
798+
'value' => 50,
799+
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
794800
];
795801

796802
return [
@@ -872,7 +878,8 @@ private function getProductConfiguration7($selectionsPriceType, $customOptionsPr
872878
$tierPriceData = [
873879
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
874880
'qty' => 1,
875-
'value' => 50
881+
'value' => 50,
882+
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
876883
];
877884

878885
return [

dev/tests/integration/testsuite/Magento/Bundle/_files/product_with_tier_pricing.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,21 @@
4141
'cust_group' => \Magento\Customer\Model\GroupManagement::CUST_GROUP_ALL,
4242
'price_qty' => 2,
4343
'price' => 8,
44+
'percentage_value' => 8
4445
],
4546
[
4647
'website_id' => 0,
4748
'cust_group' => \Magento\Customer\Model\GroupManagement::CUST_GROUP_ALL,
4849
'price_qty' => 5,
4950
'price' => 30,
51+
'percentage_value' => 30
5052
],
5153
[
5254
'website_id' => 0,
5355
'cust_group' => \Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID,
5456
'price_qty' => 3,
5557
'price' => 20,
58+
'percentage_value' => 20
5659
],
5760
]
5861
)

0 commit comments

Comments
 (0)