Skip to content

Commit 3db1dfa

Browse files
committed
Merge branch '2.3-develop' of github.com:magento/magento2ce into 2.3-develop
2 parents 5e6d06a + ed8b676 commit 3db1dfa

File tree

92 files changed

+1801
-639
lines changed

Some content is hidden

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

92 files changed

+1801
-639
lines changed

app/code/Magento/Backend/etc/adminhtml/system.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@
234234
<field id="destinations" translate="label" type="multiselect" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
235235
<label>Top destinations</label>
236236
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
237+
<can_be_empty>1</can_be_empty>
237238
</field>
238239
</group>
239240
<group id="locale" translate="label" type="text" sortOrder="8" showInDefault="1" showInWebsite="1" showInStore="1">

app/code/Magento/Catalog/Controller/Adminhtml/Product/Builder.php

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
use Magento\Store\Model\StoreFactory;
1212
use Psr\Log\LoggerInterface as Logger;
1313
use Magento\Framework\Registry;
14+
use Magento\Catalog\Api\ProductRepositoryInterface;
15+
use Magento\Catalog\Model\Product;
16+
use Magento\Catalog\Model\Product\Type as ProductTypes;
1417

1518
class Builder
1619
{
@@ -39,6 +42,11 @@ class Builder
3942
*/
4043
protected $storeFactory;
4144

45+
/**
46+
* @var ProductRepositoryInterface
47+
*/
48+
private $productRepository;
49+
4250
/**
4351
* Constructor
4452
*
@@ -47,61 +55,87 @@ class Builder
4755
* @param Registry $registry
4856
* @param WysiwygModel\Config $wysiwygConfig
4957
* @param StoreFactory|null $storeFactory
58+
* @param ProductRepositoryInterface|null $productRepository
5059
*/
5160
public function __construct(
5261
ProductFactory $productFactory,
5362
Logger $logger,
5463
Registry $registry,
5564
WysiwygModel\Config $wysiwygConfig,
56-
StoreFactory $storeFactory = null
65+
StoreFactory $storeFactory = null,
66+
ProductRepositoryInterface $productRepository = null
5767
) {
5868
$this->productFactory = $productFactory;
5969
$this->logger = $logger;
6070
$this->registry = $registry;
6171
$this->wysiwygConfig = $wysiwygConfig;
6272
$this->storeFactory = $storeFactory ?: \Magento\Framework\App\ObjectManager::getInstance()
6373
->get(\Magento\Store\Model\StoreFactory::class);
74+
$this->productRepository = $productRepository ?: \Magento\Framework\App\ObjectManager::getInstance()
75+
->get(ProductRepositoryInterface::class);
6476
}
6577

6678
/**
6779
* Build product based on user request
6880
*
6981
* @param RequestInterface $request
7082
* @return \Magento\Catalog\Model\Product
83+
* @throws \RuntimeException
7184
*/
7285
public function build(RequestInterface $request)
7386
{
74-
$productId = (int)$request->getParam('id');
75-
/** @var $product \Magento\Catalog\Model\Product */
76-
$product = $this->productFactory->create();
77-
$product->setStoreId($request->getParam('store', 0));
78-
$store = $this->storeFactory->create();
79-
$store->load($request->getParam('store', 0));
80-
87+
$productId = (int) $request->getParam('id');
88+
$storeId = $request->getParam('store', 0);
89+
$attributeSetId = (int) $request->getParam('set');
8190
$typeId = $request->getParam('type');
82-
if (!$productId && $typeId) {
83-
$product->setTypeId($typeId);
84-
}
8591

86-
$product->setData('_edit_mode', true);
8792
if ($productId) {
8893
try {
89-
$product->load($productId);
94+
$product = $this->productRepository->getById($productId, true, $storeId);
9095
} catch (\Exception $e) {
91-
$product->setTypeId(\Magento\Catalog\Model\Product\Type::DEFAULT_TYPE);
96+
$product = $this->createEmptyProduct(ProductTypes::DEFAULT_TYPE, $attributeSetId, $storeId);
9297
$this->logger->critical($e);
9398
}
99+
} else {
100+
$product = $this->createEmptyProduct($typeId, $attributeSetId, $storeId);
94101
}
95102

96-
$setId = (int)$request->getParam('set');
97-
if ($setId) {
98-
$product->setAttributeSetId($setId);
99-
}
103+
$store = $this->storeFactory->create();
104+
$store->load($storeId);
100105

101106
$this->registry->register('product', $product);
102107
$this->registry->register('current_product', $product);
103108
$this->registry->register('current_store', $store);
104-
$this->wysiwygConfig->setStoreId($request->getParam('store'));
109+
110+
$this->wysiwygConfig->setStoreId($storeId);
111+
112+
return $product;
113+
}
114+
115+
/**
116+
* @param int $typeId
117+
* @param int $attributeSetId
118+
* @param int $storeId
119+
* @return \Magento\Catalog\Model\Product
120+
*/
121+
private function createEmptyProduct($typeId, $attributeSetId, $storeId): Product
122+
{
123+
/** @var $product \Magento\Catalog\Model\Product */
124+
$product = $this->productFactory->create();
125+
$product->setData('_edit_mode', true);
126+
127+
if ($typeId !== null) {
128+
$product->setTypeId($typeId);
129+
}
130+
131+
if ($storeId !== null) {
132+
$product->setStoreId($storeId);
133+
}
134+
135+
if ($attributeSetId) {
136+
$product->setAttributeSetId($attributeSetId);
137+
}
138+
105139
return $product;
106140
}
107141
}

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

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@
77

