Skip to content

Commit 464aff1

Browse files
committed
ACP2E-685: Product set to 'Not Visible Individually' still appear in Catalog Advanced Search Results
1 parent 7d39873 commit 464aff1

8 files changed

+106
-141
lines changed

dev/tests/integration/testsuite/Magento/Catalog/_files/layered_navigation_attribute.php

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

dev/tests/integration/testsuite/Magento/Catalog/_files/layered_navigation_attribute_rollback.php

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

dev/tests/integration/testsuite/Magento/Catalog/_files/products_with_layered_navigation_attribute.php

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,77 @@
66
declare(strict_types=1);
77

88
use Magento\Catalog\Api\Data\CategoryInterfaceFactory;
9+
use Magento\Catalog\Api\Data\ProductAttributeInterfaceFactory;
910
use Magento\Catalog\Api\Data\ProductInterfaceFactory;
11+
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
1012
use Magento\Catalog\Api\ProductRepositoryInterface;
1113
use Magento\Catalog\Model\Product;
1214
use Magento\Catalog\Model\Product\Attribute\Source\Status;
1315
use Magento\Catalog\Model\Product\Type;
1416
use Magento\Catalog\Model\Product\Visibility;
17+
use Magento\Eav\Model\Config;
18+
use Magento\Eav\Setup\EavSetup;
1519
use Magento\Indexer\Model\Indexer;
1620
use Magento\Indexer\Model\Indexer\Collection;
1721
use Magento\Msrp\Model\Product\Attribute\Source\Type as SourceType;
1822
use Magento\Store\Api\WebsiteRepositoryInterface;
1923
use Magento\TestFramework\Helper\Bootstrap;
20-
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
21-
22-
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/layered_navigation_attribute.php');
24+
use Magento\TestFramework\Helper\CacheCleaner;
2325

2426
$objectManager = Bootstrap::getObjectManager();
2527

28+
/** @var Config $eavConfig */
29+
$eavConfig = $objectManager->get(Config::class);
30+
31+
/** @var ProductAttributeRepositoryInterface $attributeRepository */
32+
$attributeRepository = $objectManager->get(ProductAttributeRepositoryInterface::class);
33+
/** @var ProductAttributeInterfaceFactory $attributeFactory */
34+
$attributeFactory = $objectManager->get(ProductAttributeInterfaceFactory::class);
35+
36+
/** @var $installer EavSetup */
37+
$installer = $objectManager->get(EavSetup::class);
38+
$attributeSetId = $installer->getAttributeSetId(Product::ENTITY, 'Default');
39+
$groupId = $installer->getDefaultAttributeGroupId(Product::ENTITY, $attributeSetId);
40+
2641
/** @var WebsiteRepositoryInterface $websiteRepository */
2742
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
2843
$baseWebsite = $websiteRepository->get('base');
2944

45+
$attributeModel = $attributeFactory->create();
46+
$attributeModel->setData(
47+
[
48+
'attribute_code' => 'test_configurable',
49+
'entity_type_id' => $installer->getEntityTypeId(Product::ENTITY),
50+
'is_global' => 1,
51+
'is_user_defined' => 1,
52+
'frontend_input' => 'select',
53+
'is_unique' => 0,
54+
'is_required' => 0,
55+
'is_searchable' => 1,
56+
'is_visible_in_advanced_search' => 1,
57+
'is_comparable' => 1,
58+
'is_filterable' => 1,
59+
'is_filterable_in_search' => 1,
60+
'is_used_for_promo_rules' => 0,
61+
'is_html_allowed_on_front' => 1,
62+
'is_visible_on_front' => 1,
63+
'used_in_product_listing' => 1,
64+
'used_for_sort_by' => 1,
65+
'frontend_label' => ['Test Configurable'],
66+
'backend_type' => 'int',
67+
'option' => [
68+
'value' => ['option_0' => ['Option 1'], 'option_1' => ['Option 2']],
69+
'order' => ['option_0' => 1, 'option_1' => 2],
70+
],
71+
'default' => ['option_0']
72+
]
73+
);
74+
$attribute = $attributeRepository->save($attributeModel);
75+
76+
$installer->addAttributeToGroup(Product::ENTITY, $attributeSetId, $groupId, $attribute->getId());
77+
CacheCleaner::cleanAll();
78+
$eavConfig->clear();
79+
3080
/** @var ProductRepositoryInterface $productRepository */
3181
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
3282
/** @var ProductInterfaceFactory $productInterfaceFactory */

