Skip to content

Commit b2571e3

Browse files
committed
Merge remote-tracking branch 'magento/2.3-develop' into MC-15427
2 parents 348edaa + 70bf7c6 commit b2571e3

File tree

161 files changed

+5760
-1291
lines changed

Some content is hidden

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

161 files changed

+5760
-1291
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ atlassian*
4848
/pub/media/import/*
4949
!/pub/media/import/.htaccess
5050
/pub/media/logo/*
51+
/pub/media/custom_options/*
52+
!/pub/media/custom_options/.htaccess
5153
/pub/media/theme/*
5254
/pub/media/theme_customization/*
5355
!/pub/media/theme_customization/.htaccess

app/code/Magento/AsynchronousOperations/Model/MassSchedule.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Psr\Log\LoggerInterface;
2121
use Magento\AsynchronousOperations\Model\ResourceModel\Operation\OperationRepository;
2222
use Magento\Authorization\Model\UserContextInterface;
23+
use Magento\Framework\Encryption\Encryptor;
2324

2425
/**
2526
* Class MassSchedule used for adding multiple entities as Operations to Bulk Management with the status tracking
@@ -63,6 +64,11 @@ class MassSchedule
6364
*/
6465
private $userContext;
6566

67+
/**
68+
* @var Encryptor
69+
*/
70+
private $encryptor;
71+
6672
/**
6773
* Initialize dependencies.
6874
*
@@ -73,6 +79,7 @@ class MassSchedule
7379
* @param LoggerInterface $logger
7480
* @param OperationRepository $operationRepository
7581
* @param UserContextInterface $userContext
82+
* @param Encryptor|null $encryptor
7683
*/
7784
public function __construct(
7885
IdentityGeneratorInterface $identityService,
@@ -81,7 +88,8 @@ public function __construct(
8188
BulkManagementInterface $bulkManagement,
8289
LoggerInterface $logger,
8390
OperationRepository $operationRepository,
84-
UserContextInterface $userContext = null
91+
UserContextInterface $userContext = null,
92+
Encryptor $encryptor = null
8593
) {
8694
$this->identityService = $identityService;
8795
$this->itemStatusInterfaceFactory = $itemStatusInterfaceFactory;
@@ -90,6 +98,7 @@ public function __construct(
9098
$this->logger = $logger;
9199
$this->operationRepository = $operationRepository;
92100
$this->userContext = $userContext ?: ObjectManager::getInstance()->get(UserContextInterface::class);
101+
$this->encryptor = $encryptor ?: ObjectManager::getInstance()->get(Encryptor::class);
93102
}
94103

95104
/**
@@ -130,9 +139,13 @@ public function publishMass($topicName, array $entitiesArray, $groupId = null, $
130139
$requestItem = $this->itemStatusInterfaceFactory->create();
131140

132141
try {
133-
$operations[] = $this->operationRepository->createByTopic($topicName, $entityParams, $groupId);
142+
$operation = $this->operationRepository->createByTopic($topicName, $entityParams, $groupId);
143+
$operations[] = $operation;
134144
$requestItem->setId($key);
135145
$requestItem->setStatus(ItemStatusInterface::STATUS_ACCEPTED);
146+
$requestItem->setDataHash(
147+
$this->encryptor->hash($operation->getSerializedData(), Encryptor::HASH_VERSION_SHA256)
148+
);
136149
$requestItems[] = $requestItem;
137150
} catch (\Exception $exception) {
138151
$this->logger->error($exception);

app/code/Magento/Backend/Block/Widget/Grid/Massaction/AbstractMassaction.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -282,25 +282,23 @@ public function getGridIdsJson()
282282
if (!$this->getUseSelectAll()) {
283283
return '';
284284
}
285-
/** @var \Magento\Framework\Data\Collection $allIdsCollection */
286-
$allIdsCollection = clone $this->getParentBlock()->getCollection();
287285

288-
if ($this->getMassactionIdField()) {
289-
$massActionIdField = $this->getMassactionIdField();
286+
/** @var \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection $collection */
287+
$collection = clone $this->getParentBlock()->getCollection();
288+
289+
if ($collection instanceof AbstractDb) {
290+
$idsSelect = clone $collection->getSelect();
291+
$idsSelect->reset(\Magento\Framework\DB\Select::ORDER);
292+
$idsSelect->reset(\Magento\Framework\DB\Select::LIMIT_COUNT);
293+
$idsSelect->reset(\Magento\Framework\DB\Select::LIMIT_OFFSET);
294+
$idsSelect->reset(\Magento\Framework\DB\Select::COLUMNS);
295+
$idsSelect->columns($this->getMassactionIdField(), 'main_table');
296+
$idList = $collection->getConnection()->fetchCol($idsSelect);
290297
} else {
291-
$massActionIdField = $this->getParentBlock()->getMassactionIdField();
298+
$idList = $collection->setPageSize(0)->getColumnValues($this->getMassactionIdField());
292299
}
293300

294-
if ($allIdsCollection instanceof AbstractDb) {
295-
$allIdsCollection->getSelect()->limit();
296-
$allIdsCollection->clear();
297-
}
298-
299-
$gridIds = $allIdsCollection->setPageSize(0)->getColumnValues($massActionIdField);
300-
if (!empty($gridIds)) {
301-
return join(",", $gridIds);
302-
}
303-
return '';
301+
return implode(',', $idList);
304302
}
305303

306304
/**

app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/MassactionTest.php

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -269,62 +269,6 @@ public function testGetGridIdsJsonWithoutUseSelectAll()
269269
$this->assertEmpty($this->_block->getGridIdsJson());
270270
}
271271

272-
/**
273-
* @param array $items
274-
* @param string $result
275-
*
276-
* @dataProvider dataProviderGetGridIdsJsonWithUseSelectAll
277-
*/
278-
public function testGetGridIdsJsonWithUseSelectAll(array $items, $result)
279-
{
280-
$this->_block->setUseSelectAll(true);
281-
282-
if ($this->_block->getMassactionIdField()) {
283-
$massActionIdField = $this->_block->getMassactionIdField();
284-
} else {
285-
$massActionIdField = $this->_block->getParentBlock()->getMassactionIdField();
286-
}
287-
288-
$collectionMock = $this->getMockBuilder(\Magento\Framework\Data\Collection::class)
289-
->disableOriginalConstructor()
290-
->getMock();
291-
292-
$this->_gridMock->expects($this->once())
293-
->method('getCollection')
294-
->willReturn($collectionMock);
295-
$collectionMock->expects($this->once())
296-
->method('setPageSize')
297-
->with(0)
298-
->willReturnSelf();
299-
$collectionMock->expects($this->once())
300-
->method('getColumnValues')
301-
->with($massActionIdField)
302-
->willReturn($items);
303-
304-
$this->assertEquals($result, $this->_block->getGridIdsJson());
305-
}
306-
307-
/**
308-
* @return array
309-
*/
310-
public function dataProviderGetGridIdsJsonWithUseSelectAll()
311-
{
312-
return [
313-
[
314-
[],
315-
'',
316-
],
317-
[
318-
[1],
319-
'1',
320-
],
321-
[
322-
[1, 2, 3],
323-
'1,2,3',
324-
],
325-
];
326-
}
327-
328272
/**
329273
* @param string $itemId
330274
* @param array|\Magento\Framework\DataObject $item

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ public function execute()
159159
if ($redirectBack === 'duplicate') {
160160
$product->unsetData('quantity_and_stock_status');
161161
$newProduct = $this->productCopier->copy($product);
162+
$this->checkUniqueAttributes($product);
162163
$this->messageManager->addSuccessMessage(__('You duplicated the product.'));
163164
}
164165
} catch (\Magento\Framework\Exception\LocalizedException $e) {
@@ -343,4 +344,25 @@ private function persistMediaData(ProductInterface $product, array $data)
343344

344345
return $data;
345346
}
347+
348+
/**
349+
* Check unique attributes and add error to message manager
350+
*
351+
* @param \Magento\Catalog\Model\Product $product
352+
*/
353+
private function checkUniqueAttributes(\Magento\Catalog\Model\Product $product)
354+
{
355+
$uniqueLabels = [];
356+
foreach ($product->getAttributes() as $attribute) {
357+
if ($attribute->getIsUnique() && $attribute->getIsUserDefined()
358+
&& $product->getData($attribute->getAttributeCode()) !== null
359+
) {
360+
$uniqueLabels[] = $attribute->getDefaultFrontendLabel();
361+
}
362+
}
363+
if ($uniqueLabels) {
364+
$uniqueLabels = implode('", "', $uniqueLabels);
365+
$this->messageManager->addErrorMessage(__('The value of attribute(s) "%1" must be unique', $uniqueLabels));
366+
}
367+
}
346368
}

app/code/Magento/Catalog/Test/Mftf/Data/ProductData.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,11 @@
428428
<var key="sku" entityType="product" entityKey="sku" />
429429
<requiredEntity type="product_option">ProductOptionDropDownWithLongValuesTitle</requiredEntity>
430430
</entity>
431+
<entity name="ProductWithTextFieldAndAreaOptions" type="product">
432+
<var key="sku" entityType="product" entityKey="sku" />
433+
<requiredEntity type="product_option">ProductOptionField</requiredEntity>
434+
<requiredEntity type="product_option">ProductOptionArea</requiredEntity>
435+
</entity>
431436
<entity name="ApiVirtualProductWithDescription" type="product">
432437
<data key="sku" unique="suffix">api-virtual-product</data>
433438
<data key="type_id">virtual</data>

app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCustomProductAttributeWithDropdownFieldTest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
<severity value="CRITICAL"/>
1717
<testCaseId value="MC-10905"/>
1818
<group value="mtf_migrated"/>
19+
<skip>
20+
<issueId value="MC-15474"/>
21+
</skip>
1922
</annotations>
2023

2124
<before>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<field id="grid_per_page_values" translate="label comment" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
6060
<label>Products per Page on Grid Allowed Values</label>
6161
<comment>Comma-separated.</comment>
62-
<validate>validate-per-page-value-list</validate>
62+
<validate>validate-per-page-value-list required-entry</validate>
6363
</field>
6464
<field id="grid_per_page" translate="label comment" type="text" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
6565
<label>Products per Page on Grid Default Value</label>
@@ -69,7 +69,7 @@
6969
<field id="list_per_page_values" translate="label comment" type="text" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
7070
<label>Products per Page on List Allowed Values</label>
7171
<comment>Comma-separated.</comment>
72-
<validate>validate-per-page-value-list</validate>
72+
<validate>validate-per-page-value-list required-entry</validate>
7373
</field>
7474
<field id="list_per_page" translate="label comment" type="text" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
7575
<label>Products per Page on List Default Value</label>
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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\CatalogUrlRewrite\Model\Products;
9+
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Catalog\Model\Product;
12+
use Magento\Catalog\Model\Product\Visibility;
13+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
14+
use Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator;
15+
use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator;
16+
use Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException;
17+
use Magento\UrlRewrite\Model\UrlPersistInterface;
18+
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
19+
20+
/**
21+
* Save/Delete UrlRewrites by Product ID's and visibility
22+
*/
23+
class AdaptUrlRewritesToVisibilityAttribute
24+
{
25+
/**
26+
* @var CollectionFactory
27+
*/
28+
private $productCollectionFactory;
29+
30+
/**
31+
* @var ProductUrlRewriteGenerator
32+
*/
33+
private $urlRewriteGenerator;
34+
35+
/**
36+
* @var UrlPersistInterface
37+
*/
38+
private $urlPersist;
39+
40+
/**
41+
* @var ProductUrlPathGenerator
42+
*/
43+
private $urlPathGenerator;
44+
45+
/**
46+
* @param CollectionFactory $collectionFactory
47+
* @param ProductUrlRewriteGenerator $urlRewriteGenerator
48+
* @param UrlPersistInterface $urlPersist
49+
* @param ProductUrlPathGenerator|null $urlPathGenerator
50+
*/
51+
public function __construct(
52+
CollectionFactory $collectionFactory,
53+
ProductUrlRewriteGenerator $urlRewriteGenerator,
54+
UrlPersistInterface $urlPersist,
55+
ProductUrlPathGenerator $urlPathGenerator
56+
) {
57+
$this->productCollectionFactory = $collectionFactory;
58+
$this->urlRewriteGenerator = $urlRewriteGenerator;
59+
$this->urlPersist = $urlPersist;
60+
$this->urlPathGenerator = $urlPathGenerator;
61+
}
62+
63+
/**
64+
* Process Url Rewrites according to the products visibility attribute
65+
*
66+
* @param array $productIds
67+
* @param int $visibility
68+
* @throws UrlAlreadyExistsException
69+
*/
70+
public function execute(array $productIds, int $visibility): void
71+
{
72+
$products = $this->getProductsByIds($productIds);
73+
74+
/** @var Product $product */
75+
foreach ($products as $product) {
76+
if ($visibility == Visibility::VISIBILITY_NOT_VISIBLE) {
77+
$this->urlPersist->deleteByData(
78+
[
79+
UrlRewrite::ENTITY_ID => $product->getId(),
80+
UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE,
81+
]
82+
);
83+
} elseif ($visibility !== Visibility::VISIBILITY_NOT_VISIBLE) {
84+
$product->setVisibility($visibility);
85+
$productUrlPath = $this->urlPathGenerator->getUrlPath($product);
86+
$productUrlRewrite = $this->urlRewriteGenerator->generate($product);
87+
$product->unsUrlPath();
88+
$product->setUrlPath($productUrlPath);
89+
90+
try {
91+
$this->urlPersist->replace($productUrlRewrite);
92+
} catch (UrlAlreadyExistsException $e) {
93+
throw new UrlAlreadyExistsException(
94+
__(
95+
'Can not change the visibility of the product with SKU equals "%1". '
96+
. 'URL key "%2" for specified store already exists.',
97+
$product->getSku(),
98+
$product->getUrlKey()
99+
),
100+
$e,
101+
$e->getCode(),
102+
$e->getUrls()
103+
);
104+
}
105+
}
106+
}
107+
}
108+
109+
/**
110+
* Get Product Models by Id's
111+
*
112+
* @param array $productIds
113+
* @return array
114+
*/
115+
private function getProductsByIds(array $productIds): array
116+
{
117+
$productCollection = $this->productCollectionFactory->create();
118+
$productCollection->addAttributeToSelect(ProductInterface::VISIBILITY);
119+
$productCollection->addAttributeToSelect('url_key');
120+
$productCollection->addFieldToFilter(
121+
'entity_id',
122+
['in' => array_unique($productIds)]
123+
);
124+
125+
return $productCollection->getItems();
126+
}
127+
}

0 commit comments

Comments
 (0)