88
use Magento\Catalog\Api\CategoryRepositoryInterface;
99
use Magento\Catalog\Api\Data\CategoryInterface;
10-
use Magento\Catalog\Model\Entity\GetCategoryCustomAttributeCodes;
1110
use Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator;
12-
use Magento\Eav\Model\Entity\GetCustomAttributeCodesInterface;
1311
use Magento\Framework\Api\AttributeValueFactory;
14-
use Magento\Framework\App\ObjectManager;
1512
use Magento\Framework\Convert\ConvertArray;
1613
use Magento\Framework\Exception\NoSuchEntityException;
1714
use Magento\Framework\Profiler;
@@ -214,11 +211,6 @@ class Category extends \Magento\Catalog\Model\AbstractModel implements
214211
*/
215212
protected $metadataService;
216213

217-
/**
218-
* @var GetCustomAttributeCodesInterface
219-
*/
220-
private $getCustomAttributeCodes;
221-
222214
/**
223215
* @param \Magento\Framework\Model\Context $context
224216
* @param \Magento\Framework\Registry $registry
@@ -241,7 +233,6 @@ class Category extends \Magento\Catalog\Model\AbstractModel implements
241233
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
242234
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
243235
* @param array $data
244-
* @param GetCustomAttributeCodesInterface|null $getCustomAttributeCodes
245236
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
246237
*/
247238
public function __construct(
@@ -265,8 +256,7 @@ public function __construct(
265256
CategoryRepositoryInterface $categoryRepository,
266257
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
267258
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
268-
array $data = [],
269-
GetCustomAttributeCodesInterface $getCustomAttributeCodes = null
259+
array $data = []
270260
) {
271261
$this->metadataService = $metadataService;
272262
$this->_treeModel = $categoryTreeResource;
@@ -281,9 +271,6 @@ public function __construct(
281271
$this->urlFinder = $urlFinder;
282272
$this->indexerRegistry = $indexerRegistry;
283273
$this->categoryRepository = $categoryRepository;
284-
$this->getCustomAttributeCodes = $getCustomAttributeCodes ?? ObjectManager::getInstance()->get(
285-
GetCategoryCustomAttributeCodes::class
286-
);
287274
parent::__construct(
288275
$context,
289276
$registry,
@@ -317,7 +304,11 @@ protected function _construct()
317304
*/
318305
protected function getCustomAttributesCodes()
319306
{
320-
return $this->getCustomAttributeCodes->execute($this->metadataService);
307+
if ($this->customAttributesCodes === null) {
308+
$this->customAttributesCodes = $this->getEavAttributesCodes($this->metadataService);
309+
$this->customAttributesCodes = array_diff($this->customAttributesCodes, CategoryInterface::ATTRIBUTES);
310+
}
311+
return $this->customAttributesCodes;
321312
}
322313

323314
/**

app/code/Magento/Catalog/Model/Entity/GetCategoryCustomAttributeCodes.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

app/code/Magento/Catalog/Model/Entity/GetProductCustomAttributeCodes.php

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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\Catalog\Model;
9+
10+
/**
11+
* Filter custom attributes for product using the blacklist
12+
*/
13+
class FilterProductCustomAttribute
14+
{
15+
/**
16+
* @var array
17+
*/
18+
private $blackList;
19+
20+
/**
21+
* @param array $blackList
22+
*/
23+
public function __construct(array $blackList = [])
24+
{
25+
$this->blackList = $blackList;
26+
}
27+
28+
/**
29+
* Delete custom attribute
30+
* @param array $attributes
31+
* @return array
32+
*/
33+
public function execute(array $attributes): array
34+
{
35+
return array_diff($attributes, $this->blackList);
36+
}
37+
}

0 commit comments

Comments
 (0)