5
5
*/
6
6
namespace Magento \Framework \Search \Adapter \Mysql ;
7
7
8
+ use Magento \Catalog \Model \Product ;
9
+ use Magento \Catalog \Model \ResourceModel \Eav \Attribute ;
8
10
use Magento \CatalogSearch \Model \ResourceModel \EngineInterface ;
11
+ use Magento \Eav \Model \ResourceModel \Entity \Attribute \Option \Collection ;
9
12
use Magento \Framework \App \Config \MutableScopeConfigInterface ;
10
13
use Magento \Search \Model \EngineResolver ;
11
14
use Magento \TestFramework \Helper \Bootstrap ;
@@ -375,18 +378,18 @@ public function advancedSearchDataProvider()
375
378
*/
376
379
public function testCustomFilterableAttribute ()
377
380
{
378
- /** @var \Magento\Catalog\Model\ResourceModel\Eav\ Attribute $attribute */
379
- $ attribute = $ this ->objectManager ->get (\ Magento \ Catalog \ Model \ ResourceModel \ Eav \ Attribute::class)
380
- ->loadByCode (\ Magento \ Catalog \ Model \ Product::ENTITY , 'select_attribute ' );
381
- /** @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\ Collection $selectOptions */
381
+ /** @var Attribute $attribute */
382
+ $ attribute = $ this ->objectManager ->get (Attribute::class)
383
+ ->loadByCode (Product::ENTITY , 'select_attribute ' );
384
+ /** @var Collection $selectOptions */
382
385
$ selectOptions = $ this ->objectManager
383
- ->create (\ Magento \ Eav \ Model \ ResourceModel \ Entity \ Attribute \ Option \ Collection::class)
386
+ ->create (Collection::class)
384
387
->setAttributeFilter ($ attribute ->getId ());
385
388
386
- $ attribute ->loadByCode (\ Magento \ Catalog \ Model \ Product::ENTITY , 'multiselect_attribute ' );
387
- /** @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\ Collection $multiselectOptions */
389
+ $ attribute ->loadByCode (Product::ENTITY , 'multiselect_attribute ' );
390
+ /** @var Collection $multiselectOptions */
388
391
$ multiselectOptions = $ this ->objectManager
389
- ->create (\ Magento \ Eav \ Model \ ResourceModel \ Entity \ Attribute \ Option \ Collection::class)
392
+ ->create (Collection::class)
390
393
->setAttributeFilter ($ attribute ->getId ());
391
394
392
395
$ this ->requestBuilder ->bind ('select_attribute ' , $ selectOptions ->getLastItem ()->getId ());
@@ -395,7 +398,72 @@ public function testCustomFilterableAttribute()
395
398
$ this ->requestBuilder ->bind ('price.to ' , 100 );
396
399
$ this ->requestBuilder ->bind ('category_ids ' , 2 );
397
400
$ this ->requestBuilder ->setRequestName ('filterable_custom_attributes ' );
401
+ $ queryResponse = $ this ->executeQuery ();
402
+ $ this ->assertEquals (1 , $ queryResponse ->count ());
403
+ }
404
+
405
+ /**
406
+ * Data provider for testFilterByAttributeValues.
407
+ *
408
+ * @return array
409
+ */
410
+ public function filterByAttributeValuesDataProvider ()
411
+ {
412
+ return [
413
+ 'quick_search_container ' => [
414
+ 'quick_search_container ' ,
415
+ [
416
+ // Make sure search uses "should" cause.
417
+ 'search_term ' => 'Simple Product ' ,
418
+ ],
419
+ ],
420
+ 'advanced_search_container ' => [
421
+ 'advanced_search_container ' ,
422
+ [
423
+ // Make sure "wildcard" feature works.
424
+ 'sku ' => 'simple_product ' ,
425
+ ]
426
+ ],
427
+ 'catalog_view_container ' => [
428
+ 'catalog_view_container ' ,
429
+ [
430
+ 'category_ids ' => 2
431
+ ]
432
+ ]
433
+ ];
434
+ }
398
435
436
+ /**
437
+ * Test filtering by two attributes.
438
+ *
439
+ * @magentoDataFixture Magento/Framework/Search/_files/filterable_attributes.php
440
+ * @magentoConfigFixture current_store catalog/search/engine mysql
441
+ * @dataProvider filterByAttributeValuesDataProvider
442
+ * @param string $requestName
443
+ * @param array $additionalData
444
+ * @return void
445
+ */
446
+ public function testFilterByAttributeValues ($ requestName , $ additionalData )
447
+ {
448
+ /** @var Attribute $attribute */
449
+ $ attribute = $ this ->objectManager ->get (Attribute::class)
450
+ ->loadByCode (Product::ENTITY , 'select_attribute_1 ' );
451
+ /** @var Collection $selectOptions1 */
452
+ $ selectOptions1 = $ this ->objectManager
453
+ ->create (Collection::class)
454
+ ->setAttributeFilter ($ attribute ->getId ());
455
+ $ attribute ->loadByCode (Product::ENTITY , 'select_attribute_2 ' );
456
+ /** @var Collection $selectOptions2 */
457
+ $ selectOptions2 = $ this ->objectManager
458
+ ->create (Collection::class)
459
+ ->setAttributeFilter ($ attribute ->getId ());
460
+ $ this ->requestBuilder ->bind ('select_attribute_1 ' , $ selectOptions1 ->getLastItem ()->getId ());
461
+ $ this ->requestBuilder ->bind ('select_attribute_2 ' , $ selectOptions2 ->getLastItem ()->getId ());
462
+ // Binds for specific containers.
463
+ foreach ($ additionalData as $ key => $ value ) {
464
+ $ this ->requestBuilder ->bind ($ key , $ value );
465
+ }
466
+ $ this ->requestBuilder ->setRequestName ($ requestName );
399
467
$ queryResponse = $ this ->executeQuery ();
400
468
$ this ->assertEquals (1 , $ queryResponse ->count ());
401
469
}
@@ -425,12 +493,12 @@ public function testAdvancedSearchDateField($rangeFilter, $expectedRecordsCount)
425
493
*/
426
494
public function testAdvancedSearchCompositeProductWithOutOfStockOption ()
427
495
{
428
- /** @var \Magento\Catalog\Model\ResourceModel\Eav\ Attribute $attribute */
429
- $ attribute = $ this ->objectManager ->get (\ Magento \ Catalog \ Model \ ResourceModel \ Eav \ Attribute::class)
430
- ->loadByCode (\ Magento \ Catalog \ Model \ Product::ENTITY , 'test_configurable ' );
431
- /** @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\ Collection $selectOptions */
496
+ /** @var Attribute $attribute */
497
+ $ attribute = $ this ->objectManager ->get (Attribute::class)
498
+ ->loadByCode (Product::ENTITY , 'test_configurable ' );
499
+ /** @var Collection $selectOptions */
432
500
$ selectOptions = $ this ->objectManager
433
- ->create (\ Magento \ Eav \ Model \ ResourceModel \ Entity \ Attribute \ Option \ Collection::class)
501
+ ->create (Collection::class)
434
502
->setAttributeFilter ($ attribute ->getId ());
435
503
436
504
$ firstOption = $ selectOptions ->getFirstItem ();
@@ -456,12 +524,12 @@ public function testAdvancedSearchCompositeProductWithOutOfStockOption()
456
524
*/
457
525
public function testAdvancedSearchCompositeProductWithDisabledChild ()
458
526
{
459
- /** @var \Magento\Catalog\Model\ResourceModel\Eav\ Attribute $attribute */
460
- $ attribute = $ this ->objectManager ->get (\ Magento \ Catalog \ Model \ ResourceModel \ Eav \ Attribute::class)
461
- ->loadByCode (\ Magento \ Catalog \ Model \ Product::ENTITY , 'test_configurable ' );
462
- /** @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\ Collection $selectOptions */
527
+ /** @var Attribute $attribute */
528
+ $ attribute = $ this ->objectManager ->get (Attribute::class)
529
+ ->loadByCode (Product::ENTITY , 'test_configurable ' );
530
+ /** @var Collection $selectOptions */
463
531
$ selectOptions = $ this ->objectManager
464
- ->create (\ Magento \ Eav \ Model \ ResourceModel \ Entity \ Attribute \ Option \ Collection::class)
532
+ ->create (Collection::class)
465
533
->setAttributeFilter ($ attribute ->getId ());
466
534
467
535
$ firstOption = $ selectOptions ->getFirstItem ();
@@ -518,7 +586,7 @@ public function testSearchQueryBoost()
518
586
* Now we're going to change search weight of one of the attributes to ensure that it will affect
519
587
* how products are ordered in the search result
520
588
*/
521
- /** @var \Magento\Catalog\Model\ResourceModel\Eav\ Attribute $attribute */
589
+ /** @var Attribute $attribute */
522
590
$ attribute = $ productAttributeRepository ->get ('name ' );
523
591
$ attribute ->setSearchWeight (20 );
524
592
$ productAttributeRepository ->save ($ attribute );
0 commit comments