Skip to content

Commit 7de0949

Browse files
committed
Merge branch '2.3-develop' into MC-20675
2 parents 4d7b951 + d271281 commit 7de0949

File tree

15 files changed

+2611
-459
lines changed

15 files changed

+2611
-459
lines changed

app/code/Magento/Catalog/Ui/Component/UrlInput/Product.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
use Magento\Framework\UrlInterface;
1212

13+
/**
14+
* Returns configuration for product Url Input type
15+
*/
1316
class Product implements \Magento\Ui\Model\UrlInput\ConfigInterface
1417
{
1518
/**
@@ -27,7 +30,7 @@ public function __construct(UrlInterface $urlBuilder)
2730
}
2831

2932
/**
30-
* {@inheritdoc}
33+
* @inheritdoc
3134
*/
3235
public function getConfig(): array
3336
{
@@ -46,6 +49,7 @@ public function getConfig(): array
4649
'template' => 'ui/grid/filters/elements/ui-select',
4750
'searchUrl' => $this->urlBuilder->getUrl('catalog/product/search'),
4851
'filterPlaceholder' => __('Product Name or SKU'),
52+
'filterRateLimitMethod' => 'notifyWhenChangesStop',
4953
'isDisplayEmptyPlaceholder' => true,
5054
'emptyOptionsHtml' => __('Start typing to find products'),
5155
'missingValuePlaceholder' => __('Product with ID: %s doesn\'t exist'),
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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\CatalogGraphQl\Plugin;
9+
10+
use Magento\Catalog\Model\Product;
11+
use Magento\Framework\Message\MessageInterface;
12+
use Magento\Framework\View\DesignLoader as ViewDesignLoader;
13+
use Magento\Framework\Message\ManagerInterface;
14+
use Magento\Catalog\Block\Product\ImageFactory;
15+
16+
/**
17+
* Load necessary design files for GraphQL
18+
*/
19+
class DesignLoader
20+
{
21+
/**
22+
* @var DesignLoader
23+
*/
24+
private $designLoader;
25+
26+
/**
27+
* @var ManagerInterface
28+
*/
29+
private $messageManager;
30+
31+
/**
32+
* @param ViewDesignLoader $designLoader
33+
* @param ManagerInterface $messageManager
34+
*/
35+
public function __construct(
36+
ViewDesignLoader $designLoader,
37+
ManagerInterface $messageManager
38+
) {
39+
$this->designLoader = $designLoader;
40+
$this->messageManager = $messageManager;
41+
}
42+
43+
/**
44+
* Before create load the design files
45+
*
46+
* @param ImageFactory $subject
47+
* @param Product $product
48+
* @param string $imageId
49+
* @param array|null $attributes
50+
*
51+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
52+
*/
53+
public function beforeCreate(
54+
ImageFactory $subject,
55+
Product $product,
56+
string $imageId,
57+
array $attributes = null
58+
) {
59+
try {
60+
$this->designLoader->load();
61+
} catch (\Magento\Framework\Exception\LocalizedException $e) {
62+
if ($e->getPrevious() instanceof \Magento\Framework\Config\Dom\ValidationException) {
63+
/** @var MessageInterface $message */
64+
$message = $this->messageManager
65+
->createMessage(MessageInterface::TYPE_ERROR)
66+
->setText($e->getMessage());
67+
$this->messageManager->addUniqueMessages([$message]);
68+
}
69+
}
70+
}
71+
}

app/code/Magento/CatalogGraphQl/etc/graphql/di.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,8 @@
137137
</argument>
138138
</arguments>
139139
</type>
140+
141+
<type name="Magento\Catalog\Block\Product\ImageFactory">
142+
<plugin name="designLoader" type="Magento\CatalogGraphQl\Plugin\DesignLoader" />
143+
</type>
140144
</config>
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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\Controller\Adminhtml\Category\Save;
9+
10+
use Magento\CatalogUrlRewrite\Model\Map\DataCategoryUrlRewriteDatabaseMap;
11+
use Magento\Framework\App\Request\Http as HttpRequest;
12+
use Magento\Framework\Serialize\Serializer\Json;
13+
use Magento\TestFramework\TestCase\AbstractBackendController;
14+
use Magento\UrlRewrite\Model\ResourceModel\UrlRewriteCollectionFactory;
15+
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
16+
17+
/**
18+
* Class defines url rewrite creation for category save controller
19+
*
20+
* @magentoAppArea adminhtml
21+
* @magentoDbIsolation enabled
22+
*/
23+
class UrlRewriteTest extends AbstractBackendController
24+
{
25+
/** @var $urlRewriteCollectionFactory */
26+
private $urlRewriteCollectionFactory;
27+
28+
/** @var Json */
29+
private $jsonSerializer;
30+
31+
/**
32+
* @inheritDoc
33+
*/
34+
protected function setUp()
35+
{
36+
parent::setUp();
37+
38+
$this->urlRewriteCollectionFactory = $this->_objectManager->get(UrlRewriteCollectionFactory::class);
39+
$this->jsonSerializer = $this->_objectManager->get(Json::class);
40+
}
41+
42+
/**
43+
* @magentoConfigFixture default/catalog/seo/generate_category_product_rewrites 1
44+
* @dataProvider categoryDataProvider
45+
* @param array $data
46+
* @return void
47+
*/
48+
public function testUrlRewrite(array $data): void
49+
{
50+
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
51+
$this->getRequest()->setPostValue($data);
52+
$this->dispatch('backend/catalog/category/save');
53+
$categoryId = $this->jsonSerializer->unserialize($this->getResponse()->getBody())['category']['entity_id'];
54+
$this->assertNotNull($categoryId, 'The category was not created');
55+
$urlRewriteCollection = $this->urlRewriteCollectionFactory->create();
56+
$urlRewriteCollection->addFieldToFilter(UrlRewrite::ENTITY_ID, ['eq' => $categoryId])
57+
->addFieldToFilter(UrlRewrite::ENTITY_TYPE, ['eq' => DataCategoryUrlRewriteDatabaseMap::ENTITY_TYPE]);
58+
$this->assertCount(
59+
1,
60+
$urlRewriteCollection->getItems(),
61+
'Wrong count of url rewrites was created'
62+
);
63+
}
64+
65+
/**
66+
* @return array
67+
*/
68+
public function categoryDataProvider(): array
69+
{
70+
return [
71+
'url_rewrite_is_created_during_category_save' => [
72+
[
73+
'path' => '1/2',
74+
'name' => 'Custom Name',
75+
'parent' => 2,
76+
'is_active' => '0',
77+
'include_in_menu' => '1',
78+
'display_mode' => 'PRODUCTS',
79+
'is_anchor' => true,
80+
'return_session_messages_only' => true,
81+
'use_config' => [
82+
'available_sort_by' => 1,
83+
'default_sort_by' => 1,
84+
'filter_price_range' => 1,
85+
],
86+
],
87+
],
88+
];
89+
}
90+
}

0 commit comments

Comments
 (0)