Skip to content

Commit d736ef7

Browse files
author
Anna Bukatar
committed
Merge branch '2.4-develop' of https://github.com/magento-l3/magento2ce into ACP2E-1171
2 parents 4177cb0 + a99d718 commit d736ef7

File tree

16 files changed

+379
-90
lines changed

16 files changed

+379
-90
lines changed

app/code/Magento/Catalog/Test/Mftf/Section/StorefrontNavigationSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<element name="topCategory" type="button" selector="//a[contains(@class,'level-top')]/span[contains(text(),'{{var1}}')]" parameterized="true"/>
1212
<element name="subCategory" type="button" selector="//ul[contains(@class,'submenu')]//span[contains(text(),'{{var1}}')]" parameterized="true"/>
1313
<element name="breadcrumbs" type="textarea" selector=".items"/>
14+
<element name="breadcrumbsHomeLink" type="button" selector=".home a"/>
1415
<element name="categoryBreadcrumbs" type="textarea" selector=".breadcrumbs li"/>
1516
<element name="categoryBreadcrumbsByNumber" type="textarea" selector=".breadcrumbs li:nth-of-type({{number}})" parameterized="true"/>
1617
</section>

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,4 +570,19 @@
570570
<type name="Magento\Customer\Model\EmailNotificationInterface">
571571
<plugin name="saveWishlistDataAndAddReferenceKeyToBackUrl" type="Magento\Wishlist\Plugin\SaveWishlistDataAndAddReferenceKeyToBackUrl"/>
572572
</type>
573+
<type name="Magento\Eav\Model\Validator\Attribute\Data">
574+
<arguments>
575+
<argument name="ignoredAttributesByTypesList" xsi:type="array">
576+
<item name="customer" xsi:type="array">
577+
<item name="website_id" xsi:type="string">website_id</item>
578+
<item name="store_id" xsi:type="string">store_id</item>
579+
<item name="group_id" xsi:type="string">group_id</item>
580+
<item name="dob" xsi:type="string">dob</item>
581+
</item>
582+
<item name="customer_address" xsi:type="array">
583+
<item name="country_id" xsi:type="string">country_id</item>
584+
</item>
585+
</argument>
586+
</arguments>
587+
</type>
573588
</config>

app/code/Magento/Eav/Model/Attribute/Data/Multiselect.php

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
* @author Magento Core Team <core@magentocommerce.com>
1414
*/
15-
class Multiselect extends \Magento\Eav\Model\Attribute\Data\Select
15+
class Multiselect extends AbstractData
1616
{
1717
/**
1818
* Extract data from request and return value
@@ -40,7 +40,11 @@ public function compactValue($value)
4040
if (is_array($value)) {
4141
$value = implode(',', $value);
4242
}
43-
return parent::compactValue($value);
43+
if ($value !== false) {
44+
$this->getEntity()->setData($this->getAttribute()->getAttributeCode(), $value);
45+
}
46+
47+
return $this;
4448
}
4549

4650
/**
@@ -75,4 +79,63 @@ public function outputValue($format = \Magento\Eav\Model\AttributeDataFactory::O
7579

7680
return $output;
7781
}
82+
83+
/**
84+
* @inheritdoc
85+
*/
86+
public function validateValue($value)
87+
{
88+
$errors = [];
89+
$attribute = $this->getAttribute();
90+
91+
if ($value === false) {
92+
// try to load original value and validate it
93+
$value = $this->getEntity()->getData($attribute->getAttributeCode());
94+
}
95+
96+
if ($attribute->getIsRequired() && empty($value) && $value != '0') {
97+
$label = __($attribute->getStoreLabel());
98+
$errors[] = __('"%1" is a required value.', $label);
99+
}
100+
101+
if (!empty($value) && $attribute->getSourceModel()) {
102+
$values = is_array($value) ? $value : explode(',', (string) $value);
103+
$errors = array_merge(
104+
$errors,
105+
$this->validateBySource($values)
106+
);
107+
}
108+
109+
return empty($errors) ? true : $errors;
110+
}
111+
112+
/**
113+
* Validate values using source
114+
*
115+
* @param array $values
116+
* @return array
117+
*/
118+
private function validateBySource(array $values): array
119+
{
120+
$errors = [];
121+
foreach ($values as $value) {
122+
if (!$this->getAttribute()->getSource()->getOptionText($value)) {
123+
$errors[] = __(
124+
'Attribute %1 does not contain option with Id %2',
125+
$this->getAttribute()->getAttributeCode(),
126+
$value
127+
);
128+
}
129+
}
130+
131+
return $errors;
132+
}
133+
134+
/**
135+
* @inheritdoc
136+
*/
137+
public function restoreValue($value)
138+
{
139+
return $this->compactValue($value);
140+
}
78141
}

