Skip to content

Commit 8b1aa59

Browse files
Merge branch '2.4.3-develop' into 2.4.3-develop-2.4-develop-sync-041221
2 parents 9a68d68 + 7b03070 commit 8b1aa59

File tree

47 files changed

+1851
-139
lines changed

Some content is hidden

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

47 files changed

+1851
-139
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Gallery/Upload.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@ public function execute()
108108

109109
$result['url'] = $this->productMediaConfig->getTmpMediaUrl($result['file']);
110110
$result['file'] = $result['file'] . '.tmp';
111-
} catch (\Exception $e) {
111+
} catch (LocalizedException $e) {
112112
$result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()];
113+
} catch (\Throwable $e) {
114+
$result = ['error' => 'Something went wrong while saving the file(s).', 'errorcode' => 0];
113115
}
114116

115117
/** @var \Magento\Framework\Controller\Result\Raw $response */

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* See COPYING.txt for license details.
66
*/
77
-->
8-
98
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
109
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
1110
<section name="AdminAddProductsToOptionPanel">
@@ -16,4 +15,4 @@
1615
<element name="firstCheckbox" type="input" selector="//tr[1]//input[@data-action='select-row']"/>
1716
<element name="nthCheckbox" type="input" selector="//tr[{{var}}]//input[@data-action='select-row']" parameterized="true"/>
1817
</section>
19-
</sections>
18+
</sections>

