Skip to content

Commit 1ea2179

Browse files
author
Oleksandr Gorkun
committed
MC-18685: Remove custom layout updates from admin
1 parent c966fdc commit 1ea2179

File tree

6 files changed

+32
-28
lines changed

6 files changed

+32
-28
lines changed

app/code/Magento/Catalog/Model/Category/Attribute/Backend/LayoutUpdate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class LayoutUpdate extends AbstractLayoutUpdate
2525
private $manager;
2626

2727
/**
28-
* @param LayoutUpdateManager $manager
28+
* @param LayoutUpdateManager\Proxy $manager
2929
*/
30-
public function __construct(LayoutUpdateManager $manager)
30+
public function __construct(LayoutUpdateManager\Proxy $manager)
3131
{
3232
$this->manager = $manager;
3333
}

app/code/Magento/Catalog/Model/Category/Attribute/Source/LayoutUpdate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ class LayoutUpdate extends AbstractLayoutUpdate
2323
private $manager;
2424

2525
/**
26-
* @param LayoutUpdateManager $manager
26+
* @param LayoutUpdateManager\Proxy $manager
2727
*/
28-
public function __construct(LayoutUpdateManager $manager)
28+
public function __construct(LayoutUpdateManager\Proxy $manager)
2929
{
3030
$this->manager = $manager;
3131
}

