Skip to content

Commit 3faac9c

Browse files
authored
Merge pull request #417 from magento-l3/PR-10122023
Pr 10122023
2 parents 2fbeaa3 + a99e6e9 commit 3faac9c

File tree

5 files changed

+156
-1
lines changed

5 files changed

+156
-1
lines changed

InventoryCatalogAdminUi/Test/Mftf/Test/AdminCreateOrderWithVirtualProductFromDefaultSourceWithBackordersTest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
<waitForElementVisible selector="{{StorefrontMinicartSection.viewAndEditCart}}" stepKey="waitForViewAndEditCartVisible"/>
102102
<click selector="{{StorefrontMinicartSection.goToCheckout}}" stepKey="goToCheckout"/>
103103
<waitForPageLoad stepKey="waitForGuestCheckoutPageLoad"/>
104+
<waitForElementVisible selector="{{CheckoutShippingSection.emailAddress}}" stepKey="waitForEmailFieldVisible" />
104105
<fillField selector="{{CheckoutShippingSection.emailAddress}}" userInput="{{MsiCustomer1.email}}" stepKey="enterEmail"/>
105106
<waitForPageLoad stepKey="waitAfterEnterEmail"/>
106107
<fillField selector=".billing-address-form input[name=firstname]" userInput="{{MsiCustomer1.firstname}}" stepKey="enterFirstName"/>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/************************************************************************
3+
*
4+
* Copyright 2023 Adobe
5+
* All Rights Reserved.
6+
*
7+
* NOTICE: All information contained herein is, and remains
8+
* the property of Adobe and its suppliers, if any. The intellectual
9+
* and technical concepts contained herein are proprietary to Adobe
10+
* and its suppliers and are protected by all applicable intellectual
11+
* property laws, including trade secret and copyright laws.
12+
* Dissemination of this information or reproduction of this material
13+
* is strictly forbidden unless prior written permission is obtained
14+
* from Adobe.
15+
* ************************************************************************
16+
*/
17+
declare(strict_types=1);
18+
19+
namespace Magento\InventoryConfigurableProduct\Plugin\Model\ResourceModel\Attribute;
20+
21+
use Magento\Catalog\Api\Data\ProductInterface;
22+
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
23+
use Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionSelectBuilderInterface;
24+
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
25+
use Magento\Framework\App\ScopeInterface;
26+
use Magento\Framework\DB\Select;
27+
use Magento\Framework\EntityManager\MetadataPool;
28+
use Magento\Framework\Exception\NoSuchEntityException;
29+
use Magento\Store\Model\Store;
30+
use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus;
31+
32+
/**
33+
* Plugin for OptionSelectBuilderInterface to add "enabled" filter.
34+
*/
35+
class IsEnabledOptionSelectBuilder
36+
{
37+
/**
38+
* @param ProductAttributeRepositoryInterface $attributeRepository
39+
* @param MetadataPool $metadataPool
40+
*/
41+
public function __construct(
42+
private readonly ProductAttributeRepositoryInterface $attributeRepository,
43+
private readonly MetadataPool $metadataPool
44+
) {
45+
}
46+
47+
/**
48+
* Add "enabled" filter to select.
49+
*
50+
* @param OptionSelectBuilderInterface $subject
51+
* @param Select $select
52+
* @param AbstractAttribute $superAttribute
53+
* @param int $productId
54+
* @param ScopeInterface $scope
55+
* @return Select
56+
*
57+
* @throws NoSuchEntityException
58+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
59+
*/
60+
public function afterGetSelect(
61+
OptionSelectBuilderInterface $subject,
62+
Select $select,
63+
AbstractAttribute $superAttribute,
64+
int $productId,
65+
ScopeInterface $scope
66+
) {
67+
$storeId = $scope->getId();
68+
$status = $this->attributeRepository->get(ProductInterface::STATUS);
69+
$metadata = $this->metadataPool->getMetadata(ProductInterface::class);
70+
$linkField = $metadata->getLinkField();
71+
72+
$select->joinInner(
73+
['entity_status_global' => $status->getBackendTable()],
74+
"entity_status_global.{$linkField} = entity.{$linkField}"
75+
. " AND entity_status_global.attribute_id = {$status->getAttributeId()}"
76+
. " AND entity_status_global.store_id = " . Store::DEFAULT_STORE_ID,
77+
[]
78+
)->joinLeft(
79+
['entity_status_store' => $status->getBackendTable()],
80+
"entity_status_store.{$linkField} = entity.{$linkField}"
81+
. " AND entity_status_store.attribute_id = {$status->getAttributeId()}"
82+
. " AND entity_status_store.store_id = {$storeId}",
83+
[]
84+
)->where(
85+
$select->getConnection()->getIfNullSql('entity_status_global.value', 'entity_status_store.value') . ' = ?',
86+
ProductStatus::STATUS_ENABLED
87+
);
88+
89+
return $select;
90+
}
91+
}