dev/tests/integration/testsuite/Magento/Catalog/_files/products_with_layered_navigation_attribute_rollback.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
declare(strict_types=1);
77

88
use Magento\Catalog\Api\CategoryRepositoryInterface;
9+
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
910
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Eav\Model\Config;
1012
use Magento\Framework\Exception\NoSuchEntityException;
1113
use Magento\Framework\Registry;
1214
use Magento\TestFramework\Catalog\Model\GetCategoryByName;
1315
use Magento\TestFramework\Helper\Bootstrap;
14-
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
1516

1617
$objectManager = Bootstrap::getObjectManager();
1718
/** @var Registry $registry */
@@ -44,7 +45,17 @@
4445
//Category already removed
4546
}
4647

47-
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/layered_navigation_attribute_rollback.php');
48+
$eavConfig = $objectManager->get(Config::class);
49+
/** @var ProductAttributeRepositoryInterface $attributeRepository */
50+
$attributeRepository = $objectManager->get(ProductAttributeRepositoryInterface::class);
51+
52+
try {
53+
$attribute = $attributeRepository->get('test_configurable');
54+
$attributeRepository->delete($attribute);
55+
} catch (NoSuchEntityException $exception) {
56+
//Attribute already removed
57+
}
58+
$eavConfig->clear();
4859

4960
$registry->unregister('isSecureArea');
5061
$registry->register('isSecureArea', false);

dev/tests/integration/testsuite/Magento/CatalogSearch/Model/AdvancedTest.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99

1010
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
1111
use Magento\Catalog\Model\Product;
12-
use Magento\Framework\Search\Request\Config as RequestConfig;
13-
use Magento\Framework\Search\Request\Config\FilesystemReader as RequestConfigReader;
1412
use Magento\TestFramework\Helper\Bootstrap;
1513
use PHPUnit\Framework\TestCase;
1614

15+
/**
16+
* @magentoDbIsolation disabled
17+
*/
1718
class AdvancedTest extends TestCase
1819
{
1920
/**
@@ -23,21 +24,16 @@ class AdvancedTest extends TestCase
2324

2425
protected function setUp(): void
2526
{
26-
$requestConfigReader = Bootstrap::getObjectManager()->get(RequestConfigReader::class);
27-
$requestConfig = Bootstrap::getObjectManager()->get(RequestConfig::class);
28-
$requestConfig->merge($requestConfigReader->read());
29-
3027
$this->model = Bootstrap::getObjectManager()->create(Advanced::class);
3128
}
3229

3330
/**
34-
* @magentoDbIsolation disabled
35-
* @magentoDataFixture Magento/Catalog/_files/products_with_not_empty_layered_navigation_attribute.php
36-
* @magentoDataFixture Magento/Catalog/_files/not_visible_product_with_layered_navigation_attribute.php
31+
* @magentoDataFixture Magento/CatalogSearch/_files/product_for_search.php
32+
* @magentoDataFixture Magento/CatalogSearch/_files/not_visible_searchable_product.php
3733
*/
3834
public function testAddFilters(): void
3935
{
40-
$attributeCode = 'test_configurable';
36+
$attributeCode = 'test_searchable_attribute';
4137
$attributeRepository = Bootstrap::getObjectManager()->get(ProductAttributeRepositoryInterface::class);
4238
$attribute = $attributeRepository->get($attributeCode);
4339
$option = $attribute->getOptions()[1];
@@ -50,6 +46,6 @@ public function testAddFilters(): void
5046
self::assertCount(1, $products);
5147
/** @var Product $product */
5248
$product = array_shift($products);
53-
self::assertEquals('Option 1', $product->getAttributeText($attributeCode));
49+
self::assertEquals('simple_for_search', $product->getSku());
5450
}
5551
}
Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,53 @@
88
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
99
use Magento\Catalog\Api\ProductRepositoryInterface;
1010
use Magento\Catalog\Model\Product;
11-
use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus;
12-
use Magento\Catalog\Model\Product\Type as ProductType;
13-
use Magento\Catalog\Model\Product\Visibility as ProductVisibility;
11+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
12+
use Magento\Catalog\Model\Product\Type;
13+
use Magento\Catalog\Model\Product\Visibility;
1414
use Magento\Indexer\Model\Indexer\Collection as IndexerCollection;
1515
use Magento\Store\Api\WebsiteRepositoryInterface;
1616
use Magento\TestFramework\Helper\Bootstrap;
1717
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
1818

19-
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/layered_navigation_attribute.php');
19+
Resolver::getInstance()->requireDataFixture('Magento/CatalogSearch/_files/searchable_attribute.php');
2020