app/code/Magento/CatalogInventory/Model/Quote/Item/QuantityValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public function validate(Observer $observer)
185185
* Check item for options
186186
*/
187187
if ($options) {
188-
$qty = $product->getTypeInstance()->prepareQuoteItemQty($qty, $product);
188+
$qty = $product->getTypeInstance()->prepareQuoteItemQty($quoteItem->getQty(), $product);
189189
$quoteItem->setData('qty', $qty);
190190
if ($stockStatus) {
191191
$this->checkOptionsQtyIncrements($quoteItem, $options);

app/code/Magento/CatalogInventory/Model/Quote/Item/QuantityValidator/Initializer/Option.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function initialize(
120120
/**
121121
* if option's qty was updates we also need to update quote item qty
122122
*/
123-
$quoteItem->setData('qty', (int) $qty);
123+
$quoteItem->setData('qty', (int) $result->getItemQty());
124124
}
125125
if ($result->getMessage() !== null) {
126126
$option->setMessage($result->getMessage());

app/code/Magento/CatalogInventory/Test/Unit/Model/Quote/Item/QuantityValidator/Initializer/OptionTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ protected function setUp(): void
125125
);
126126
$this->resultMock = $this->getMockBuilder(DataObject::class)
127127
->addMethods(
128-
['getItemIsQtyDecimal', 'getHasQtyOptionUpdate', 'getOrigQty', 'getMessage', 'getItemBackorders']
128+
['getItemIsQtyDecimal', 'getHasQtyOptionUpdate', 'getOrigQty', 'getMessage', 'getItemBackorders', 'getItemQty']
129129
)
130130
->disableOriginalConstructor()
131131
->getMock();
@@ -217,6 +217,7 @@ public function testInitializeWhenResultIsDecimalGetBackordersMessageHasOptionQt
217217
$this->optionMock->expects($this->once())->method('setBackorders')->with('backorders');
218218

219219
$this->stockItemMock->expects($this->once())->method('unsIsChildItem');
220+
$this->resultMock->expects($this->once())->method('getItemQty')->willReturn($qty);
220221
$this->validator->initialize($this->optionMock, $this->quoteItemMock, $qty);
221222
}
222223

app/code/Magento/CatalogInventory/Test/Unit/Model/Quote/Item/QuantityValidator/Initializer/QuantityValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ private function createInitialStub($qty)
564564
$this->quoteItemMock->expects($this->any())
565565
->method('getQuote')
566566
->willReturn($this->quoteMock);
567-
$this->quoteItemMock->expects($this->once())
567+
$this->quoteItemMock->expects($this->any())
568568
->method('getQty')
569569
->willReturn($qty);
570570
$this->quoteItemMock->expects($this->any())

app/code/Magento/Cms/Controller/Adminhtml/Page/PostDataProcessor.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\App\ObjectManager;
1111
use Magento\Framework\Config\Dom\ValidationException;
1212
use Magento\Framework\Config\Dom\ValidationSchemaException;
13+
use Magento\Cms\Model\Page\CustomLayout\CustomLayoutValidator;
1314

1415
/**
1516
* Controller helper for user input.
@@ -36,23 +37,32 @@ class PostDataProcessor
3637
*/
3738
private $validationState;
3839

40+
/**
41+
* @var CustomLayoutValidator
42+
*/
43+
private $customLayoutValidator;
44+
3945
/**
4046
* @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter
4147
* @param \Magento\Framework\Message\ManagerInterface $messageManager
4248
* @param \Magento\Framework\View\Model\Layout\Update\ValidatorFactory $validatorFactory
43-
* @param DomValidationState $validationState
49+
* @param DomValidationState|null $validationState
50+
* @param CustomLayoutValidator|null $customLayoutValidator
4451
*/
4552
public function __construct(
4653
\Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter,
4754
\Magento\Framework\Message\ManagerInterface $messageManager,
4855
\Magento\Framework\View\Model\Layout\Update\ValidatorFactory $validatorFactory,
49-
DomValidationState $validationState = null
56+
DomValidationState $validationState = null,
57+
CustomLayoutValidator $customLayoutValidator = null
5058
) {
5159
$this->dateFilter = $dateFilter;
5260
$this->messageManager = $messageManager;
5361
$this->validatorFactory = $validatorFactory;
5462
$this->validationState = $validationState
5563
?: ObjectManager::getInstance()->get(DomValidationState::class);
64+
$this->customLayoutValidator = $customLayoutValidator
65+
?: ObjectManager::getInstance()->get(CustomLayoutValidator::class);
5666
}
5767

5868
/**
@@ -146,6 +156,9 @@ private function validateData($data, $layoutXmlValidator)
146156
) {
147157
return false;
148158
}
159+
if (!$this->customLayoutValidator->validate($data)) {
160+
return false;
161+
}
149162
} catch (ValidationException $e) {
150163
return false;
151164
} catch (ValidationSchemaException $e) {
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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\Cms\Model\Page\CustomLayout;
9+
10+
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\Framework\Message\ManagerInterface;
12+
use Magento\Cms\Model\PageRepository;
13+
14+
/**
15+
* Class for layout update validation
16+
*/
17+
class CustomLayoutValidator
18+
{
19+
/**
20+
* @var PageFactory
21+
*/
22+
private $pageFactory;
23+
24+
/**
25+
* @var ManagerInterface
26+
*/
27+
private $messageManager;
28+
29+
/**
30+
* CustomLayoutValidator constructor.
31+
* @param PageRepository $pageFactory
32+
* @param ManagerInterface $messageManager
33+
*/
34+
public function __construct(
35+
PageRepository $pageFactory,
36+
ManagerInterface $messageManager
37+
) {
38+
$this->pageFactory = $pageFactory;
39+
$this->messageManager = $messageManager;
40+
}
41+
42+
/**
43+
* Validates layout update and custom layout update for CMS page
44+
*
45+
* @param array $data
46+
* @return bool
47+
* @throws LocalizedException
48+
*/
49+
public function validate(array $data) : bool
50+
{
51+
[$layoutUpdate, $customLayoutUpdate, $oldLayoutUpdate, $oldCustomLayoutUpdate] = $this->getLayoutUpdates($data);
52+
if (isset($data['page_id'])) {
53+
if ($layoutUpdate && $oldLayoutUpdate !== $layoutUpdate
54+
|| $customLayoutUpdate && $oldCustomLayoutUpdate !== $customLayoutUpdate
55+
) {
56+
throw new LocalizedException(__('Custom layout update text cannot be changed, only removed'));
57+
}
58+
} else {
59+
if ($layoutUpdate || $customLayoutUpdate) {
60+
throw new LocalizedException(__('Custom layout update text cannot be changed, only removed'));
61+
}
62+
}
63+
return true;
64+
}
65+
66+
/**
67+
* Gets page layout update values
68+
*
69+
* @param array $data
70+
* @return array
71+
* @throws \Magento\Framework\Exception\NoSuchEntityException
72+
*/
73+
private function getLayoutUpdates(array $data) : array
74+
{
75+
$layoutUpdate = $data['layout_update_xml'] ?? null;
76+
$customLayoutUpdate = $data['custom_layout_update_xml'] ?? null;
77+
$oldLayoutUpdate = null;
78+
$oldCustomLayoutUpdate = null;
79+
if (isset($data['page_id'])) {
80+
$page = $this->pageFactory->getById($data['page_id']);
81+
$oldLayoutUpdate = $page->getId() ? $page->getLayoutUpdateXml() : null;
82+
$oldCustomLayoutUpdate = $page->getId() ? $page->getCustomLayoutUpdateXml() : null;
83+
}
84+
85+
return [$layoutUpdate, $customLayoutUpdate, $oldLayoutUpdate, $oldCustomLayoutUpdate];
86+
}
87+
}

app/code/Magento/ConfigurableProduct/Plugin/Model/Attribute/Backend/AttributeValidation.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\ConfigurableProduct\Plugin\Model\Attribute\Backend;
78

9+
use Closure;
810
use Magento\Catalog\Api\Data\ProductInterface;
911
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
12+
use Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend;
13+
use Magento\Framework\DataObject;
1014

1115
/**
12-
* Skip validate attributes used for create configurable product
16+
* Skip validate attributes used for create configurable product.
1317
*/
1418
class AttributeValidation
1519
{
@@ -19,29 +23,36 @@ class AttributeValidation
1923
private $configurableProductType;
2024

2125
/**
22-
* AttributeValidation constructor.
26+
* @var array
27+
*/
28+
private $unskippableAttributes;
29+
30+
/**
2331
* @param Configurable $configurableProductType
32+
* @param array|null $unskippableAttributes
2433
*/
2534
public function __construct(
26-
Configurable $configurableProductType
35+
Configurable $configurableProductType,
36+
array $unskippableAttributes = []
2737
) {
2838
$this->configurableProductType = $configurableProductType;
39+
$this->unskippableAttributes = $unskippableAttributes;
2940
}
3041

3142
/**
32-
* @param \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend $subject
43+
* Around plugin to skip attribute validation used for create configurable product.
44+
*
45+
* @param AbstractBackend $subject
3346
* @param \Closure $proceed
34-
* @param \Magento\Framework\DataObject $entity
47+
* @param DataObject $entity
3548
* @return bool
3649
*/
37-
public function aroundValidate(
38-
\Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend $subject,
39-
\Closure $proceed,
40-
\Magento\Framework\DataObject $entity
41-
) {
50+
public function aroundValidate(AbstractBackend $subject, Closure $proceed, DataObject $entity)
51+
{
4252
$attribute = $subject->getAttribute();
4353
if ($entity instanceof ProductInterface
4454
&& $entity->getTypeId() == Configurable::TYPE_CODE
55+
&& !in_array($attribute->getAttributeCode(), $this->unskippableAttributes)
4556
&& in_array(
4657
$attribute->getAttributeId(),
4758
$this->configurableProductType->getUsedProductAttributeIds($entity),
@@ -50,6 +61,7 @@ public function aroundValidate(
5061
) {
5162
return true;
5263
}
64+
5365
return $proceed($entity);
5466
}
5567
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333
<type name="Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend">
3434
<plugin name="ConfigurableProduct::skipValidation" type="Magento\ConfigurableProduct\Plugin\Model\Attribute\Backend\AttributeValidation"/>
3535
</type>
36+
<type name="Magento\ConfigurableProduct\Plugin\Model\Attribute\Backend\AttributeValidation">
37+
<arguments>
38+
<argument name="unskippableAttributes" xsi:type="array">
39+
<item name="custom_layout_update" xsi:type="string">custom_layout_update</item>
40+
</argument>
41+
</arguments>
42+
</type>
3643
<type name="Magento\Catalog\Model\Entity\Product\Attribute\Group\AttributeMapperInterface">
3744
<plugin name="configurable_product" type="Magento\ConfigurableProduct\Model\Entity\Product\Attribute\Group\AttributeMapper\Plugin" sortOrder="50" />
3845
</type>

0 commit comments

Comments
 (0)