InventoryConfigurableProduct/Test/GraphQl/ConfigurableOptionsNonDefaultStockWebsiteTest.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@
99

1010
use Magento\Catalog\Api\ProductRepositoryInterface;
1111
use Magento\Catalog\Api\Data\ProductInterface;
12+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
13+
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
1214
use Magento\ConfigurableProduct\Api\Data\OptionInterface;
15+
use Magento\ConfigurableProduct\Test\Fixture\Attribute as AttributeFixture;
16+
use Magento\ConfigurableProduct\Test\Fixture\Product as ConfigurableProductFixture;
1317
use Magento\Framework\Exception\LocalizedException;
1418
use Magento\Framework\Exception\NoSuchEntityException;
1519
use Magento\Store\Model\StoreManagerInterface;
20+
use Magento\TestFramework\Fixture\DataFixture;
21+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
1622
use Magento\TestFramework\Helper\Bootstrap;
1723
use Magento\TestFramework\TestCase\GraphQlAbstract;
1824

@@ -150,4 +156,59 @@ private function assertConfigurableProductOptions($product, $response)
150156
);
151157
}
152158
}
159+
160+
#[
161+
DataFixture(AttributeFixture::class, ['options' => ['brown', 'beige', 'black']], 'attr'),
162+
DataFixture(ProductFixture::class, as: 'p1'),
163+
DataFixture(ProductFixture::class, ['status' => Status::STATUS_DISABLED], 'p2'),
164+
DataFixture(ProductFixture::class, as: 'p3'),
165+
DataFixture(
166+
ConfigurableProductFixture::class,
167+
['_options' => ['$attr$'],'_links' => ['$p1$', '$p2$', '$p3$']],
168+
'conf1'
169+
),
170+
]
171+
public function testShouldNotReturnOptionsWithDisabledProductsDefaultStock(): void
172+
{
173+
$fixtures = Bootstrap::getObjectManager()->get(DataFixtureStorageManager::class)->getStorage();
174+
$sku = $fixtures->get('conf1')->getSku();
175+
$brown = $fixtures->get('p1')->getSku();
176+
$black = $fixtures->get('p3')->getSku();
177+
$query = <<<QUERY
178+
{
179+
products(filter: { sku: { eq: "$sku" } }) {
180+
items {
181+
sku
182+
... on ConfigurableProduct {
183+
configurable_options {
184+
label
185+
values {
186+
label
187+
}
188+
}
189+
variants {
190+
product {
191+
sku
192+
}
193+
}
194+
}
195+
}
196+
}
197+
}
198+
QUERY;
199+
$response = $this->graphQlQuery($query, [], '', ['Store' => 'default']);
200+
$this->assertCount(1, $response['products']['items']);
201+
$product = $response['products']['items'][0];
202+
$this->assertEquals($sku, $product['sku']);
203+
$this->assertCount(1, $product['configurable_options']);
204+
$this->assertEqualsCanonicalizing(
205+
['brown', 'black'],
206+
array_column($product['configurable_options'][0]['values'], 'label')
207+
);
208+
$this->assertCount(2, $product['variants']);
209+
$this->assertEqualsCanonicalizing(
210+
[$brown, $black],
211+
array_column(array_column($product['variants'], 'product'), 'sku')
212+
);
213+
}
153214
}

InventoryConfigurableProduct/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"magento/module-store": "*",
1414
"magento/module-catalog-inventory": "*",
1515
"magento/module-sales": "*",
16-
"magento/module-configurable-product": "*"
16+
"magento/module-configurable-product": "*",
17+
"magento/module-eav": "*"
1718
},
1819
"suggest": {
1920
"magento/module-inventory": "*",

InventoryConfigurableProduct/etc/graphql/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
99
<type name="Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionSelectBuilderInterface">
1010
<plugin name="Magento_ConfigurableProduct_Plugin_Model_ResourceModel_Attribute_InStockOptionSelectBuilder_GraphQl" type="Magento\InventoryConfigurableProduct\Plugin\Model\ResourceModel\Attribute\IsSalableOptionSelectBuilder"/>
11+
<plugin name="Magento_ConfigurableProduct_Plugin_Model_ResourceModel_Attribute_EnabledOptionSelectBuilder_GraphQl" type="Magento\InventoryConfigurableProduct\Plugin\Model\ResourceModel\Attribute\IsEnabledOptionSelectBuilder"/>
1112
</type>
1213
</config>

0 commit comments

Comments
 (0)