Skip to content

Commit 84a3c1a

Browse files
committed
Merge remote-tracking branch 'origin/2.3-develop' into MC-20070
2 parents e005d8c + 03dd86e commit 84a3c1a

File tree

48 files changed

+2159
-327
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2159
-327
lines changed

app/code/Magento/Bundle/Test/Unit/Ui/DataProvider/Product/Form/Modifier/AbstractModifierTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ protected function setUp()
4545
$this->locatorMock = $this->getMockBuilder(LocatorInterface::class)
4646
->getMockForAbstractClass();
4747
$this->productMock = $this->getMockBuilder(ProductInterface::class)
48+
->setMethods(['getPriceType'])
4849
->getMockForAbstractClass();
4950

5051
$this->locatorMock->expects($this->any())
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Bundle\Test\Unit\Ui\DataProvider\Product\Form\Modifier;
7+
8+
use Magento\Bundle\Ui\DataProvider\Product\Form\Modifier\BundlePrice;
9+
use Magento\Catalog\Api\Data\ProductAttributeInterface;
10+
use Magento\Framework\Stdlib\ArrayManager;
11+
12+
class BundlePriceTest extends AbstractModifierTest
13+
{
14+
/**
15+
* @return BundlePrice
16+
*/
17+
protected function createModel()
18+
{
19+
return $this->objectManager->getObject(
20+
BundlePrice::class,
21+
[
22+
'locator' => $this->locatorMock,
23+
'arrayManager' => $this->arrayManagerMock
24+
]
25+
);
26+
}
27+
28+
/**
29+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
30+
*/
31+
public function testModifyMeta()
32+
{
33+
$this->productMock->expects($this->any())
34+
->method('getId')
35+
->willReturn(true);
36+
$this->productMock->expects($this->any())
37+
->method('getPriceType')
38+
->willReturn(0);
39+
$priceTypePath = 'bundle-items/children/' . BundlePrice::CODE_PRICE_TYPE;
40+
$priceTypeConfigPath = $priceTypePath . BundlePrice::META_CONFIG_PATH;
41+
$pricePath = 'product-details/children/' . ProductAttributeInterface::CODE_PRICE;
42+
$priceConfigPath = $pricePath . BundlePrice::META_CONFIG_PATH;
43+
$sourceMeta = [
44+
'bundle-items' => [
45+
'children' => [
46+
BundlePrice::CODE_PRICE_TYPE => []
47+
]
48+
]
49+
];
50+
$priceTypeParams = [
51+
'disabled' => true,
52+
'valueMap' => [
53+
'false' => '1',
54+
'true' => '0'
55+
],
56+
'validation' => [
57+
'required-entry' => false
58+
]
59+
];
60+
$priceTypeMeta = [
61+
'bundle-items' => [
62+
'children' => [
63+
BundlePrice::CODE_PRICE_TYPE => $priceTypeParams
64+
]
65+
]
66+
];
67+
$priceParams = [
68+
'imports' => [
69+
'disabled' => 'ns = ${ $.ns }, index = ' . BundlePrice::CODE_PRICE_TYPE . ':checked'
70+
]
71+
];
72+
$priceMeta = [
73+
'product-details' => [
74+
'children' => [
75+
BundlePrice::CODE_PRICE_TYPE => []
76+
]
77+
],
78+
'bundle-items' => [
79+
'children' => [
80+
ProductAttributeInterface::CODE_PRICE => $priceParams
81+
]
82+
]
83+
];
84+
$taxParams = [
85+
'service' => [
86+
'template' => ''
87+
]
88+
];
89+
90+
$this->arrayManagerMock->expects(static::any())
91+
->method('findPath')
92+
->willReturnMap(
93+
[
94+
[
95+
BundlePrice::CODE_PRICE_TYPE,
96+
$sourceMeta,
97+
null,
98+
'children',
99+
ArrayManager::DEFAULT_PATH_DELIMITER,
100+
$priceTypePath
101+
],
102+
[
103+
ProductAttributeInterface::CODE_PRICE,
104+
$priceTypeMeta,
105+
BundlePrice::DEFAULT_GENERAL_PANEL . '/children',
106+
'children',
107+
ArrayManager::DEFAULT_PATH_DELIMITER,
108+
$pricePath
109+
],
110+
[
111+
BundlePrice::CODE_TAX_CLASS_ID,
112+
$priceMeta,
113+
null,
114+
'children',
115+
ArrayManager::DEFAULT_PATH_DELIMITER,
116+
$pricePath
117+
],
118+
[
119+
BundlePrice::CODE_TAX_CLASS_ID,
120+
$priceMeta,
121+
null,
122+
'children',
123+
ArrayManager::DEFAULT_PATH_DELIMITER,
124+
$pricePath
125+
]
126+
]
127+
);
128+
$this->arrayManagerMock->expects($this->exactly(4))
129+
->method('merge')
130+
->willReturnMap(
131+
[
132+
[
133+
$priceTypeConfigPath,
134+
$sourceMeta,
135+
$priceTypeParams,
136+
ArrayManager::DEFAULT_PATH_DELIMITER,
137+
$priceTypeMeta
138+
],
139+
[
140+
$priceConfigPath,
141+
$priceTypeMeta,
142+
$priceParams,
143+
ArrayManager::DEFAULT_PATH_DELIMITER,
144+
$priceMeta
145+
],
146+
[
147+
$priceConfigPath,
148+
$priceMeta,
149+
$priceParams,
150+
ArrayManager::DEFAULT_PATH_DELIMITER,
151+
$priceMeta
152+
],
153+
[
154+
$priceConfigPath,
155+
$priceMeta,
156+
$taxParams,
157+
ArrayManager::DEFAULT_PATH_DELIMITER,
158+
$priceMeta
159+
]
160+
]
161+
);
162+
163+
$this->assertSame($priceMeta, $this->getModel()->modifyMeta($sourceMeta));
164+
}
165+
166+
public function testModifyData()
167+
{
168+
$expectedData = [];
169+
$this->assertEquals($expectedData, $this->getModel()->modifyData($expectedData));
170+
}
171+
}

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Bundle\Ui\DataProvider\Product\Form\Modifier;
77