app/code/Magento/Eav/Model/Attribute/Data/Select.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function extractValue(RequestInterface $request)
2727

2828
/**
2929
* Validate data
30+
*
3031
* Return true or array of errors
3132
*
3233
* @param array|string $value
@@ -47,8 +48,11 @@ public function validateValue($value)
4748
$errors[] = __('"%1" is a required value.', $label);
4849
}
4950

50-
if (!$errors && !$attribute->getIsRequired() && empty($value)) {
51-
return true;
51+
if (!empty($value)
52+
&& $attribute->getSourceModel()
53+
&& !$attribute->getSource()->getOptionText($value)
54+
) {
55+
$errors[] = __('Attribute %1 does not contain option with Id %2', $attribute->getAttributeCode(), $value);
5256
}
5357

5458
if (count($errors) == 0) {

app/code/Magento/Eav/Model/Validator/Attribute/Data.php

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
namespace Magento\Eav\Model\Validator\Attribute;
88

99
use Magento\Eav\Model\Attribute;
10+
use Magento\Eav\Model\AttributeDataFactory;
11+
use Magento\Framework\DataObject;
1012

1113
/**
1214
* EAV attribute data validator
@@ -36,16 +38,25 @@ class Data extends \Magento\Framework\Validator\AbstractValidator
3638
protected $_data = [];
3739

3840
/**
39-
* @var \Magento\Eav\Model\AttributeDataFactory
41+
* @var AttributeDataFactory
4042
*/
4143
protected $_attrDataFactory;
4244

