Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into develop
  • Loading branch information
mage-os-ci committed Nov 10, 2023
2 parents 0862b75 + 3faac9c commit 4b0cace
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
<waitForElementVisible selector="{{StorefrontMinicartSection.viewAndEditCart}}" stepKey="waitForViewAndEditCartVisible"/>
<click selector="{{StorefrontMinicartSection.goToCheckout}}" stepKey="goToCheckout"/>
<waitForPageLoad stepKey="waitForGuestCheckoutPageLoad"/>
<waitForElementVisible selector="{{CheckoutShippingSection.emailAddress}}" stepKey="waitForEmailFieldVisible" />
<fillField selector="{{CheckoutShippingSection.emailAddress}}" userInput="{{MsiCustomer1.email}}" stepKey="enterEmail"/>
<waitForPageLoad stepKey="waitAfterEnterEmail"/>
<fillField selector=".billing-address-form input[name=firstname]" userInput="{{MsiCustomer1.firstname}}" stepKey="enterFirstName"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php
/************************************************************************
*
* Copyright 2023 Adobe
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe and its suppliers, if any. The intellectual
* and technical concepts contained herein are proprietary to Adobe
* and its suppliers and are protected by all applicable intellectual
* property laws, including trade secret and copyright laws.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe.
* ************************************************************************
*/
declare(strict_types=1);

namespace Magento\InventoryConfigurableProduct\Plugin\Model\ResourceModel\Attribute;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
use Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionSelectBuilderInterface;
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
use Magento\Framework\App\ScopeInterface;
use Magento\Framework\DB\Select;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Store\Model\Store;
use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus;

/**
* Plugin for OptionSelectBuilderInterface to add "enabled" filter.
*/
class IsEnabledOptionSelectBuilder
{
/**
* @param ProductAttributeRepositoryInterface $attributeRepository
* @param MetadataPool $metadataPool
*/
public function __construct(
private readonly ProductAttributeRepositoryInterface $attributeRepository,
private readonly MetadataPool $metadataPool
) {
}

/**
* Add "enabled" filter to select.
*
* @param OptionSelectBuilderInterface $subject
* @param Select $select
* @param AbstractAttribute $superAttribute
* @param int $productId
* @param ScopeInterface $scope
* @return Select
*
* @throws NoSuchEntityException
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterGetSelect(
OptionSelectBuilderInterface $subject,
Select $select,
AbstractAttribute $superAttribute,
int $productId,
ScopeInterface $scope
) {
$storeId = $scope->getId();
$status = $this->attributeRepository->get(ProductInterface::STATUS);
$metadata = $this->metadataPool->getMetadata(ProductInterface::class);
$linkField = $metadata->getLinkField();

$select->joinInner(
['entity_status_global' => $status->getBackendTable()],
"entity_status_global.{$linkField} = entity.{$linkField}"
. " AND entity_status_global.attribute_id = {$status->getAttributeId()}"
. " AND entity_status_global.store_id = " . Store::DEFAULT_STORE_ID,
[]
)->joinLeft(
['entity_status_store' => $status->getBackendTable()],
"entity_status_store.{$linkField} = entity.{$linkField}"
. " AND entity_status_store.attribute_id = {$status->getAttributeId()}"
. " AND entity_status_store.store_id = {$storeId}",
[]
)->where(
$select->getConnection()->getIfNullSql('entity_status_global.value', 'entity_status_store.value') . ' = ?',
ProductStatus::STATUS_ENABLED
);

return $select;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@

use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\Product\Attribute\Source\Status;
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
use Magento\ConfigurableProduct\Api\Data\OptionInterface;
use Magento\ConfigurableProduct\Test\Fixture\Attribute as AttributeFixture;
use Magento\ConfigurableProduct\Test\Fixture\Product as ConfigurableProductFixture;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Store\Model\StoreManagerInterface;
use Magento\TestFramework\Fixture\DataFixture;
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\GraphQlAbstract;

Expand Down Expand Up @@ -150,4 +156,59 @@ private function assertConfigurableProductOptions($product, $response)
);
}
}

#[
DataFixture(AttributeFixture::class, ['options' => ['brown', 'beige', 'black']], 'attr'),
DataFixture(ProductFixture::class, as: 'p1'),
DataFixture(ProductFixture::class, ['status' => Status::STATUS_DISABLED], 'p2'),
DataFixture(ProductFixture::class, as: 'p3'),
DataFixture(
ConfigurableProductFixture::class,
['_options' => ['$attr$'],'_links' => ['$p1$', '$p2$', '$p3$']],
'conf1'
),
]
public function testShouldNotReturnOptionsWithDisabledProductsDefaultStock(): void
{
$fixtures = Bootstrap::getObjectManager()->get(DataFixtureStorageManager::class)->getStorage();
$sku = $fixtures->get('conf1')->getSku();
$brown = $fixtures->get('p1')->getSku();
$black = $fixtures->get('p3')->getSku();
$query = <<<QUERY
{
products(filter: { sku: { eq: "$sku" } }) {
items {
sku
... on ConfigurableProduct {
configurable_options {
label
values {
label
}
}
variants {
product {
sku
}
}
}
}
}
}
QUERY;
$response = $this->graphQlQuery($query, [], '', ['Store' => 'default']);
$this->assertCount(1, $response['products']['items']);
$product = $response['products']['items'][0];
$this->assertEquals($sku, $product['sku']);
$this->assertCount(1, $product['configurable_options']);
$this->assertEqualsCanonicalizing(
['brown', 'black'],
array_column($product['configurable_options'][0]['values'], 'label')
);
$this->assertCount(2, $product['variants']);
$this->assertEqualsCanonicalizing(
[$brown, $black],
array_column(array_column($product['variants'], 'product'), 'sku')
);
}
}
3 changes: 2 additions & 1 deletion InventoryConfigurableProduct/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"magento/module-store": "*",
"magento/module-catalog-inventory": "*",
"magento/module-sales": "*",
"magento/module-configurable-product": "*"
"magento/module-configurable-product": "*",
"magento/module-eav": "*"
},
"suggest": {
"magento/module-inventory": "*",
Expand Down
1 change: 1 addition & 0 deletions InventoryConfigurableProduct/etc/graphql/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionSelectBuilderInterface">
<plugin name="Magento_ConfigurableProduct_Plugin_Model_ResourceModel_Attribute_InStockOptionSelectBuilder_GraphQl" type="Magento\InventoryConfigurableProduct\Plugin\Model\ResourceModel\Attribute\IsSalableOptionSelectBuilder"/>
<plugin name="Magento_ConfigurableProduct_Plugin_Model_ResourceModel_Attribute_EnabledOptionSelectBuilder_GraphQl" type="Magento\InventoryConfigurableProduct\Plugin\Model\ResourceModel\Attribute\IsEnabledOptionSelectBuilder"/>
</type>
</config>

0 comments on commit 4b0cace

Please sign in to comment.