Skip to content

Commit d8a43fd

Browse files
committed
Merge branch 'MC-43051' of https://github.com/magento-l3/magento2ce into L3-PR-20210830
2 parents b6df4eb + f3f73ab commit d8a43fd

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

app/code/Magento/ConfigurableProductGraphQl/Model/Variant/Collection.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Magento\GraphQl\Model\Query\ContextInterface;
1818
use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Product\CollectionProcessorInterface;
1919
use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Product\CollectionPostProcessor;
20+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
2021

2122
/**
2223
* Collection for fetching configurable child product data.
@@ -163,6 +164,9 @@ private function fetch(ContextInterface $context) : array
163164

164165
/** @var Product $childProduct */
165166
foreach ($childCollection as $childProduct) {
167+
if ((int)$childProduct->getStatus() !== Status::STATUS_ENABLED) {
168+
continue;
169+
}
166170
$formattedChild = ['model' => $childProduct, 'sku' => $childProduct->getSku()];
167171
$parentId = (int)$childProduct->getParentId();
168172
if (!isset($this->childrenMap[$parentId])) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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\GraphQl\ConfigurableProduct;
9+
10+
use Magento\TestFramework\TestCase\GraphQlAbstract;
11+
12+
/**
13+
* Checks disabled child product is not in configurable variants.
14+
*/
15+
class ConfigurableProductChildStatusDisabledTest extends GraphQlAbstract
16+
{
17+
/**
18+
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable_disable_first_child.php
19+
* @magentoConfigFixture default_store cataloginventory/options/show_out_of_stock 1
20+
*/
21+
public function testConfigurableProductChildStatusDisabled()
22+
{
23+
$parentSku = 'configurable';
24+
$enabledChildSku = 'simple_20';
25+
$disabledChildSku = 'simple_10';
26+
$query = $this->getQuery($parentSku);
27+
$response = $this->graphQlQuery($query);
28+
$this->assertContainsEquals(
29+
['product' => ['sku' => $enabledChildSku, 'stock_status' => 'IN_STOCK']],
30+
$response['products']['items'][0]['variants']
31+
);
32+
$this->assertNotContainsEquals(
33+
['product' => ['sku' => $disabledChildSku, 'stock_status' => 'OUT_OF_STOCK']],
34+
$response['products']['items'][0]['variants']
35+
);
36+
}
37+
38+
/**
39+
* @param string $sku
40+
* @return string
41+
*/
42+
private function getQuery(string $sku)
43+
{
44+
return <<<QUERY
45+
{
46+
products(filter: {sku: {eq: "{$sku}"}})
47+
{
48+
items {
49+
sku
50+
... on ConfigurableProduct {
51+
variants {
52+
product {
53+
sku
54+
stock_status
55+
}
56+
}
57+
}
58+
}
59+
}
60+
}
61+
QUERY;
62+
}
63+
}

0 commit comments

Comments
 (0)