Skip to content

Commit 87e9a3c

Browse files
author
Oleksii Korshenko
authored
Merge pull request #1350 from magento-engcom/develop-prs
Public Pull Requests #10274 #10089
2 parents 069509a + 3c992de commit 87e9a3c

File tree

6 files changed

+214
-77
lines changed

6 files changed

+214
-77
lines changed

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/EavTest.php

Lines changed: 147 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Eav\Model\Config;
1111
use Magento\Framework\App\RequestInterface;
1212
use Magento\Framework\EntityManager\EventManager;
13+
use Magento\Framework\Phrase;
1314
use Magento\Store\Model\StoreManagerInterface;
1415
use Magento\Store\Api\Data\StoreInterface;
1516
use Magento\Ui\DataProvider\EavValidationRules;
@@ -452,12 +453,13 @@ public function testModifyData()
452453
* @param int $productId
453454
* @param bool $productRequired
454455
* @param string $attrValue
456+
* @param string $note
455457
* @param array $expected
456458
* @covers \Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Eav::isProductExists
457459
* @covers \Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Eav::setupAttributeMeta
458460
* @dataProvider setupAttributeMetaDataProvider
459461
*/
460-
public function testSetupAttributeMetaDefaultAttribute($productId, $productRequired, $attrValue, $expected)
462+
public function testSetupAttributeMetaDefaultAttribute($productId, $productRequired, $attrValue, $note, $expected)
461463
{
462464
$configPath = 'arguments/data/config';
463465
$groupCode = 'product-details';
@@ -483,6 +485,10 @@ public function testSetupAttributeMetaDefaultAttribute($productId, $productRequi
483485
->method('getValue')
484486
->willReturn('value');
485487

488+
$this->productAttributeMock->expects($this->any())
489+
->method('getNote')
490+
->willReturn($note);
491+
486492
$attributeMock = $this->getMockBuilder(AttributeInterface::class)
487493
->disableOriginalConstructor()
488494
->getMock();
@@ -527,82 +533,147 @@ public function testSetupAttributeMetaDefaultAttribute($productId, $productRequi
527533
public function setupAttributeMetaDataProvider()
528534
{
529535
return [
530-
'default_null_prod_not_new_and_required' => [
531-
'productId' => 1,
532-
'productRequired' => true,
533-
'attrValue' => 'val',
534-
'expected' => [
535-
'dataType' => null,
536-
'formElement' => null,
537-
'visible' => null,
538-
'required' => true,
539-
'notice' => null,
540-
'default' => null,
541-
'label' => null,
542-
'code' => 'code',
543-
'source' => 'product-details',
544-
'scopeLabel' => '',
545-
'globalScope' => false,
546-
'sortOrder' => 0
547-
],
548-
],
549-
'default_null_prod_not_new_and_not_required' => [
550-
'productId' => 1,
551-
'productRequired' => false,
552-
'attrValue' => 'val',
553-
'expected' => [
554-
'dataType' => null,
555-
'formElement' => null,
556-
'visible' => null,
557-
'required' => false,
558-
'notice' => null,
559-
'default' => null,
560-
'label' => null,
561-
'code' => 'code',
562-
'source' => 'product-details',
563-
'scopeLabel' => '',
564-
'globalScope' => false,
565-
'sortOrder' => 0
566-
],
567-
],
568-
'default_null_prod_new_and_not_required' => [
569-
'productId' => null,
570-
'productRequired' => false,
571-
'attrValue' => null,
572-
'expected' => [
573-
'dataType' => null,
574-
'formElement' => null,
575-
'visible' => null,
576-
'required' => false,
577-
'notice' => null,
578-
'default' => 'required_value',
579-
'label' => null,
580-
'code' => 'code',
581-
'source' => 'product-details',
582-
'scopeLabel' => '',
583-
'globalScope' => false,
584-
'sortOrder' => 0
585-
],
536+
'default_null_prod_not_new_and_required' => $this->defaultNullProdNotNewAndRequired(),
537+
'default_null_prod_not_new_and_not_required' => $this->defaultNullProdNotNewAndNotRequired(),
538+
'default_null_prod_new_and_not_required' => $this->defaultNullProdNewAndNotRequired(),
539+
'default_null_prod_new_and_required' => $this->defaultNullProdNewAndRequired(),
540+
'default_null_prod_new_and_required_and_filled_notice' =>
541+
$this->defaultNullProdNewAndRequiredAndFilledNotice()
542+
];
543+
}
544+
545+
/**
546+
* @return array
547+
*/
548+
private function defaultNullProdNotNewAndRequired()
549+
{
550+
return [
551+
'productId' => 1,
552+
'productRequired' => true,
553+
'attrValue' => 'val',
554+
'note' => null,
555+
'expected' => [
556+
'dataType' => null,
557+
'formElement' => null,
558+
'visible' => null,
559+
'required' => true,
560+
'notice' => null,
561+
'default' => null,
562+
'label' => null,
563+
'code' => 'code',
564+
'source' => 'product-details',
565+
'scopeLabel' => '',
566+
'globalScope' => false,
567+
'sortOrder' => 0
568+
],
569+
];
570+
}
571+
572+
/**
573+
* @return array
574+
*/
575+
private function defaultNullProdNotNewAndNotRequired()
576+
{
577+
return [
578+
'productId' => 1,
579+
'productRequired' => false,
580+
'attrValue' => 'val',
581+
'note' => null,
582+
'expected' => [
583+
'dataType' => null,
584+
'formElement' => null,
585+
'visible' => null,
586+
'required' => false,
587+
'notice' => null,
588+
'default' => null,
589+
'label' => null,
590+
'code' => 'code',
591+
'source' => 'product-details',
592+
'scopeLabel' => '',
593+
'globalScope' => false,
594+
'sortOrder' => 0
595+
],
596+
];
597+
}
598+
599+
/**
600+
* @return array
601+
*/
602+
private function defaultNullProdNewAndNotRequired()
603+
{
604+
return [
605+
'productId' => null,
606+
'productRequired' => false,
607+
'attrValue' => null,
608+
'note' => null,
609+
'expected' => [
610+
'dataType' => null,
611+
'formElement' => null,
612+
'visible' => null,
613+
'required' => false,
614+
'notice' => null,
615+
'default' => 'required_value',
616+
'label' => null,
617+
'code' => 'code',
618+
'source' => 'product-details',
619+
'scopeLabel' => '',
620+
'globalScope' => false,
621+
'sortOrder' => 0
622+
],
623+
];
624+
}
625+
626+
/**
627+
* @return array
628+
*/
629+
private function defaultNullProdNewAndRequired()
630+
{
631+
return [
632+
'productId' => null,
633+
'productRequired' => false,
634+
'attrValue' => null,
635+
'note' => null,
636+
'expected' => [
637+
'dataType' => null,
638+
'formElement' => null,
639+
'visible' => null,
640+
'required' => false,
641+
'notice' => null,
642+
'default' => 'required_value',
643+
'label' => null,
644+
'code' => 'code',
645+
'source' => 'product-details',
646+
'scopeLabel' => '',
647+
'globalScope' => false,
648+
'sortOrder' => 0
649+
],
650+
];
651+
}
652+
653+
/**
654+
* @return array
655+
*/
656+
private function defaultNullProdNewAndRequiredAndFilledNotice()
657+
{
658+
return [
659+
'productId' => null,
660+
'productRequired' => false,
661+
'attrValue' => null,
662+
'note' => 'example notice',
663+
'expected' => [
664+
'dataType' => null,
665+
'formElement' => null,
666+
'visible' => null,
667+
'required' => false,
668+
'notice' => __('example notice'),
669+
'default' => 'required_value',
670+
'label' => null,
671+
'code' => 'code',
672+
'source' => 'product-details',
673+
'scopeLabel' => '',
674+
'globalScope' => false,
675+
'sortOrder' => 0
586676
],
587-
'default_null_prod_new_and_required' => [
588-
'productId' => null,
589-
'productRequired' => false,
590-
'attrValue' => null,
591-
'expected' => [
592-
'dataType' => null,
593-
'formElement' => null,
594-
'visible' => null,
595-
'required' => false,
596-
'notice' => null,
597-
'default' => 'required_value',
598-
'label' => null,
599-
'code' => 'code',
600-
'source' => 'product-details',
601-
'scopeLabel' => '',
602-
'globalScope' => false,
603-
'sortOrder' => 0
604-
],
605-
]
606677
];
607678
}
608679
}

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ public function setupAttributeMeta(ProductAttributeInterface $attribute, $groupC
555555
'formElement' => $this->getFormElementsMapValue($attribute->getFrontendInput()),
556556
'visible' => $attribute->getIsVisible(),
557557
'required' => $attribute->getIsRequired(),
558-
'notice' => $attribute->getNote(),
558+
'notice' => $attribute->getNote() === null ? null : __($attribute->getNote()),
559559
'default' => (!$this->isProductExists()) ? $attribute->getDefaultValue() : null,
560560
'label' => $attribute->getDefaultFrontendLabel(),
561561
'code' => $attribute->getAttributeCode(),
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogSearch\Ui\DataProvider\Product;
7+
8+
use Magento\Framework\Data\Collection;
9+
use Magento\CatalogSearch\Model\ResourceModel\Search\Collection as SearchCollection;
10+
use Magento\Ui\DataProvider\AddFilterToCollectionInterface;
11+
12+
/**
13+
* Class AddFulltextFilterToCollection
14+
*/
15+
class AddFulltextFilterToCollection implements AddFilterToCollectionInterface
16+
{
17+
/**
18+
* Search Collection
19+
*
20+
* @var SearchCollection
21+
*/
22+
private $searchCollection;
23+
24+
/**
25+
* @param SearchCollection $searchCollection
26+
*/
27+
public function __construct(SearchCollection $searchCollection)
28+
{
29+
$this->searchCollection = $searchCollection;
30+
}
31+
32+
/**
33+
* {@inheritdoc}
34+
*
35+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
36+
*/
37+
public function addFilter(Collection $collection, $field, $condition = null)
38+
{
39+
/** @var $collection \Magento\Catalog\Model\ResourceModel\Product\Collection */
40+
if (isset($condition['fulltext']) && !empty($condition['fulltext'])) {
41+
$this->searchCollection->addBackendSearchFilter($condition['fulltext']);
42+
$productIds = $this->searchCollection->load()->getAllIds();
43+
$collection->addIdFilter($productIds);
44+
}
45+
}
46+
}

app/code/Magento/CatalogSearch/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"magento/module-eav": "100.2.*",
1212
"magento/module-backend": "100.2.*",
1313
"magento/module-theme": "100.2.*",
14+
"magento/module-ui": "100.2.*",
1415
"magento/module-catalog-inventory": "100.2.*",
1516
"magento/framework": "100.2.*"
1617
},

app/code/Magento/CatalogSearch/etc/adminhtml/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,11 @@
1919
<type name="Magento\Catalog\Block\Adminhtml\Product\Attribute\Edit\Tab\Front">
2020
<plugin name="search_weigh" type="Magento\CatalogSearch\Block\Plugin\FrontTabPlugin" />
2121
</type>
22+
<type name="Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider">
23+
<arguments>
24+
<argument name="addFilterStrategies" xsi:type="array">
25+
<item name="fulltext" xsi:type="object">Magento\CatalogSearch\Ui\DataProvider\Product\AddFulltextFilterToCollection</item>
26+
</argument>
27+
</arguments>
28+
</type>
2229
</config>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
9+
<listingToolbar name="listing_top">
10+
<filterSearch name="fulltext"/>
11+
</listingToolbar>
12+
</listing>

0 commit comments

Comments
 (0)