app/code/Magento/Catalog/Model/Category/Authorization.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,16 @@ private function extractAttributeValue(CategoryModel $category, AttributeInterfa
7777
* Find values to compare the new one.
7878
*
7979
* @param AttributeInterface $attribute
80-
* @param CategoryModel|null $oldCategory
80+
* @param array|null $oldCategory
8181
* @return mixed[]
8282
*/
83-
private function fetchOldValue(AttributeInterface $attribute, ?CategoryModel $oldCategory): array
83+
private function fetchOldValue(AttributeInterface $attribute, ?array $oldCategory): array
8484
{
8585
$oldValues = [null];
86+
$attrCode = $attribute->getAttributeCode();
8687
if ($oldCategory) {
8788
//New value must match saved value exactly
88-
$oldValues = [$oldCategory->getData($attribute->getAttributeCode())];
89+
$oldValues = [!empty($oldCategory[$attrCode]) ? $oldCategory[$attrCode] : null];
8990
if (empty($oldValues[0])) {
9091
$oldValues[0] = null;
9192
}
@@ -101,10 +102,10 @@ private function fetchOldValue(AttributeInterface $attribute, ?CategoryModel $ol
101102
* Determine whether a category has design properties changed.
102103
*
103104
* @param CategoryModel $category
104-
* @param CategoryModel|null $oldCategory
105+
* @param array|null $oldCategory
105106
* @return bool
106107
*/
107-
private function hasChanges(CategoryModel $category, ?CategoryModel $oldCategory): bool
108+
private function hasChanges(CategoryModel $category, ?array $oldCategory): bool
108109
{
109110
foreach ($category->getDesignAttributes() as $designAttribute) {
110111
$oldValues = $this->fetchOldValue($designAttribute, $oldCategory);
@@ -134,21 +135,22 @@ private function hasChanges(CategoryModel $category, ?CategoryModel $oldCategory
134135
public function authorizeSavingOf(CategoryInterface $category): void
135136
{
136137
if (!$this->authorization->isAllowed('Magento_Catalog::edit_category_design')) {
137-
$savedCategory = null;
138+
$oldData = null;
138139
if ($category->getId()) {
139-
/** @var CategoryModel $savedCategory */
140-
$savedCategory = $this->categoryFactory->create();
141140
if ($category->getOrigData()) {
142-
$savedCategory->setData($category->getOrigData());
141+
$oldData = $category->getOrigData();
143142
} else {
143+
/** @var CategoryModel $savedCategory */
144+
$savedCategory = $this->categoryFactory->create();
144145
$savedCategory->load($category->getId());
145146
if (!$savedCategory->getName()) {
146147
throw NoSuchEntityException::singleField('id', $category->getId());
147148
}
149+
$oldData = $savedCategory->getData();
148150
}
149151
}
150152

151-
if ($this->hasChanges($category, $savedCategory)) {
153+
if ($this->hasChanges($category, $oldData)) {
152154
throw new AuthorizationException(__('Not allowed to edit the category\'s design attributes'));
153155
}
154156
}

app/code/Magento/Catalog/Model/Product/Attribute/Backend/LayoutUpdate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class LayoutUpdate extends AbstractLayoutUpdate
2525
private $manager;
2626

2727
/**
28-
* @param LayoutUpdateManager $manager
28+
* @param LayoutUpdateManager\Proxy $manager
2929
*/
30-
public function __construct(LayoutUpdateManager $manager)
30+
public function __construct(LayoutUpdateManager\Proxy $manager)
3131
{
3232
$this->manager = $manager;
3333
}

app/code/Magento/Catalog/Model/Product/Attribute/Source/LayoutUpdate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ class LayoutUpdate extends AbstractLayoutUpdate
2323
private $manager;
2424

2525
/**
26-
* @param LayoutUpdateManager $manager
26+
* @param LayoutUpdateManager\Proxy $manager
2727
*/
28-
public function __construct(LayoutUpdateManager $manager)
28+
public function __construct(LayoutUpdateManager\Proxy $manager)
2929
{
3030
$this->manager = $manager;
3131
}

app/code/Magento/Catalog/Model/Product/Authorization.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,15 @@ private function extractAttributeValue(ProductModel $product, AttributeInterface
7777
* Prepare old values to compare to.
7878
*
7979
* @param AttributeInterface $attribute
80-
* @param ProductModel|null $oldProduct
80+
* @param array|null $oldProduct
8181
* @return array
8282
*/
83-
private function fetchOldValues(AttributeInterface $attribute, ?ProductModel $oldProduct): array
83+
private function fetchOldValues(AttributeInterface $attribute, ?array $oldProduct): array
8484
{
85+
$attrCode = $attribute->getAttributeCode();
8586
if ($oldProduct) {
8687
//New value may only be the saved value
87-
$oldValues = [$oldProduct->getData($attribute->getAttributeCode())];
88+
$oldValues = [!empty($oldProduct[$attrCode]) ? $oldProduct[$attrCode] : null];
8889
if (empty($oldValues[0])) {
8990
$oldValues[0] = null;
9091
}
@@ -100,10 +101,10 @@ private function fetchOldValues(AttributeInterface $attribute, ?ProductModel $ol
100101
* Check whether the product has changed.
101102
*
102103
* @param ProductModel $product
103-
* @param ProductModel|null $oldProduct
104+
* @param array|null $oldProduct
104105
* @return bool
105106
*/
106-
private function hasProductChanged(ProductModel $product, ?ProductModel $oldProduct = null): bool
107+
private function hasProductChanged(ProductModel $product, ?array $oldProduct = null): bool
107108
{
108109
$designAttributes = [
109110
'custom_design',
@@ -147,20 +148,21 @@ private function hasProductChanged(ProductModel $product, ?ProductModel $oldProd
147148
public function authorizeSavingOf(ProductInterface $product): void
148149
{
149150
if (!$this->authorization->isAllowed('Magento_Catalog::edit_product_design')) {
150-
$savedProduct = null;
151+
$oldData = null;
151152
if ($product->getId()) {
152-
/** @var ProductModel $savedProduct */
153-
$savedProduct = $this->productFactory->create();
154153
if ($product->getOrigData()) {
155-
$savedProduct->setData($product->getOrigData());
154+
$oldData = $product->getOrigData();
156155
} else {
156+
/** @var ProductModel $savedProduct */
157+
$savedProduct = $this->productFactory->create();
157158
$savedProduct->load($product->getId());
158159
if (!$savedProduct->getSku()) {
159160
throw NoSuchEntityException::singleField('id', $product->getId());
160161
}
162+
$oldData = $product->getOrigData();
161163
}
162164
}
163-
if ($this->hasProductChanged($product, $savedProduct)) {
165+
if ($this->hasProductChanged($product, $oldData)) {
164166
throw new AuthorizationException(__('Not allowed to edit the product\'s design attributes'));
165167
}
166168
}

0 commit comments

Comments
 (0)