Skip to content

Commit 357caac

Browse files
committed
530 - [Cart Operations] Update Cart Items validation messages
Merge remote-tracking branch 'origin/2.3-develop' into 530-update-cart-items-validation-messages # Conflicts: # dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/AddSimpleProductToCartTest.php
2 parents e627992 + 4f6c78e commit 357caac

File tree

100 files changed

+3827
-381
lines changed

Some content is hidden

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

100 files changed

+3827
-381
lines changed

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
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+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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\Observer;
9+
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\CatalogUrlRewrite\Model\Products\AdaptUrlRewritesToVisibilityAttribute;
12+
use Magento\Framework\Event\Observer;
13+
use Magento\Framework\Event\ObserverInterface;
14+
use Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException;
15+
16+
/**
17+
* Consider URL rewrites on change product visibility via mass action
18+
*/
19+
class ProcessUrlRewriteOnChangeProductVisibilityObserver implements ObserverInterface
20+
{
21+
/**
22+
* @var AdaptUrlRewritesToVisibilityAttribute
23+
*/
24+
private $adaptUrlRewritesToVisibility;
25+
26+
/**
27+
* @param AdaptUrlRewritesToVisibilityAttribute $adaptUrlRewritesToVisibility
28+
*/
29+
public function __construct(AdaptUrlRewritesToVisibilityAttribute $adaptUrlRewritesToVisibility)
30+
{
31+
$this->adaptUrlRewritesToVisibility = $adaptUrlRewritesToVisibility;
32+
}
33+
34+
/**
35+
* Generate urls for UrlRewrites and save it in storage
36+
*
37+
* @param Observer $observer
38+
* @return void
39+
* @throws UrlAlreadyExistsException
40+
*/
41+
public function execute(Observer $observer)
42+
{
43+
$event = $observer->getEvent();
44+
$attrData = $event->getAttributesData();
45+
$productIds = $event->getProductIds();
46+
$visibility = $attrData[ProductInterface::VISIBILITY] ?? 0;
47+
48+
if (!$visibility || !$productIds) {
49+
return;
50+
}
51+
52+
$this->adaptUrlRewritesToVisibility->execute($productIds, (int)$visibility);
53+
}
54+
}

app/code/Magento/CatalogUrlRewrite/etc/events.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
<event name="catalog_product_save_after">
2828
<observer name="process_url_rewrite_saving" instance="Magento\CatalogUrlRewrite\Observer\ProductProcessUrlRewriteSavingObserver"/>
2929
</event>
30+
<event name="catalog_product_attribute_update_before">
31+
<observer name="process_url_rewrite_on_change_product_visibility" instance="Magento\CatalogUrlRewrite\Observer\ProcessUrlRewriteOnChangeProductVisibilityObserver"/>
32+
</event>
3033
<event name="catalog_category_save_before">
3134
<observer name="category_url_path_autogeneration" instance="Magento\CatalogUrlRewrite\Observer\CategoryUrlPathAutogeneratorObserver"/>
3235
</event>

app/code/Magento/CheckoutAgreements/view/frontend/layout/multishipping_checkout_overview.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
99
<body>
1010
<referenceBlock name="checkout_overview">
11-
<block class="Magento\CheckoutAgreements\Block\Agreements" name="checkout.multishipping.agreements" as="agreements" template="Magento_CheckoutAgreements::multishipping_agreements.phtml"/>
11+
<block class="Magento\CheckoutAgreements\Block\Agreements" name="checkout.multishipping.agreements" as="agreements" template="Magento_CheckoutAgreements::additional_agreements.phtml"/>
1212
</referenceBlock>
1313
</body>
1414
</page>

app/code/Magento/CheckoutAgreements/view/frontend/templates/multishipping_agreements.phtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
// @deprecated
78
// @codingStandardsIgnoreFile
89

910
?>

app/code/Magento/Cms/Model/Wysiwyg/Images/Storage.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ public function getDirsCollection($path)
270270
$collection = $this->getCollection($path)
271271
->setCollectDirs(true)
272272
->setCollectFiles(false)
273-
->setCollectRecursively(false);
273+
->setCollectRecursively(false)
274+
->setOrder('basename', \Magento\Framework\Data\Collection\Filesystem::SORT_ORDER_ASC);
274275

275276
$conditions = $this->getConditionsForExcludeDirs();
276277

app/code/Magento/Cms/Test/Unit/Model/Wysiwyg/Images/StorageTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,10 @@ protected function generalTestGetDirsCollection($path, $collectionArray = [], $e
417417
->method('setCollectRecursively')
418418
->with(false)
419419
->willReturnSelf();
420+
$storageCollectionMock->expects($this->once())
421+
->method('setOrder')
422+
->with('basename', \Magento\Framework\Data\Collection\Filesystem::SORT_ORDER_ASC)
423+
->willReturnSelf();
420424
$storageCollectionMock->expects($this->once())
421425
->method('getIterator')
422426
->willReturn(new \ArrayIterator($collectionArray));

0 commit comments

Comments
 (0)