Skip to content

Commit 666e37e

Browse files
committed
Merge remote-tracking branch 'origin/MC-29633' into 2.4-develop-pr5
2 parents 3b0a8b7 + 6d064fd commit 666e37e

File tree

3 files changed

+192
-2
lines changed

3 files changed

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

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

0 commit comments

Comments
 (0)