Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CatalogGraphQl\Model\Resolver\Product;

use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;

/**
* Format the option type value.
*/
class CustomizableDateTypeOptionValue implements ResolverInterface
{
/**
* Resolver option code.
*/
private const OPTION_CODE = 'type';

/**
* Resolver enum type options to up case format.
*
* @param Field $field
* @param ContextInterface $context
* @param ResolveInfo $info
* @param array|null $value
* @param array|null $args
*
* @return string
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null): string
{
$dteType = $value[self::OPTION_CODE] ?? '';

return strtoupper($dteType);
}
}
7 changes: 7 additions & 0 deletions app/code/Magento/CatalogGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ enum PriceTypeEnum @doc(description: "This enumeration the price type.") {
DYNAMIC
}

enum CustomizableDateTypeEnum @doc(description: "This enumeration customizable date type.") {
DATE
DATE_TIME
TIME
}

type ProductPrices @doc(description: "ProductPrices is deprecated, replaced by PriceRange. The ProductPrices object contains the regular price of an item, as well as its minimum and maximum prices. Only composite products, which include bundle, configurable, and grouped products, can contain a minimum and maximum price.") {
minimalPrice: Price @deprecated(reason: "Use PriceRange.minimum_price.") @doc(description: "The lowest possible final price for all the options defined within a composite product. If you are specifying a price range, this would be the from value.")
maximalPrice: Price @deprecated(reason: "Use PriceRange.maximum_price.") @doc(description: "The highest possible final price for all the options defined within a composite product. If you are specifying a price range, this would be the to value.")
Expand Down Expand Up @@ -153,6 +159,7 @@ type CustomizableDateOption implements CustomizableOptionInterface @doc(descript
type CustomizableDateValue @doc(description: "CustomizableDateValue defines the price and sku of a product whose page contains a customized date picker.") {
price: Float @doc(description: "The price assigned to this option.")
price_type: PriceTypeEnum @doc(description: "FIXED, PERCENT, or DYNAMIC.")
type: CustomizableDateTypeEnum @doc(description: "DATE, DATE_TIME or TIME") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableDateTypeOptionValue")
sku: String @doc(description: "The Stock Keeping Unit for this option.")
uid: ID! @doc(description: "A string that encodes option details.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableEnteredOptionValueUid") # A Base64 string that encodes option details.
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\GraphQl\Catalog\Options;

use Exception;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Helper\CompareArraysRecursively;
use Magento\TestFramework\TestCase\GraphQlAbstract;

/**
* Test for customizable product options.
*/
class CustomizableOptionsTest extends GraphQlAbstract
{
/**
* @var CompareArraysRecursively
*/
private $compareArraysRecursively;

/**
* @inheritDoc
*/
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
$this->compareArraysRecursively = $objectManager->create(CompareArraysRecursively::class);
}

/**
* @magentoApiDataFixture Magento/Catalog/_files/product_with_options.php
*
* @param array $optionDataProvider
*
* @dataProvider getProductCustomizableOptionsProvider
* @throws Exception
*/
public function testQueryCustomizableOptions(array $optionDataProvider): void
{
$productSku = 'simple';
$query = $this->getQuery($productSku);
$response = $this->graphQlQuery($query);
$responseProduct = reset($response['products']['items']);
self::assertNotEmpty($responseProduct['options']);

foreach ($optionDataProvider as $key => $data) {
$this->compareArraysRecursively->execute($data, $responseProduct[$key]);
}
}

/**
* Get query.
*
* @param string $sku
*
* @return string
*/
private function getQuery(string $sku): string
{
return <<<QUERY
query {
products(filter: { sku: { eq: "$sku" } }) {
items {
... on CustomizableProductInterface {
options {
option_id
title
... on CustomizableDateOption {
value {
type
}
}
}
}
}
}
}
QUERY;
}

/**
* Get product customizable options provider.
*
* @return array
*/
public function getProductCustomizableOptionsProvider(): array
{
return [
'products' => [
'items' => [
'options' => [
[
'title' => 'test_option_code_1'
],
[
'title' => 'area option'
],
[
'title' => 'file option'
],
[
'title' => 'radio option'
],
[
'title' => 'multiple option'
],
[
'title' => 'date option',
'values' => [
'type' => 'DATE'
]
],
[
'title' => 'date_time option',
'values' => [
'type' => 'DATE_TIME'
]
],
[
'title' => 'time option',
'values' => [
'type' => 'TIME'
]
]
]
]
]
];
}
}