4345
/**
44-
* @param \Magento\Eav\Model\AttributeDataFactory $attrDataFactory
46+
* @var array
4547
*/
46-
public function __construct(\Magento\Eav\Model\AttributeDataFactory $attrDataFactory)
47-
{
48+
private $ignoredAttributesByTypesList;
49+
50+
/**
51+
* @param AttributeDataFactory $attrDataFactory
52+
* @param array $ignoredAttributesByTypesList
53+
*/
54+
public function __construct(
55+
AttributeDataFactory $attrDataFactory,
56+
array $ignoredAttributesByTypesList = []
57+
) {
4858
$this->_attrDataFactory = $attrDataFactory;
59+
$this->ignoredAttributesByTypesList = $ignoredAttributesByTypesList;
4960
}
5061

5162
/**
@@ -111,18 +122,17 @@ public function isValid($entity)
111122
/** @var $attributes Attribute[] */
112123
$attributes = $this->_getAttributes($entity);
113124

114-
$data = [];
115-
if ($this->_data) {
116-
$data = $this->_data;
117-
} elseif ($entity instanceof \Magento\Framework\DataObject) {
118-
$data = $entity->getData();
119-
}
125+
$data = $this->retrieveData($entity);
120126

121127
foreach ($attributes as $attribute) {
122128
$attributeCode = $attribute->getAttributeCode();
123129
if (!$attribute->getDataModel() && !$attribute->getFrontendInput()) {
124130
continue;
125131
}
132+
if (!isset($data[$attributeCode]) && !$attribute->getIsVisible()) {
133+
continue;
134+
}
135+
126136
$dataModel = $this->_attrDataFactory->create($attribute, $entity);
127137
$dataModel->setExtractedData($data);
128138
if (!isset($data[$attributeCode])) {
@@ -149,6 +159,7 @@ protected function _getAttributes($entity)
149159
{
150160
/** @var \Magento\Eav\Model\Attribute[] $attributes */
151161
$attributes = [];
162+
$ignoreAttributes = $this->deniedAttributesList;
152163

153164
if ($this->_attributes) {
154165
$attributes = $this->_attributes;
@@ -158,27 +169,27 @@ protected function _getAttributes($entity)
158169
/** @var \Magento\Eav\Model\Entity\Type $entityType */
159170
$entityType = $entity->getEntityType();
160171
$attributes = $entityType->getAttributeCollection()->getItems();
172+
173+
$ignoredTypeAttributes = $this->ignoredAttributesByTypesList[$entityType->getEntityTypeCode()] ?? [];
174+
if ($ignoredTypeAttributes) {
175+
$ignoreAttributes = array_merge($ignoreAttributes, $ignoredTypeAttributes);
176+
}
161177
}
162178

163179
$attributesByCode = [];
164180
$attributesCodes = [];
165181
foreach ($attributes as $attribute) {
166-
if (!$attribute->getIsVisible()) {
167-
continue;
168-
}
169182
$attributeCode = $attribute->getAttributeCode();
170183
$attributesByCode[$attributeCode] = $attribute;
171184
$attributesCodes[] = $attributeCode;
172185
}
173186

174-
$ignoreAttributes = $this->deniedAttributesList;
175187
if ($this->allowedAttributesList) {
176188
$ignoreAttributes = array_merge(
177189
$ignoreAttributes,
178190
array_diff($attributesCodes, $this->allowedAttributesList)
179191
);
180192
}
181-
182193
foreach ($ignoreAttributes as $attributeCode) {
183194
unset($attributesByCode[$attributeCode]);
184195
}
@@ -201,4 +212,22 @@ protected function _addErrorMessages($code, array $messages)
201212
$this->_messages[$code] = array_merge($this->_messages[$code], $messages);
202213
}
203214
}
215+
216+
/**
217+
* Retrieve entity data
218+
*
219+
* @param \Magento\Framework\Model\AbstractModel $entity
220+
* @return array
221+
*/
222+
private function retrieveData($entity): array
223+
{
224+
$data = [];
225+
if ($this->_data) {
226+
$data = $this->_data;
227+
} elseif ($entity instanceof DataObject) {
228+
$data = $entity->getData();
229+
}
230+
231+
return $data;
232+
}
204233
}

app/code/Magento/Eav/Test/Unit/Model/Validator/Attribute/DataTest.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Magento\Framework\Model\AbstractModel;
1818
use Magento\Framework\ObjectManagerInterface;
1919
use Magento\Framework\Stdlib\StringUtils;
20-
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
2120
use PHPUnit\Framework\MockObject\MockObject;
2221
use PHPUnit\Framework\TestCase;
2322

@@ -32,21 +31,15 @@ class DataTest extends TestCase
3231
private $attrDataFactory;
3332

3433
/**
35-
* @var \Magento\Eav\Model\Validator\Attribute\Data
34+
* @var Data
3635
*/
3736
private $model;
3837

39-
/**
40-
* @var ObjectManager
41-
*/
42-
private $objectManager;
43-
4438
/**
4539
* @inheritdoc
4640
*/
4741
protected function setUp(): void
4842
{
49-
$this->objectManager = new ObjectManager($this);
5043
$this->attrDataFactory = $this->getMockBuilder(AttributeDataFactory::class)
5144
->onlyMethods(['create'])
5245
->setConstructorArgs(
@@ -57,10 +50,7 @@ protected function setUp(): void
5750
)
5851
->getMock();
5952

60-
$this->model = $this->objectManager->getObject(
61-
Data::class,
62-
['_attrDataFactory' => $this->attrDataFactory]
63-
);
53+
$this->model = new Data($this->attrDataFactory);
6454
}
6555

6656
/**
@@ -190,7 +180,8 @@ public function isValidDataProvider(): array
190180
],
191181
'attributeReturns' => ['Error'],
192182
'isValid' => true,
193-
'messages' => []
183+
'messages' => [],
184+
'data' => [],
194185
],
195186
];
196187
}

app/code/Magento/Sales/Block/Adminhtml/Order/Create/Sidebar/Cart.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ public function getItemCollection()
5959
$collection = $this->getData('item_collection');
6060
if ($collection === null) {
6161
$collection = $this->getCreateOrderModel()->getCustomerCart()->getAllVisibleItems();
62+
$transferredItems = $this->getCreateOrderModel()->getSession()->getTransferredItems() ?? [];
63+
$transferredItems = $transferredItems[$this->getDataId()] ?? [];
64+
if (!empty($transferredItems)) {
65+
foreach ($collection as $key => $item) {
66+
if (in_array($item->getId(), $transferredItems)) {
67+
unset($collection[$key]);
68+
}
69+
}
70+
}
71+
6272
$this->setData('item_collection', $collection);
6373
}
6474
return $collection;

app/code/Magento/Sales/Block/Adminhtml/Order/Create/Sidebar/Wishlist.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ public function getItemCollection()
5555
$collection = $this->getCreateOrderModel()->getCustomerWishlist(true);
5656
if ($collection) {
5757
$collection = $collection->getItemCollection()->load();
58+
$transferredItems = $this->getCreateOrderModel()->getSession()->getTransferredItems() ?? [];
59+
$transferredItems = $transferredItems[$this->getDataId()] ?? [];
60+
if (!empty($transferredItems)) {
61+
foreach ($collection as $key => $item) {
62+
if (in_array($item->getId(), $transferredItems)) {
63+
$collection->removeItemByKey($key);
64+
}
65+
}
66+
}
5867
}
5968
$this->setData('item_collection', $collection);
6069
}

0 commit comments

Comments
 (0)