Skip to content

Commit 5102559

Browse files
committed
Merge branch 'ASI-1780' of github.com:Nazar65/magento2 into asi-delivery-24
2 parents 86423e7 + 322f917 commit 5102559

File tree

19 files changed

+462
-480
lines changed

19 files changed

+462
-480
lines changed

app/code/Magento/Catalog/view/adminhtml/web/js/components/product-ui-select.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* See COPYING.txt for license details.
44
*/
55

6+
/**
7+
* @deprecated see Magento/Ui/view/base/web/js/grid/filters/elements/ui-select.js
8+
*/
69
define([
710
'Magento_Ui/js/form/element/ui-select',
811
'jquery',
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\MediaGalleryCatalogUi\Controller\Adminhtml\Product;
10+
11+
use Magento\Framework\Controller\ResultInterface;
12+
use Magento\Backend\App\Action\Context;
13+
use Magento\Catalog\Api\ProductRepositoryInterface;
14+
use Magento\Framework\Controller\Result\JsonFactory;
15+
use Magento\Framework\App\Action\HttpGetActionInterface;
16+
use Magento\Backend\App\Action;
17+
18+
/**
19+
* Returns selected product by product id. for ui-select filter
20+
*/
21+
class GetSelected extends Action implements HttpGetActionInterface
22+
{
23+
/**
24+
* @see _isAllowed()
25+
*/
26+
const ADMIN_RESOURCE = 'Magento_Catalog::products';
27+
28+
/**
29+
* @var JsonFactory
30+
*/
31+
private $resultJsonFactory;
32+
33+
/**
34+
* @var ProductRepositoryInterface
35+
*/
36+
private $productRepository;
37+
38+
/**
39+
* GetSelected constructor.
40+
*
41+
* @param JsonFactory $jsonFactory
42+
* @param ProductRepositoryInterface $productRepository
43+
* @param Context $context
44+
*/
45+
public function __construct(
46+
JsonFactory $jsonFactory,
47+
ProductRepositoryInterface $productRepository,
48+
Context $context
49+
) {
50+
$this->resultJsonFactory = $jsonFactory;
51+
$this->productRepository = $productRepository;
52+
parent::__construct($context);
53+
}
54+
55+
/**
56+
* Return selected products options
57+
*
58+
* @return ResultInterface
59+
*/
60+
public function execute() : ResultInterface
61+
{
62+
$productIds = $this->getRequest()->getParam('ids');
63+
$options = [];
64+
65+
if (!is_array($productIds)) {
66+
return $this->resultJsonFactory->create()->setData('parameter ids must be type of array');
67+
}
68+
foreach ($productIds as $id) {
69+
try {
70+
$product = $this->productRepository->getById($id);
71+
$options[] = [
72+
'value' => $product->getId(),
73+
'label' => $product->getName(),
74+
'is_active' => $product->getSatus(),
75+
'path' => $product->getSku()
76+
];
77+
} catch (\Exception $e) {
78+
continue;
79+
}
80+
}
81+
82+
return $this->resultJsonFactory->create()->setData($options);
83+
}
84+
}

app/code/Magento/MediaGalleryCatalogUi/Ui/Component/Listing/Filters/UsedInProducts.php

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

app/code/Magento/MediaGalleryCatalogUi/view/adminhtml/ui_component/media_gallery_category_listing.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
provider="${ $.parentName }"
5959
sortOrder="10"
6060
class="Magento\MediaGalleryUi\Ui\Component\Listing\Filters\Asset"
61-
component="Magento_Ui/js/form/element/ui-select"
61+
component="Magento_Ui/js/grid/filters/elements/ui-select"
6262
template="Magento_MediaGalleryUi/grid/filters/elements/ui-select">
6363
<argument name="data" xsi:type="array">
6464
<item name="config" xsi:type="array">
@@ -74,6 +74,7 @@
7474
<item name="filterRateLimitMethod" xsi:type="string" translate="true">notifyWhenChangesStop</item>
7575
<item name="searchOptions" xsi:type="boolean">true</item>
7676
<item name="searchUrl" xsi:type="url" path="media_gallery/asset/search" />
77+
<item name="validationUrl" xsi:type="url" path="media_gallery/asset/getSelected"/>
7778
<item name="levelsVisibility" xsi:type="number">1</item>
7879
</item>
7980
</argument>

app/code/Magento/MediaGalleryCatalogUi/view/adminhtml/ui_component/media_gallery_listing.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
name="product_id"
1414
provider="${ $.parentName }"
1515
sortOrder="110"
16-
class="Magento\MediaGalleryCatalogUi\Ui\Component\Listing\Filters\UsedInProducts"
17-
component="Magento_Catalog/js/components/product-ui-select"
16+
component="Magento_Ui/js/grid/filters/elements/ui-select"
1817
template="ui/grid/filters/elements/ui-select">
1918
<argument name="data" xsi:type="array">
2019
<item name="config" xsi:type="array">
@@ -30,7 +29,7 @@
3029
<item name="filterRateLimitMethod" xsi:type="string">notifyWhenChangesStop</item>
3130
<item name="levelsVisibility" xsi:type="number">1</item>
3231
<item name="searchUrl" xsi:type="url" path="catalog/product/search"/>
33-
<item name="validationUrl" xsi:type="url" path="catalog/product/getSelected"/>
32+
<item name="validationUrl" xsi:type="url" path="media_gallery_catalog/product/getSelected"/>
3433
</item>
3534
</argument>
3635
<settings>

app/code/Magento/MediaGalleryCatalogUi/view/adminhtml/ui_component/standalone_media_gallery_listing.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
name="product_id"
1414
provider="${ $.parentName }"
1515
sortOrder="110"
16-
class="Magento\MediaGalleryCatalogUi\Ui\Component\Listing\Filters\UsedInProducts"
17-
component="Magento_Catalog/js/components/product-ui-select"
16+
component="Magento_Ui/js/grid/filters/elements/ui-select"
1817
template="ui/grid/filters/elements/ui-select">
1918
<argument name="data" xsi:type="array">
2019
<item name="config" xsi:type="array">
@@ -30,7 +29,7 @@
3029
<item name="filterRateLimitMethod" xsi:type="string">notifyWhenChangesStop</item>
3130
<item name="levelsVisibility" xsi:type="number">1</item>
3231
<item name="searchUrl" xsi:type="url" path="catalog/product/search"/>
33-
<item name="validationUrl" xsi:type="url" path="catalog/product/getSelected"/>
32+
<item name="validationUrl" xsi:type="url" path="media_gallery_catalog/product/getSelected"/>
3433
</item>
3534
</argument>
3635
<settings>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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\MediaGalleryCmsUi\Controller\Adminhtml\Block;
9+
10+
use Magento\Backend\App\Action;
11+
use Magento\Backend\App\Action\Context;
12+
use Magento\Cms\Api\BlockRepositoryInterface;
13+
use Magento\Framework\App\Action\HttpGetActionInterface;
14+
use Magento\Framework\Controller\Result\JsonFactory;
15+
use Magento\Framework\Controller\ResultInterface;
16+
17+
/**
18+
* Controller to get selected block for ui-select component
19+
*/
20+
class GetSelected extends Action implements HttpGetActionInterface
21+
{
22+
/**
23+
* Authorization level of a basic admin session
24+
*
25+
* @see _isAllowed()
26+
*/
27+
const ADMIN_RESOURCE = 'Magento_Cms::block';
28+
29+
/**
30+
* @var JsonFactory
31+
*/
32+
private $resultJsonFactory;
33+
34+
/**
35+
* @var BlockRepositoryInterface
36+
*/
37+
private $blockRepository;
38+
39+
/**
40+
* @param JsonFactory $resultFactory
41+
* @param BlockRepositoryInterface $blockRepository
42+
* @param Context $context
43+
*/
44+
public function __construct(
45+
JsonFactory $resultFactory,
46+
BlockRepositoryInterface $blockRepository,
47+
Context $context
48+
) {
49+
$this->resultJsonFactory = $resultFactory;
50+
$this->blockRepository = $blockRepository;
51+
parent::__construct($context);
52+
}
53+
54+
/**
55+
* Return selected blocks options.
56+
*
57+
* @return ResultInterface
58+
*/
59+
public function execute(): ResultInterface
60+
{
61+
$options = [];
62+
$blockIds = $this->getRequest()->getParam('ids');
63+
64+
if (!is_array($blockIds)) {
65+
return $this->resultJsonFactory->create()->setData('parameter ids must be type of array');
66+
}
67+
foreach ($blockIds as $id) {
68+
try {
69+
$block = $this->blockRepository->getById($id);
70+
$options[] = [
71+
'value' => $block->getId(),
72+
'label' => $block->getTitle(),
73+
'is_active' => $block->isActive(),
74+
'optgroup' => false
75+
];
76+
} catch (\Exception $e) {
77+
continue;
78+
}
79+
}
80+
81+
return $this->resultJsonFactory->create()->setData($options);
82+
}
83+
}

0 commit comments

Comments
 (0)