2121
$objectManager = Bootstrap::getObjectManager();
2222

2323
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
2424
$baseWebsite = $websiteRepository->get('base');
2525

2626
$attributeRepository = $objectManager->get(ProductAttributeRepositoryInterface::class);
27-
$attribute = $attributeRepository->get('test_configurable');
27+
$attribute = $attributeRepository->get('test_searchable_attribute');
2828

29-
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
3029
$product = $objectManager->create(Product::class);
31-
$product->setTypeId(ProductType::TYPE_SIMPLE)
30+
$product->setTypeId(Type::TYPE_SIMPLE)
3231
->setAttributeSetId($product->getDefaultAttributeSetId())
33-
->setName('Not visible simple')
34-
->setSku('not_visible_simple')
35-
->setTaxClassId('none')
36-
->setDescription('description')
37-
->setShortDescription('short description')
38-
->setPrice(10)
32+
->setWebsiteIds([1])
33+
->setName('Simple product name')
34+
->setSku('simple_for_search')
35+
->setPrice(100)
3936
->setWeight(1)
37+
->setShortDescription('Product short description')
38+
->setTaxClassId(0)
39+
->setDescription('Product description')
4040
->setMetaTitle('meta title')
4141
->setMetaKeyword('meta keyword')
4242
->setMetaDescription('meta description')
43-
->setVisibility(ProductVisibility::VISIBILITY_NOT_VISIBLE)
44-
->setStatus(ProductStatus::STATUS_ENABLED)
45-
->setWebsiteIds([$baseWebsite->getId()])
46-
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
47-
->setData($attribute->getAttributeCode(), $attribute->getSource()->getOptionId('Option 1'));
43+
->setVisibility(Visibility::VISIBILITY_BOTH)
44+
->setStatus(Status::STATUS_ENABLED)
45+
->setTestSearchableAttribute($attribute->getSource()->getOptionId('Option 1'))
46+
->setStockData(
47+
[
48+
'use_config_manage_stock' => 1,
49+
'qty' => 100,
50+
'is_qty_decimal' => 0,
51+
'is_in_stock' => 1,
52+
]
53+
);
54+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
4855
$productRepository->save($product);
4956

50-
$indexerCollection = $objectManager->get(IndexerCollection::class);
51-
foreach ($indexerCollection->getItems() as $indexer) {
52-
$indexer->reindexAll();
53-
}
57+
//$indexerCollection = $objectManager->get(IndexerCollection::class);
58+
//foreach ($indexerCollection->getItems() as $indexer) {
59+
// $indexer->reindexAll();
60+
//}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
//Product already removed
2121
}
2222

23-
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/layered_navigation_attribute_rollback.php');
23+
Resolver::getInstance()->requireDataFixture('Magento/CatalogSearch/_files/searchable_attribute_rollback.php');

dev/tests/integration/testsuite/Magento/CatalogSearch/_files/product_for_search_rollback.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,14 @@
77
declare(strict_types=1);
88

99
use Magento\Catalog\Api\ProductRepositoryInterface;
10-
use Magento\Catalog\Model\Product;
11-
use Magento\Eav\Setup\EavSetup;
12-
use Magento\Eav\Setup\EavSetupFactory;
1310
use Magento\Framework\Exception\NoSuchEntityException;
1411
use Magento\Framework\Registry;
1512
use Magento\TestFramework\Helper\Bootstrap;
1613
use Magento\TestFramework\ObjectManager;
14+
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
1715

1816
/** @var ObjectManager $objectManager */
1917
$objectManager = Bootstrap::getObjectManager();
20-
/** @var EavSetupFactory $eavSetupFactory */
21-
$eavSetupFactory = $objectManager->create(EavSetupFactory::class);
2218
/** @var Registry $registry */
2319
$registry = $objectManager->get(Registry::class);
2420
/** @var ProductRepositoryInterface $productRepository */
@@ -31,9 +27,8 @@
3127
} catch (NoSuchEntityException $e) {
3228
//Product already deleted.
3329
}
34-
/** @var EavSetup $eavSetup */
35-
$eavSetup = $eavSetupFactory->create();
36-
$eavSetup->removeAttribute(Product::ENTITY, 'test_searchable_attribute');
3730

3831
$registry->unregister('isSecureArea');
3932
$registry->register('isSecureArea', false);
33+
34+
Resolver::getInstance()->requireDataFixture('Magento/CatalogSearch/_files/searchable_attribute_rollback.php');

0 commit comments

Comments
 (0)