Skip to content

Issue 32793 Add has_options and required_options to grapql Product Interface #33125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/code/Magento/CatalogGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ interface ProductInterface @typeResolver(class: "Magento\\CatalogGraphQl\\Model\
categories: [CategoryInterface] @doc(description: "The categories assigned to a product.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Categories") @cache(cacheIdentity: "Magento\\CatalogGraphQl\\Model\\Resolver\\Category\\CategoriesIdentity")
canonical_url: String @doc(description: "Relative canonical URL. This value is returned only if the system setting 'Use Canonical Link Meta Tag For Products' is enabled") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CanonicalUrl")
media_gallery: [MediaGalleryInterface] @doc(description: "An array of Media Gallery objects.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\MediaGallery")
has_options: Boolean @doc(description: "Indicates whether additional options have been created for the product.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be wrapped in an interface?
we do have CustomizableProductInterface and this can be used as a fragment
in this interface we have
options: [CustomizableOptionInterface]
which has_options can be as simple as is_empty(options)
and required_options will be inside CustomizableOptionInterface for each option required: Boolean
So what is the real need for these 2 fields what we can't achieve it the existing way?

required_options: Boolean @doc(description: "Indicates whether the product has required options.")
}

interface PhysicalProductInterface @typeResolver(class: "Magento\\CatalogGraphQl\\Model\\ProductInterfaceTypeResolverComposite") @doc(description: "PhysicalProductInterface contains attributes specific to tangible products.") {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\GraphQl\Catalog;

use Exception;
use Magento\TestFramework\TestCase\GraphQlAbstract;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a class description

/**
* Test for checking has_options & required_options attributes in Products query.
*/
class ProductHasOptionsTest extends GraphQlAbstract
{
/**
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_custom_options.php
*
* @return void
* @throws Exception
*/
public function testHasOptionsAndRequiredOptionsAttribute(): void
{
$productSku = 'simple_with_custom_options';
$query = <<<QUERY
{
products(filter: {sku: {eq: "{$productSku}"}}) {
items {
sku
has_options
required_options
}
}
}
QUERY;
$response = $this->graphQlQuery($query);

$this->assertArrayHasKey('has_options', $response['products']['items'][0]);
$this->assertArrayHasKey('required_options', $response['products']['items'][0]);
}
}