Skip to content

Commit d739b47

Browse files
committed
Merge branch 'develop' into FearlessKiwis-MAGETWO-59718
2 parents 8aedf83 + 9b9c992 commit d739b47

File tree

25 files changed

+649
-234
lines changed

25 files changed

+649
-234
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
}

app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundlePanel.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Magento\Ui\Component\DynamicRows;
1515
use Magento\Ui\Component\Form;
1616
use Magento\Ui\Component\Modal;
17+
use Magento\Catalog\Api\Data\ProductAttributeInterface;
18+
use Magento\Catalog\Model\Config\Source\ProductPriceOptionsInterface;
1719

1820
/**
1921
* Create Ship Bundle Items and Affect Bundle Product Selections fields
@@ -73,6 +75,7 @@ public function __construct(
7375
*/
7476
public function modifyMeta(array $meta)
7577
{
78+
$meta = $this->removeFixedTierPrice($meta);
7679
$path = $this->arrayManager->findPath(static::CODE_BUNDLE_DATA, $meta, null, 'children');
7780

7881
$meta = $this->arrayManager->merge(
@@ -178,6 +181,43 @@ public function modifyMeta(array $meta)
178181
return $meta;
179182
}
180183

184+
/**
185+
* Remove option with fixed tier price from config.
186+
*
187+
* @param array $meta
188+
* @return array
189+
*/
190+
private function removeFixedTierPrice(array $meta)
191+
{
192+
$tierPricePath = $this->arrayManager->findPath(
193+
ProductAttributeInterface::CODE_TIER_PRICE,
194+
$meta,
195+
null,
196+
'children'
197+
);
198+
$pricePath = $this->arrayManager->findPath(
199+
ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE,
200+
$meta,
201+
$tierPricePath
202+
);
203+
$pricePath = $this->arrayManager->slicePath($pricePath, 0, -1) . '/value_type/arguments/data/options';
204+
205+
$price = $this->arrayManager->get($pricePath, $meta);
206+
$meta = $this->arrayManager->remove($pricePath, $meta);
207+
foreach ($price as $key => $item) {
208+
if ($item['value'] == ProductPriceOptionsInterface::VALUE_FIXED) {
209+
unset($price[$key]);
210+
}
211+
}
212+
$meta = $this->arrayManager->merge(
213+
$this->arrayManager->slicePath($pricePath, 0, -1),
214+
$meta,
215+
['options' => $price]
216+
);
217+
218+
return $meta;
219+
}
220+
181221
/**
182222
* {@inheritdoc}
183223
*/

app/code/Magento/Bundle/etc/adminhtml/di.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
<argument name="modifiers" xsi:type="array">
2828
<item name="bundle" xsi:type="array">
2929
<item name="class" xsi:type="string">Magento\Bundle\Ui\DataProvider\Product\Form\Modifier\Composite</item>
30-
<item name="sortOrder" xsi:type="number">125</item>
30+
<item name="sortOrder" xsi:type="number">180</item>
3131
</item>
3232
<item name="bundle_stock_data" xsi:type="array">
3333
<item name="class" xsi:type="string">Magento\Bundle\Ui\DataProvider\Product\Form\Modifier\StockData</item>
34-
<item name="sortOrder" xsi:type="number">126</item>
34+
<item name="sortOrder" xsi:type="number">190</item>
3535
</item>
3636
</argument>
3737
</arguments>

app/code/Magento/Bundle/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,5 @@
130130
</argument>
131131
</arguments>
132132
</type>
133+
133134
</config>

app/code/Magento/Bundle/view/base/templates/product/price/tier_prices.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ $tierPrices = $tierPriceModel->getTierPriceList();
2222
<?php /* @escapeNotVerified */ echo __(
2323
'Buy %1 with %2 discount each',
2424
$price['price_qty'],
25-
'<strong class="benefit">' . $tierPriceModel->getSavePercent($price['price']) . '%</strong>'
25+
'<strong class="benefit">' . round($price['percentage_value']) . '%</strong>'
2626
); ?>
2727
</li>
2828
<?php endforeach; ?>

app/code/Magento/Catalog/Model/Config/Source/Product/Options/Price.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function toOptionArray()
2323
{
2424
return [
2525
['value' => self::VALUE_FIXED, 'label' => __('Fixed')],
26-
['value' => self::VALUE_PERCENT, 'label' => __('Percent')],
26+
['value' => self::VALUE_PERCENT, 'label' => __('Discount')],
2727
];
2828
}
2929
}

app/code/Magento/Catalog/Model/Product/Attribute/Backend/Tierprice.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ protected function modifyPriceData($object, $data)
157157
$data = parent::modifyPriceData($object, $data);
158158
foreach ($data as $key => $tierPrice) {
159159
if ($this->getPercentage($tierPrice)) {
160+
$data[$key]['price'] = $object->getPrice() * (1 - $this->getPercentage($tierPrice) / 100);
160161
$data[$key]['website_price'] = $object->getPrice() * (1 - $this->getPercentage($tierPrice) / 100);
161162
}
162163
}

0 commit comments

Comments
 (0)