Skip to content

Commit 36c9718

Browse files
committed
Merge remote-tracking branch 'magento2/2.3-develop' into MAGETWO-95539
2 parents 6e20e2e + de50d12 commit 36c9718

File tree

227 files changed

+6896
-1985
lines changed

Some content is hidden

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

227 files changed

+6896
-1985
lines changed

app/code/Magento/Backend/Block/Widget/Form.php

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Backend\Block\Widget;
78

9+
use Magento\Framework\App\ObjectManager;
10+
811
/**
912
* Backend form widget
1013
*
@@ -27,13 +30,23 @@ class Form extends \Magento\Backend\Block\Widget
2730
*/
2831
protected $_template = 'Magento_Backend::widget/form.phtml';
2932

33+
/** @var Form\Element\ElementCreator */
34+
private $creator;
35+
3036
/**
37+
* Constructs form
38+
*
3139
* @param \Magento\Backend\Block\Template\Context $context
3240
* @param array $data
41+
* @param Form\Element\ElementCreator|null $creator
3342
*/
34-
public function __construct(\Magento\Backend\Block\Template\Context $context, array $data = [])
35-
{
43+
public function __construct(
44+
\Magento\Backend\Block\Template\Context $context,
45+
array $data = [],
46+
Form\Element\ElementCreator $creator = null
47+
) {
3648
parent::__construct($context, $data);
49+
$this->creator = $creator ?: ObjectManager::getInstance()->get(Form\Element\ElementCreator::class);
3750
}
3851

3952
/**
@@ -148,6 +161,7 @@ protected function _beforeToHtml()
148161

149162
/**
150163
* Initialize form fields values
164+
*
151165
* Method will be called after prepareForm and can be used for field values initialization
152166
*
153167
* @return $this
@@ -173,32 +187,11 @@ protected function _setFieldset($attributes, $fieldset, $exclude = [])
173187
if (!$this->_isAttributeVisible($attribute)) {
174188
continue;
175189
}
176-
if (($inputType = $attribute->getFrontend()->getInputType()) && !in_array(
177-
$attribute->getAttributeCode(),
178-
$exclude
179-
) && ('media_image' != $inputType || $attribute->getAttributeCode() == 'image')
190+
if (($inputType = $attribute->getFrontend()->getInputType())
191+
&& !in_array($attribute->getAttributeCode(), $exclude)
192+
&& ('media_image' !== $inputType || $attribute->getAttributeCode() == 'image')
180193
) {
181-
$fieldType = $inputType;
182-
$rendererClass = $attribute->getFrontend()->getInputRendererClass();
183-
if (!empty($rendererClass)) {
184-
$fieldType = $inputType . '_' . $attribute->getAttributeCode();
185-
$fieldset->addType($fieldType, $rendererClass);
186-
}
187-
188-
$element = $fieldset->addField(
189-
$attribute->getAttributeCode(),
190-
$fieldType,
191-
[
192-
'name' => $attribute->getAttributeCode(),
193-
'label' => $attribute->getFrontend()->getLocalizedLabel(),
194-
'class' => $attribute->getFrontend()->getClass(),
195-
'required' => $attribute->getIsRequired(),
196-
'note' => $attribute->getNote()
197-
]
198-
)->setEntityAttribute(
199-
$attribute
200-
);
201-
194+
$element = $this->creator->create($fieldset, $attribute);
202195
$element->setAfterElementHtml($this->_getAdditionalElementHtml($element));
203196

204197
$this->_applyTypeSpecificConfig($inputType, $element, $attribute);
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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\Backend\Block\Widget\Form\Element;
9+
10+
use Magento\Eav\Model\Entity\Attribute;
11+
use Magento\Framework\Data\Form\Element\AbstractElement;
12+
use Magento\Framework\Data\Form\Element\Fieldset;
13+
14+
/**
15+
* Class ElementCreator
16+
*
17+
* @deprecated 100.3.0 in favour of UI component implementation
18+
* @package Magento\Backend\Block\Widget\Form\Element
19+
*/
20+
class ElementCreator
21+
{
22+
/**
23+
* @var array
24+
*/
25+
private $modifiers;
26+
27+
/**
28+
* ElementCreator constructor.
29+
*
30+
* @param array $modifiers
31+
*/
32+
public function __construct(array $modifiers = [])
33+
{
34+
$this->modifiers = $modifiers;
35+
}
36+
37+
/**
38+
* Creates element
39+
*
40+
* @param Fieldset $fieldset
41+
* @param Attribute $attribute
42+
*
43+
* @return AbstractElement
44+
*/
45+
public function create(Fieldset $fieldset, Attribute $attribute): AbstractElement
46+
{
47+
$config = $this->getElementConfig($attribute);
48+
49+
if (!empty($config['rendererClass'])) {
50+
$fieldType = $config['inputType'] . '_' . $attribute->getAttributeCode();
51+
$fieldset->addType($fieldType, $config['rendererClass']);
52+
}
53+
54+
return $fieldset
55+
->addField($config['attribute_code'], $config['inputType'], $config)
56+
->setEntityAttribute($attribute);
57+
}
58+
59+
/**
60+
* Returns element config
61+
*
62+
* @param Attribute $attribute
63+
* @return array
64+
*/
65+
private function getElementConfig(Attribute $attribute): array
66+
{
67+
$defaultConfig = $this->createDefaultConfig($attribute);
68+
$config = $this->modifyConfig($defaultConfig);
69+
70+
$config['label'] = __($config['label']);
71+
72+
return $config;
73+
}
74+
75+
/**
76+
* Returns default config
77+
*
78+
* @param Attribute $attribute
79+
* @return array
80+
*/
81+
private function createDefaultConfig(Attribute $attribute): array
82+
{
83+
return [
84+
'inputType' => $attribute->getFrontend()->getInputType(),
85+
'rendererClass' => $attribute->getFrontend()->getInputRendererClass(),
86+
'attribute_code' => $attribute->getAttributeCode(),
87+
'name' => $attribute->getAttributeCode(),
88+
'label' => $attribute->getFrontend()->getLabel(),
89+
'class' => $attribute->getFrontend()->getClass(),
90+
'required' => $attribute->getIsRequired(),
91+
'note' => $attribute->getNote(),
92+
];
93+
}
94+
95+
/**
96+
* Modify config
97+
*
98+
* @param array $config
99+
* @return array
100+
*/
101+
private function modifyConfig(array $config): array
102+
{
103+
if ($this->isModified($config['attribute_code'])) {
104+
return $this->applyModifier($config);
105+
}
106+
return $config;
107+
}
108+
109+
/**
110+
* Returns bool if attribute need to modify
111+
*
112+
* @param string $attribute_code
113+
* @return bool
114+
*/
115+
private function isModified($attribute_code): bool
116+
{
117+
return isset($this->modifiers[$attribute_code]);
118+
}
119+
120+
/**
121+
* Apply modifier to config
122+
*
123+
* @param array $config
124+
* @return array
125+
*/
126+
private function applyModifier(array $config): array
127+
{
128+
$modifiedConfig = $this->modifiers[$config['attribute_code']];
129+
foreach (array_keys($config) as $key) {
130+
if (isset($modifiedConfig[$key])) {
131+
$config[$key] = $modifiedConfig[$key];
132+
}
133+
}
134+
return $config;
135+
}
136+
}

app/code/Magento/Backend/view/adminhtml/templates/system/search.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<% if (data.items.length) { %>
4343
<% _.each(data.items, function(value){ %>
4444
<li class="item"
45-
<%- data.optionData(value) %>
45+
<%= data.optionData(value) %>
4646
>
4747
<a href="<%- value.url %>" class="title"><%- value.name %></a>
4848
<span class="type"><%- value.type %></span>

app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ public function getJsonConfig()
188188
$configValue = $preConfiguredValues->getData('bundle_option/' . $optionId);
189189
if ($configValue) {
190190
$defaultValues[$optionId] = $configValue;
191+
$configQty = $preConfiguredValues->getData('bundle_option_qty/' . $optionId);
192+
if ($configQty) {
193+
$options[$optionId]['selections'][$configValue]['qty'] = $configQty;
194+
}
191195
}
192196
}
193197
$position++;
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AdminCreateApiDynamicBundleProductActionGroup">
12+
<arguments>
13+
<argument name="productName" defaultValue="Api Dynamic Bundle Product" type="string"/>
14+
</arguments>
15+
<!--Create 4 simple products-->
16+
<createData entity="SimpleProduct2" stepKey="simpleProduct1">
17+
<field key="price">4.99</field>
18+
</createData>
19+
<createData entity="SimpleProduct2" stepKey="simpleProduct2">
20+
<field key="price">2.89</field>
21+
</createData>
22+
<createData entity="SimpleProduct2" stepKey="simpleProduct3">
23+
<field key="price">7.33</field>
24+
</createData>
25+
<createData entity="SimpleProduct2" stepKey="simpleProduct4">
26+
<field key="price">18.25</field>
27+
</createData>
28+
<!-- Create the bundle product based -->
29+
<createData entity="ApiBundleProduct" stepKey="createBundleProduct">
30+
<field key="name">{{productName}}</field>
31+
</createData>
32+
<createData entity="MultipleSelectOption" stepKey="createBundleOption1_1">
33+
<requiredEntity createDataKey="createBundleProduct"/>
34+
<field key="required">false</field>
35+
</createData>
36+
<createData entity="CheckboxOption" stepKey="createBundleOption1_2">
37+
<requiredEntity createDataKey="createBundleProduct"/>
38+
</createData>
39+
<createData entity="ApiBundleLink" stepKey="linkOptionToProduct">
40+
<requiredEntity createDataKey="createBundleProduct"/>
41+
<requiredEntity createDataKey="createBundleOption1_1"/>
42+
<requiredEntity createDataKey="simpleProduct1"/>
43+
</createData>
44+
<createData entity="ApiBundleLink" stepKey="linkOptionToProduct2">
45+
<requiredEntity createDataKey="createBundleProduct"/>
46+
<requiredEntity createDataKey="createBundleOption1_1"/>
47+
<requiredEntity createDataKey="simpleProduct2"/>
48+
</createData>
49+
<createData entity="ApiBundleLink" stepKey="linkOptionToProduct3">
50+
<requiredEntity createDataKey="createBundleProduct"/>
51+
<requiredEntity createDataKey="createBundleOption1_2"/>
52+
<requiredEntity createDataKey="simpleProduct3"/>
53+
</createData>
54+
<createData entity="ApiBundleLink" stepKey="linkOptionToProduct4">
55+
<requiredEntity createDataKey="createBundleProduct"/>
56+
<requiredEntity createDataKey="createBundleOption1_2"/>
57+
<requiredEntity createDataKey="simpleProduct4"/>
58+
</createData>
59+
</actionGroup>
60+
<actionGroup name="AdminCreateApiFixedBundleProductActionGroup">
61+
<arguments>
62+
<argument name="productName" defaultValue="Api Fixed Bundle Product" type="string"/>
63+
</arguments>
64+
<!--Create 4 simple products-->
65+
<createData entity="SimpleProduct2" stepKey="simpleProduct1">
66+
<field key="price">4.99</field>
67+
</createData>
68+
<createData entity="SimpleProduct2" stepKey="simpleProduct2">
69+
<field key="price">2.89</field>
70+
</createData>
71+
<createData entity="SimpleProduct2" stepKey="simpleProduct3">
72+
<field key="price">7.33</field>
73+
</createData>
74+
<createData entity="SimpleProduct2" stepKey="simpleProduct4">
75+
<field key="price">18.25</field>
76+
</createData>
77+
<!-- Create the bundle product based -->
78+
<createData entity="ApiFixedBundleProduct" stepKey="createBundleProduct">
79+
<field key="name">{{productName}}</field>
80+
</createData>
81+
<createData entity="MultipleSelectOption" stepKey="createBundleOption1_1">
82+
<requiredEntity createDataKey="createBundleProduct"/>
83+
<field key="required">false</field>
84+
</createData>
85+
<createData entity="CheckboxOption" stepKey="createBundleOption1_2">
86+
<requiredEntity createDataKey="createBundleProduct"/>
87+
</createData>
88+
<createData entity="ApiBundleLink" stepKey="linkOptionToProduct">
89+
<requiredEntity createDataKey="createBundleProduct"/>
90+
<requiredEntity createDataKey="createBundleOption1_1"/>
91+
<requiredEntity createDataKey="simpleProduct1"/>
92+
</createData>
93+
<createData entity="ApiBundleLink" stepKey="linkOptionToProduct2">
94+
<requiredEntity createDataKey="createBundleProduct"/>
95+
<requiredEntity createDataKey="createBundleOption1_1"/>
96+
<requiredEntity createDataKey="simpleProduct2"/>
97+
</createData>
98+
<createData entity="ApiBundleLink" stepKey="linkOptionToProduct3">
99+
<requiredEntity createDataKey="createBundleProduct"/>
100+
<requiredEntity createDataKey="createBundleOption1_2"/>
101+
<requiredEntity createDataKey="simpleProduct3"/>
102+
</createData>
103+
<createData entity="ApiBundleLink" stepKey="linkOptionToProduct4">
104+
<requiredEntity createDataKey="createBundleProduct"/>
105+
<requiredEntity createDataKey="createBundleOption1_2"/>
106+
<requiredEntity createDataKey="simpleProduct4"/>
107+
</createData>
108+
</actionGroup>
109+
</actionGroups>

app/code/Magento/Bundle/Test/Mftf/Data/ProductData.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,19 @@
6060
<requiredEntity type="custom_attribute">CustomAttributeDynamicPrice</requiredEntity>
6161
<requiredEntity type="custom_attribute">CustomAttributePriceViewRange</requiredEntity>
6262
</entity>
63+
<entity name="ApiFixedBundleProduct" type="product2">
64+
<data key="name" unique="suffix">Api Fixed Bundle Product</data>
65+
<data key="sku" unique="suffix">api-fixed-bundle-product</data>
66+
<data key="type_id">bundle</data>
67+
<data key="attribute_set_id">4</data>
68+
<data key="price">1.23</data>
69+
<data key="visibility">4</data>
70+
<data key="status">1</data>
71+
<data key="urlKey" unique="suffix">api-fixed-bundle-product</data>
72+
<requiredEntity type="product_extension_attribute">EavStockItem</requiredEntity>
73+
<requiredEntity type="custom_attribute">ApiProductDescription</requiredEntity>
74+
<requiredEntity type="custom_attribute">ApiProductShortDescription</requiredEntity>
75+
<requiredEntity type="custom_attribute">CustomAttributeFixPrice</requiredEntity>
76+
<requiredEntity type="custom_attribute">CustomAttributePriceView</requiredEntity>
77+
</entity>
6378
</entities>

0 commit comments

Comments
 (0)