Skip to content

Commit 2cf1773

Browse files
committed
MC-40777: Cannot save product in store view scope without Magento_Catalog::edit_product_design
1 parent 804f355 commit 2cf1773

File tree

4 files changed

+81
-21
lines changed

4 files changed

+81
-21
lines changed

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

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
use Magento\Catalog\Model\Product as ProductModel;
1313
use Magento\Catalog\Model\ProductFactory;
1414
use Magento\Eav\Api\Data\AttributeInterface;
15-
use Magento\Framework\App\ObjectManager;
16-
use Magento\Framework\App\RequestInterface;
1715
use Magento\Framework\AuthorizationInterface;
1816
use Magento\Framework\Exception\AuthorizationException;
1917
use Magento\Framework\Exception\NoSuchEntityException;
@@ -34,24 +32,14 @@ class Authorization
3432
*/
3533
private $productFactory;
3634

37-
/**
38-
* @var RequestInterface
39-
*/
40-
private $request;
41-
4235
/**
4336
* @param AuthorizationInterface $authorization
4437
* @param ProductFactory $factory
45-
* @param RequestInterface|null $request
4638
*/
47-
public function __construct(
48-
AuthorizationInterface $authorization,
49-
ProductFactory $factory,
50-
?RequestInterface $request = null
51-
) {
39+
public function __construct(AuthorizationInterface $authorization, ProductFactory $factory)
40+
{
5241
$this->authorization = $authorization;
5342
$this->productFactory = $factory;
54-
$this->request = $request ?: ObjectManager::getInstance()->get(RequestInterface::class);;
5543
}
5644

5745
/**
@@ -133,10 +121,6 @@ private function hasProductChanged(ProductModel $product, ?array $oldProduct = n
133121
if (!array_key_exists($designAttribute, $attributes)) {
134122
continue;
135123
}
136-
$useDefaults = (array) $this->request->getPost('use_default', []);
137-
if (isset($useDefaults[$designAttribute]) && $useDefaults[$designAttribute]) {
138-
continue;
139-
}
140124
$attribute = $attributes[$designAttribute];
141125
$oldValues = $this->fetchOldValues($attribute, $oldProduct);
142126
try {
@@ -145,6 +129,9 @@ private function hasProductChanged(ProductModel $product, ?array $oldProduct = n
145129
//No new value
146130
continue;
147131
}
132+
if ($attribute->getBackendType() == 'datetime' && empty($newValue)) {
133+
continue;
134+
}
148135
if (!in_array($newValue, $oldValues, true)) {
149136
return true;
150137
}

dev/tests/integration/testsuite/Magento/Catalog/Model/Product/AuthorizationTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected function setUp(): void
5858
/**
5959
* Verify AuthorizedSavingOf
6060
*
61-
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
61+
* @magentoDataFixture Magento/Catalog/_files/product_simple_with_design_attributes.php
6262
* @param array $data
6363
*
6464
* @dataProvider postRequestData
@@ -114,8 +114,8 @@ public function postRequestData(): array
114114
'page_layout' => '',
115115
'options_container' => 'container2',
116116
'custom_design' => '',
117-
'custom_design_from' => '',
118-
'custom_design_to' => '',
117+
'custom_design_from' => '2020-01-02',
118+
'custom_design_to' => '2020-01-03',
119119
'custom_layout' => '',
120120
'custom_layout_update_file' => '__no_update__',
121121
],
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
use Magento\Catalog\Api\ProductRepositoryInterface;
9+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
10+
use Magento\Catalog\Model\Product\Type;
11+
use Magento\Catalog\Model\Product\Visibility;
12+
use Magento\Catalog\Model\ProductFactory;
13+
use Magento\Store\Api\WebsiteRepositoryInterface;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
16+
$objectManager = Bootstrap::getObjectManager();
17+
/** @var ProductFactory $productFactory */
18+
$productFactory = $objectManager->get(ProductFactory::class);
19+
/** @var WebsiteRepositoryInterface $websiteRepository */
20+
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
21+
$defaultWebsiteId = $websiteRepository->get('base')->getId();
22+
$product = $productFactory->create();
23+
$product->isObjectNew(true);
24+
$product->setTypeId(Type::TYPE_SIMPLE)
25+
->setAttributeSetId($product->getDefaultAttributeSetId())
26+
->setWebsiteIds([$defaultWebsiteId])
27+
->setName('Simple with design attribute')
28+
->setSku('simple_design_attribute')
29+
->setPrice(10)
30+
->setWeight(1)
31+
->setShortDescription('Short description')
32+
->setTaxClassId(0)
33+
->setDescription('Description with <b>html tag</b>')
34+
->setMetaTitle('meta title')
35+
->setMetaKeyword('meta keyword')
36+
->setMetaDescription('meta description')
37+
->setVisibility(Visibility::VISIBILITY_BOTH)
38+
->setStatus(Status::STATUS_ENABLED)
39+
->setStockData(['use_config_manage_stock' => 0])
40+
->setCanSaveCustomOptions(true)
41+
->setCustomDesignFrom('2020-01-02')
42+
->setCustomDesignTo('2020-01-03')
43+
->setHasOptions(true);
44+
/** @var ProductRepositoryInterface $productRepositoryFactory */
45+
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
46+
$productRepository->save($product);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
use Magento\Framework\Exception\NoSuchEntityException;
9+
10+
\Magento\TestFramework\Helper\Bootstrap::getInstance()->getInstance()->reinitialize();
11+
12+
/** @var \Magento\Framework\Registry $registry */
13+
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
14+
15+
$registry->unregister('isSecureArea');
16+
$registry->register('isSecureArea', true);
17+
18+
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
19+
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
20+
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
21+
try {
22+
$product = $productRepository->get('simple_design_attribute', false, null, true);
23+
$productRepository->delete($product);
24+
} catch (NoSuchEntityException $e) {
25+
}
26+
$registry->unregister('isSecureArea');
27+
$registry->register('isSecureArea', false);

0 commit comments

Comments
 (0)