8+
use Magento\Bundle\Model\Product\Price;
89
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
910
use Magento\Catalog\Api\Data\ProductAttributeInterface;
1011
use Magento\Framework\Stdlib\ArrayManager;
@@ -39,7 +40,7 @@ public function __construct(
3940
$this->locator = $locator;
4041
$this->arrayManager = $arrayManager;
4142
}
42-
43+
4344
/**
4445
* @inheritdoc
4546
*/
@@ -89,7 +90,22 @@ public function modifyMeta(array $meta)
8990
]
9091
]
9192
);
92-
93+
if ($this->locator->getProduct()->getPriceType() == Price::PRICE_TYPE_DYNAMIC) {
94+
$meta = $this->arrayManager->merge(
95+
$this->arrayManager->findPath(
96+
static::CODE_TAX_CLASS_ID,
97+
$meta,
98+
null,
99+
'children'
100+
) . static::META_CONFIG_PATH,
101+
$meta,
102+
[
103+
'service' => [
104+
'template' => ''
105+
]
106+
]
107+
);
108+
}
93109
return $meta;
94110
}
95111

app/code/Magento/Bundle/view/base/web/js/price-bundle.js

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ define([
2828
controlContainer: 'dd', // should be eliminated
2929
priceFormat: {},
3030
isFixedPrice: false,
31-
optionTierPricesBlocksSelector: '#option-tier-prices-{1} [data-role="selection-tier-prices"]'
31+
optionTierPricesBlocksSelector: '#option-tier-prices-{1} [data-role="selection-tier-prices"]',
32+
isOptionsInitialized: false
3233
};
3334

3435
$.widget('mage.priceBundle', {
@@ -53,20 +54,37 @@ define([
5354
priceBox = $(this.options.priceBoxSelector, form),
5455
qty = $(this.options.qtyFieldSelector, form);
5556

56-
if (priceBox.data('magePriceBox') &&
57-
priceBox.priceBox('option') &&
58-
priceBox.priceBox('option').priceConfig
59-
) {
60-
if (priceBox.priceBox('option').priceConfig.optionTemplate) {
61-
this._setOption('optionTemplate', priceBox.priceBox('option').priceConfig.optionTemplate);
57+
this._updatePriceBox();
58+
priceBox.on('price-box-initialized', this._updatePriceBox.bind(this));
59+
options.on('change', this._onBundleOptionChanged.bind(this));
60+
qty.on('change', this._onQtyFieldChanged.bind(this));
61+
},
62+
63+
/**
64+
* Update price box config with bundle option prices
65+
* @private
66+
*/
67+
_updatePriceBox: function () {
68+
var form = this.element,
69+
options = $(this.options.productBundleSelector, form),
70+
priceBox = $(this.options.priceBoxSelector, form);
71+
72+
if (!this.options.isOptionsInitialized) {
73+
if (priceBox.data('magePriceBox') &&
74+
priceBox.priceBox('option') &&
75+
priceBox.priceBox('option').priceConfig
76+
) {
77+
if (priceBox.priceBox('option').priceConfig.optionTemplate) { //eslint-disable-line max-depth
78+
this._setOption('optionTemplate', priceBox.priceBox('option').priceConfig.optionTemplate);
79+
}
80+
this._setOption('priceFormat', priceBox.priceBox('option').priceConfig.priceFormat);
81+
priceBox.priceBox('setDefault', this.options.optionConfig.prices);
82+
this.options.isOptionsInitialized = true;
6283
}
63-
this._setOption('priceFormat', priceBox.priceBox('option').priceConfig.priceFormat);
64-
priceBox.priceBox('setDefault', this.options.optionConfig.prices);
84+
this._applyOptionNodeFix(options);
6585
}
66-
this._applyOptionNodeFix(options);
6786

68-
options.on('change', this._onBundleOptionChanged.bind(this));
69-
qty.on('change', this._onQtyFieldChanged.bind(this));
87+
return this;
7088
},
7189

7290
/**

app/code/Magento/Catalog/Model/Product/Type/Price.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ protected function _applyTierPrice($product, $qty, $finalPrice)
262262

263263
$tierPrice = $product->getTierPrice($qty);
264264
if (is_numeric($tierPrice)) {
265-
$finalPrice = min($finalPrice, $tierPrice);
265+
$finalPrice = min($finalPrice, (float) $tierPrice);
266266
}
267267
return $finalPrice;
268268
}
@@ -645,7 +645,7 @@ public function calculateSpecialPrice(
645645
) {
646646
if ($specialPrice !== null && $specialPrice != false) {
647647
if ($this->_localeDate->isScopeDateInInterval($store, $specialPriceFrom, $specialPriceTo)) {
648-
$finalPrice = min($finalPrice, $specialPrice);
648+
$finalPrice = min($finalPrice, (float) $specialPrice);
649649
}
650650
}
651651
return $finalPrice;

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/ProductCustomOptionsDataProviderTest.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
use Magento\Framework\App\RequestInterface;
1212
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
1313
use Magento\Framework\DB\Select as DbSelect;
14+
use Magento\Framework\EntityManager\MetadataPool;
15+
use Magento\Framework\EntityManager\EntityMetadataInterface;
16+
use Magento\Ui\DataProvider\Modifier\PoolInterface;
1417

1518
class ProductCustomOptionsDataProviderTest extends \PHPUnit\Framework\TestCase
1619
{
@@ -44,6 +47,21 @@ class ProductCustomOptionsDataProviderTest extends \PHPUnit\Framework\TestCase
4447
*/
4548
protected $dbSelectMock;
4649

50+
/**
51+
* @var MetadataPool|\PHPUnit_Framework_MockObject_MockObject
52+
*/
53+
private $metadataPool;
54+
55+
/**
56+
* @var EntityMetadataInterface|\PHPUnit_Framework_MockObject_MockObject
57+
*/
58+
private $entityMetadata;
59+
60+
/**
61+
* @var PoolInterface|\PHPUnit_Framework_MockObject_MockObject
62+
*/
63+
private $modifiersPool;
64+
4765
protected function setUp()
4866
{
4967
$this->collectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)
@@ -73,12 +91,29 @@ protected function setUp()
7391
->method('create')
7492
->willReturn($this->collectionMock);
7593

94+
$this->modifiersPool = $this->getMockBuilder(PoolInterface::class)
95+
->getMockForAbstractClass();
96+
$this->entityMetadata = $this->getMockBuilder(EntityMetadataInterface::class)
97+
->getMockForAbstractClass();
98+
$this->entityMetadata->expects($this->any())
99+
->method('getLinkField')
100+
->willReturn('entity_id');
101+
$this->metadataPool = $this->getMockBuilder(MetadataPool::class)
102+
->disableOriginalConstructor()
103+
->setMethods(['getMetadata'])
104+
->getMock();
105+
$this->metadataPool->expects($this->any())
106+
->method('getMetadata')
107+
->willReturn($this->entityMetadata);
108+
76109
$this->objectManagerHelper = new ObjectManagerHelper($this);
77110
$this->dataProvider = $this->objectManagerHelper->getObject(
78111
ProductCustomOptionsDataProvider::class,
79112
[
80113
'collectionFactory' => $this->collectionFactoryMock,
81-
'request' => $this->requestMock
114+
'request' => $this->requestMock,
115+
'modifiersPool' => $this->modifiersPool,
116+
'metadataPool' => $this->metadataPool
82117
]
83118
);
84119
}

0 commit comments

Comments
 (0)