Skip to content

Commit 6531957

Browse files
committed
MAGETWO-61164: [Backport] - Configurable Product visible on the Category when options are Out of Stock and Disabled - for 2.1
1 parent 409eef5 commit 6531957

File tree

6 files changed

+82
-11
lines changed

6 files changed

+82
-11
lines changed

app/code/Magento/ConfigurableProduct/Model/ResourceModel/Indexer/Stock/Configurable.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,25 @@ protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = f
2929
$connection = $this->getConnection();
3030
$idxTable = $usePrimaryTable ? $this->getMainTable() : $this->getIdxTable();
3131
$select = parent::_getStockStatusSelect($entityIds, $usePrimaryTable);
32+
$linkField = $metadata->getLinkField();
3233
$select->reset(
3334
\Magento\Framework\DB\Select::COLUMNS
3435
)->columns(
3536
['e.entity_id', 'cis.website_id', 'cis.stock_id']
3637
)->joinLeft(
3738
['l' => $this->getTable('catalog_product_super_link')],
38-
'l.parent_id = e.' . $metadata->getLinkField(),
39+
'l.parent_id = e.' . $linkField,
3940
[]
4041
)->join(
4142
['le' => $this->getTable('catalog_product_entity')],
4243
'le.entity_id = l.product_id',
4344
[]
45+
)->joinInner(
46+
['cpei' => $this->getTable('catalog_product_entity_int')],
47+
'le.' . $linkField . ' = cpei.' . $linkField
48+
. ' AND cpei.attribute_id = ' . $this->_getAttribute('status')->getId()
49+
. ' AND cpei.value = ' . ProductStatus::STATUS_ENABLED,
50+
[]
4451
)->joinLeft(
4552
['i' => $idxTable],
4653
'i.product_id = l.product_id AND cis.website_id = i.website_id AND cis.stock_id = i.stock_id',

dev/tests/integration/testsuite/Magento/Framework/Search/Adapter/Mysql/AdapterTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,10 @@ public function testBoolFilterWithNestedRangeInNegativeBoolFilter()
378378
*
379379
* @magentoConfigFixture current_store catalog/search/engine mysql
380380
* @dataProvider advancedSearchDataProvider
381+
* @param string $nameQuery
382+
* @param string $descriptionQuery
383+
* @param array $rangeFilter
384+
* @param int $expectedRecordsCount
381385
* @return void
382386
*/
383387
public function testSimpleAdvancedSearch(
@@ -446,6 +450,37 @@ public function testCustomFilterableAttribute()
446450
$this->assertEquals(1, $queryResponse->count());
447451
}
448452

453+
/**
454+
* @magentoDataFixture Magento/Framework/Search/_files/product_configurable_with_disabled_child.php
455+
* @magentoConfigFixture current_store catalog/search/engine mysql
456+
*/
457+
public function testAdvancedSearchCompositeProductWithDisabledChild()
458+
{
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 */
463+
$selectOptions = $this->objectManager
464+
->create(\Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection::class)
465+
->setAttributeFilter($attribute->getId());
466+
467+
$firstOption = $selectOptions->getFirstItem();
468+
$firstOptionId = $firstOption->getId();
469+
$this->requestBuilder->bind('test_configurable', $firstOptionId);
470+
$this->requestBuilder->setRequestName('filter_out_of_stock_child');
471+
472+
$queryResponse = $this->executeQuery();
473+
$this->assertEquals(0, $queryResponse->count());
474+
475+
$secondOption = $selectOptions->getLastItem();
476+
$secondOptionId = $secondOption->getId();
477+
$this->requestBuilder->bind('test_configurable', $secondOptionId);
478+
$this->requestBuilder->setRequestName('filter_out_of_stock_child');
479+
480+
$queryResponse = $this->executeQuery();
481+
$this->assertEquals(0, $queryResponse->count());
482+
}
483+
449484
/**
450485
* Advanced search request using date product attribute.
451486
*

dev/tests/integration/testsuite/Magento/Framework/Search/_files/product_configurable.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
$attributeValues = [];
3434
$attributeSetId = $installer->getAttributeSetId('catalog_product', 'Default');
3535
$associatedProductIds = [];
36-
$productIds = [10010, 10020];
36+
$productIds = [1010, 1020];
3737
array_shift($options); //remove the first option which is empty
3838

3939
$isFirstOption = true;
@@ -133,7 +133,7 @@
133133
$registry->register('isSecureArea', false);
134134

135135
$product->setTypeId(Configurable::TYPE_CODE)
136-
->setId(10001)
136+
->setId(1001)
137137
->setAttributeSetId($attributeSetId)
138138
->setWebsiteIds([1])
139139
->setName('Configurable Product')

dev/tests/integration/testsuite/Magento/Framework/Search/_files/product_configurable_rollback.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
<?php
22
/**
3-
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
3+
* Copyright © 2016 Magento. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
use Magento\TestFramework\Helper\Bootstrap;
76

8-
$objectManager = Bootstrap::getObjectManager();
7+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
8+
99
/** @var \Magento\Framework\Registry $registry */
10-
$registry = $objectManager->get(\Magento\Framework\Registry::class);
10+
$registry = $objectManager->get('Magento\Framework\Registry');
11+
1112
$registry->unregister('isSecureArea');
1213
$registry->register('isSecureArea', true);
14+
1315
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
14-
$productRepository = Bootstrap::getObjectManager()
15-
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
16+
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
17+
->get('Magento\Catalog\Api\ProductRepositoryInterface');
1618

17-
foreach (['simple_10010', 'simple_10020', 'configurable_searchable'] as $sku) {
19+
foreach (['simple_1010', 'simple_1020', 'configurable'] as $sku) {
1820
try {
1921
$product = $productRepository->get($sku, false, null, true);
20-
$stockStatus = $objectManager->create(\Magento\CatalogInventory\Model\Stock\Status::class);
22+
23+
$stockStatus = $objectManager->create('Magento\CatalogInventory\Model\Stock\Status');
2124
$stockStatus->load($product->getEntityId(), 'product_id');
2225
$stockStatus->delete();
26+
2327
$productRepository->delete($product);
2428
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
2529
//Product already removed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\Catalog\Api\ProductRepositoryInterface;
8+
use Magento\TestFramework\Helper\Bootstrap;
9+
10+
require __DIR__ . '/product_configurable.php';
11+
12+
/** @var ProductRepositoryInterface $productRepository */
13+
$productRepository = Bootstrap::getObjectManager()
14+
->create(ProductRepositoryInterface::class);
15+
16+
$product = $productRepository->get('simple_1020');
17+
$product->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED);
18+
$productRepository->save($product);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
require __DIR__ . '/product_configurable_rollback.php';

0 commit comments

Comments
 (0)