Skip to content

Commit

Permalink
LYNX-304: Added StoreConfig extra fields
Browse files Browse the repository at this point in the history
  • Loading branch information
svera committed Dec 13, 2023
1 parent 72ef5ed commit d40629c
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 2 deletions.
8 changes: 8 additions & 0 deletions app/code/Magento/QuoteGraphQl/etc/graphql/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,12 @@
</argument>
</arguments>
</type>
<type name="Magento\StoreGraphQl\Model\Resolver\Store\StoreConfigDataProvider">
<arguments>
<argument name="extendedConfigData" xsi:type="array">
<item name="is_guest_checkout_enabled" xsi:type="string">checkout/options/guest_checkout</item>
<item name="is_one_page_checkout_enabled" xsi:type="string">checkout/options/onepage_checkout_enabled</item>
</argument>
</arguments>
</type>
</config>
4 changes: 4 additions & 0 deletions app/code/Magento/QuoteGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,7 @@ enum CartUserInputErrorType {
UNDEFINED
}

type StoreConfig {
is_guest_checkout_enabled: Boolean @doc(description: "Extended Config Data - checkout/options/guest_checkout")
is_one_page_checkout_enabled: Boolean @doc(description: "Extended Config Data - checkout/options/onepage_checkout_enabled")
}
4 changes: 4 additions & 0 deletions app/code/Magento/StoreGraphQl/etc/graphql/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
<arguments>
<argument name="extendedConfigData" xsi:type="array">
<item name="use_store_in_url" xsi:type="string">web/url/use_store</item>
<item name="default_country" xsi:type="string">general/country/default</item>
<item name="countries_with_required_region" xsi:type="string">general/region/state_required</item>
<item name="display_state_if_optional" xsi:type="string">general/region/display_all</item>
<item name="optional_zip_countries" xsi:type="string">general/country/optional_zip_countries</item>
</argument>
</arguments>
</type>
Expand Down
4 changes: 4 additions & 0 deletions app/code/Magento/StoreGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ type StoreConfig @doc(description: "Contains information about a store's configu
secure_base_static_url : String @doc(description: "The secure fully-qualified URL that specifies the location of static view files.")
secure_base_media_url : String @doc(description: "The secure fully-qualified URL that specifies the location of media files.")
use_store_in_url: Boolean @doc(description: "Indicates whether the store code should be used in the URL.")
default_country: String @doc(description: "Extended Config Data - general/country/default")
countries_with_required_region: String @doc(description: "Extended Config Data - general/region/state_required")
optional_zip_countries: String @doc(description: "Extended Config Data - general/country/optional_zip_countries")
display_state_if_optional: Boolean @doc(description: "Extended Config Data - general/region/display_all")
}
32 changes: 32 additions & 0 deletions app/code/Magento/TaxGraphQl/etc/graphql/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0"?>
<!--
/************************************************************************
*
* 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.
* ************************************************************************
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\StoreGraphQl\Model\Resolver\Store\StoreConfigDataProvider">
<arguments>
<argument name="extendedConfigData" xsi:type="array">
<item name="shopping_cart_display_price" xsi:type="string">tax/cart_display/price</item>
<item name="shopping_cart_display_shipping" xsi:type="string">tax/cart_display/shipping</item>
<item name="shopping_cart_display_subtotal" xsi:type="string">tax/cart_display/subtotal</item>
<item name="shopping_cart_display_grand_total" xsi:type="string">tax/cart_display/grandtotal</item>
<item name="shopping_cart_display_full_summary" xsi:type="string">tax/cart_display/full_summary</item>
<item name="shopping_cart_display_zero_tax" xsi:type="string">tax/cart_display/zero_tax</item>
</argument>
</arguments>
</type>
</config>
9 changes: 9 additions & 0 deletions app/code/Magento/TaxGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@
enum PriceAdjustmentCodesEnum {
TAX @deprecated(reason: "`PriceAdjustmentCodesEnum` is deprecated. Tax is included or excluded in the price. Tax is not shown separately in Catalog.")
}

type StoreConfig {
shopping_cart_display_price: Int @doc(description: "Extended Config Data - tax/cart_display/price")
shopping_cart_display_shipping: Int @doc(description: "Extended Config Data - tax/cart_display/shipping")
shopping_cart_display_subtotal: Int @doc(description: "Extended Config Data - tax/cart_display/subtotal")
shopping_cart_display_grand_total: Boolean @doc(description: "Extended Config Data - tax/cart_display/grandtotal")
shopping_cart_display_full_summary: Boolean @doc(description: "Extended Config Data - tax/cart_display/full_summary")
shopping_cart_display_zero_tax: Boolean @doc(description: "Extended Config Data - tax/cart_display/zero_tax")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\GraphQl\Quote;

use Magento\Checkout\Helper\Data;
use Magento\Store\Model\ScopeInterface;
use Magento\TestFramework\Fixture\Config as ConfigFixture;
use Magento\TestFramework\TestCase\GraphQlAbstract;

/**
* Test the GraphQL endpoint's StoreConfigs query
*/
class StoreConfigResolverTest extends GraphQlAbstract
{
#[
ConfigFixture(Data::XML_PATH_GUEST_CHECKOUT, true, ScopeInterface::SCOPE_STORE, 'default'),
ConfigFixture('checkout/options/onepage_checkout_enabled', true, ScopeInterface::SCOPE_STORE, 'default'),
]
public function testGetStoreConfig(): void
{
$query
= <<<QUERY
{
storeConfig {
is_guest_checkout_enabled,
is_one_page_checkout_enabled,
}
}
QUERY;
$response = $this->graphQlQuery($query);
$this->assertArrayHasKey('storeConfig', $response);
$this->validateStoreConfig($response['storeConfig']);
}

/**
* Validate Store Config Data
*
* @param array $responseConfig
*/
private function validateStoreConfig(
array $responseConfig,
): void {
$this->assertTrue($responseConfig['is_guest_checkout_enabled']);
$this->assertTrue($responseConfig['is_one_page_checkout_enabled']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@

namespace Magento\GraphQl\Store;

use Magento\Directory\Helper\Data;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Store\Api\Data\StoreConfigInterface;
use Magento\Store\Api\StoreConfigManagerInterface;
use Magento\Store\Api\StoreRepositoryInterface;
use Magento\Store\Api\StoreResolverInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\Store;
use Magento\TestFramework\Fixture\Config;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\ObjectManager;
use Magento\TestFramework\TestCase\GraphQlAbstract;
Expand All @@ -39,6 +42,12 @@ protected function setUp(): void
* @magentoApiDataFixture Magento/Store/_files/store.php
* @throws NoSuchEntityException
*/
#[
Config(Data::XML_PATH_DEFAULT_COUNTRY, 'es', ScopeInterface::SCOPE_STORE, 'default'),
Config(Data::XML_PATH_STATES_REQUIRED, 'us', ScopeInterface::SCOPE_STORE, 'default'),
Config(Data::OPTIONAL_ZIP_COUNTRIES_CONFIG_PATH, 'fr', ScopeInterface::SCOPE_STORE, 'default'),
Config(Data::XML_PATH_DISPLAY_ALL_STATES, true, ScopeInterface::SCOPE_STORE, 'default'),
]
public function testGetStoreConfig(): void
{
/** @var StoreConfigManagerInterface $storeConfigManager */
Expand Down Expand Up @@ -80,7 +89,10 @@ public function testGetStoreConfig(): void
secure_base_link_url,
secure_base_static_url,
secure_base_media_url,
store_name
default_country,
countries_with_required_region,
optional_zip_countries,
display_state_if_optional
}
}
QUERY;
Expand Down Expand Up @@ -136,6 +148,9 @@ private function validateStoreConfig(
$this->assertEquals($storeConfig->getSecureBaseLinkUrl(), $responseConfig['secure_base_link_url']);
$this->assertEquals($storeConfig->getSecureBaseStaticUrl(), $responseConfig['secure_base_static_url']);
$this->assertEquals($storeConfig->getSecureBaseMediaUrl(), $responseConfig['secure_base_media_url']);
$this->assertEquals($store->getName(), $responseConfig['store_name']);
$this->assertEquals('es', $responseConfig['default_country']);
$this->assertEquals('us', $responseConfig['countries_with_required_region']);
$this->assertEquals('fr', $responseConfig['optional_zip_countries']);
$this->assertEquals('true', $responseConfig['display_state_if_optional']);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\GraphQl\Tax;

use Magento\Directory\Helper\Data;
use Magento\Store\Model\ScopeInterface;
use Magento\TestFramework\Fixture\Config as ConfigFixture;
use Magento\TestFramework\TestCase\GraphQlAbstract;
use Magento\Tax\Model\Config;

/**
* Test the GraphQL endpoint's StoreConfigs query
*/
class StoreConfigResolverTest extends GraphQlAbstract
{
#[
ConfigFixture(Config::XML_PATH_DISPLAY_CART_PRICE, 1, ScopeInterface::SCOPE_STORE, 'default'),
ConfigFixture(Config::XML_PATH_DISPLAY_CART_SHIPPING, 1, ScopeInterface::SCOPE_STORE, 'default'),
ConfigFixture(Config::XML_PATH_DISPLAY_CART_SUBTOTAL, 1, ScopeInterface::SCOPE_STORE, 'default'),
ConfigFixture(Config::XML_PATH_DISPLAY_CART_GRANDTOTAL, 1, ScopeInterface::SCOPE_STORE, 'default'),
ConfigFixture(Config::XML_PATH_DISPLAY_CART_FULL_SUMMARY, 1, ScopeInterface::SCOPE_STORE, 'default'),
ConfigFixture(Config::XML_PATH_DISPLAY_CART_ZERO_TAX, 1, ScopeInterface::SCOPE_STORE, 'default'),
]
public function testGetStoreConfig(): void
{
$query
= <<<QUERY
{
storeConfig {
shopping_cart_display_price,
shopping_cart_display_shipping,
shopping_cart_display_subtotal,
shopping_cart_display_grand_total,
shopping_cart_display_full_summary,
shopping_cart_display_zero_tax,
}
}
QUERY;
$response = $this->graphQlQuery($query);
$this->assertArrayHasKey('storeConfig', $response);
$this->validateStoreConfig($response['storeConfig']);
}

/**
* Validate Store Config Data
*
* @param array $responseConfig
*/
private function validateStoreConfig(
array $responseConfig,
): void {
$this->assertEquals(1, $responseConfig['shopping_cart_display_price']);
$this->assertEquals(1, $responseConfig['shopping_cart_display_shipping']);
$this->assertEquals(1, $responseConfig['shopping_cart_display_subtotal']);
$this->assertEquals(1, $responseConfig['shopping_cart_display_grand_total']);
$this->assertEquals(1, $responseConfig['shopping_cart_display_full_summary']);
$this->assertEquals(1, $responseConfig['shopping_cart_display_zero_tax']);
}
}

0 comments on commit d40629c

Please sign in to comment.