Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

GraphQl-309: [Checkout] Checkout Agreements #504

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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,48 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CheckoutAgreementsGraphQl\Model\Resolver;

use Magento\CheckoutAgreementsGraphQl\Model\Resolver\DataProvider\CheckoutAgreements as CheckoutAgreementsDataProvider;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;

/**
* CMS page field resolver, used for GraphQL request processing
VitaliyBoyko marked this conversation as resolved.
Show resolved Hide resolved
*/
class CheckoutAgreements implements ResolverInterface
{
/**
* @var CheckoutAgreementsDataProvider
*/
private $checkoutAgreementsDataProvider;

/**
* @param CheckoutAgreementsDataProvider $checkoutAgreementsDataProvider
*/
public function __construct(
CheckoutAgreementsDataProvider $checkoutAgreementsDataProvider
) {
$this->checkoutAgreementsDataProvider = $checkoutAgreementsDataProvider;
}

/**
* @inheritdoc
*/
public function resolve(
Field $field,
$context,
ResolveInfo $info,
array $value = null,
array $args = null
) {
$checkoutAgreementsData = $this->checkoutAgreementsDataProvider->getData();
VitaliyBoyko marked this conversation as resolved.
Show resolved Hide resolved

return $checkoutAgreementsData;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CheckoutAgreementsGraphQl\Model\Resolver\DataProvider;

use Magento\CheckoutAgreements\Api\CheckoutAgreementsListInterface;
use Magento\CheckoutAgreements\Api\Data\AgreementInterface;
use Magento\Framework\Api\SearchCriteriaBuilder;

/**
* Checkout Agreements data provider
*/
class CheckoutAgreements
{
/**
* @var SearchCriteriaBuilder
*/
private $searchCriteriaBuilder;

/**
* @var CheckoutAgreementsListInterface
*/
private $checkoutAgreementsList;

/**
* @param CheckoutAgreementsListInterface $checkoutAgreementsList
* @param SearchCriteriaBuilder $searchCriteriaBuilder
*/
public function __construct(
CheckoutAgreementsListInterface $checkoutAgreementsList,
SearchCriteriaBuilder $searchCriteriaBuilder
) {
$this->checkoutAgreementsList = $checkoutAgreementsList;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
}

/**
* Get All Active Checkout Agreements Data
*
* @return array
*/
public function getData(): array
{
$this->searchCriteriaBuilder->addFilter(AgreementInterface::IS_ACTIVE, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to add support of store (with tests coverage)

Also, looks using the collection (which we can consider as query API)

$agreements = $this->agreementCollectionFactory->create();
$agreements->addStoreFilter($this->_storeManager->getStore()->getId()); // TODO: store should be get from query context
 $agreements->addFieldToFilter('is_active', 1);

$searchCriteria = $this->searchCriteriaBuilder->create();
$checkoutAgreements = $this->checkoutAgreementsList->getList($searchCriteria);

$checkoutAgreementData = [];
foreach ($checkoutAgreements as $checkoutAgreement) {
$checkoutAgreementData[] = [
AgreementInterface::AGREEMENT_ID => $checkoutAgreement->getAgreementId(),
AgreementInterface::CONTENT => $checkoutAgreement->getContent(),
AgreementInterface::NAME => $checkoutAgreement->getName(),
AgreementInterface::CONTENT_HEIGHT => $checkoutAgreement->getContentHeight(),
AgreementInterface::CHECKBOX_TEXT => $checkoutAgreement->getCheckboxText(),
AgreementInterface::IS_HTML => $checkoutAgreement->getIsHtml(),
];
}

return $checkoutAgreementData;
}
}
4 changes: 4 additions & 0 deletions app/code/Magento/CheckoutAgreementsGraphQl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# CheckoutAgreementsGraphQl

**CheckoutAgreementsGraphQl** provides type information for the GraphQl module
to generate Checkout Agreements fields for Checkout Agreements information endpoints.
26 changes: 26 additions & 0 deletions app/code/Magento/CheckoutAgreementsGraphQl/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "magento/module-checkout-agreements-graph-ql",
"description": "N/A",
"type": "magento2-module",
"require": {
"php": "~7.1.3||~7.2.0",
"magento/framework": "*",
"magento/module-checkout-agreements": "*"
},
"suggest": {
"magento/module-graph-ql": "*",
"magento/module-store-graph-ql": "*"
},
"license": [
"OSL-3.0",
"AFL-3.0"
],
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Magento\\CheckoutAgreementsGraphQl\\": ""
}
}
}
14 changes: 14 additions & 0 deletions app/code/Magento/CheckoutAgreementsGraphQl/etc/module.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_CheckoutAgreementsGraphQl">
<sequence>
<module name="Magento_GraphQl"/>
VitaliyBoyko marked this conversation as resolved.
Show resolved Hide resolved
</sequence>
</module>
</config>
15 changes: 15 additions & 0 deletions app/code/Magento/CheckoutAgreementsGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright © Magento, Inc. All rights reserved.
# See COPYING.txt for license details.

type Query {
checkoutAgreements: [CheckoutAgreement] @resolver(class: "Magento\\CheckoutAgreementsGraphQl\\Model\\Resolver\\CheckoutAgreements") @doc(description: "The Checkout Agreements query returns information about a Checkout Agreements")
Copy link
Contributor

Choose a reason for hiding this comment

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

The Checkout Agreements query returns information about a Checkout Agreements :)

}

type CheckoutAgreement @doc(description: "Defines all Checkout Agreement information") {
agreement_id: Int @doc(description: "Checkout Agreement identifier")
name: String @doc(description: "Checkout Agreement name")
content: String @doc(description: "Checkout Agreement content")
content_height: String @doc(description: "Checkout Agreement content height")
checkbox_text: String @doc(description: "Checkout Agreement checkbox tex")
is_html: Boolean @doc(description: "Is Checkout Agreement content in HTML format")
VitaliyBoyko marked this conversation as resolved.
Show resolved Hide resolved
}
10 changes: 10 additions & 0 deletions app/code/Magento/CheckoutAgreementsGraphQl/registration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_CheckoutAgreementsGraphQl', __DIR__);
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
"magento/module-catalog-widget": "*",
"magento/module-checkout": "*",
"magento/module-checkout-agreements": "*",
"magento/module-checkout-agreements-graph-ql": "*",
"magento/module-cms": "*",
"magento/module-cms-url-rewrite": "*",
"magento/module-config": "*",
Expand Down
3 changes: 1 addition & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\GraphQl\CheckoutAgreements\Api;

use Magento\TestFramework\TestCase\GraphQlAbstract;

class CheckoutAgreementsListTest extends GraphQlAbstract
{
/**
* @magentoApiDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php
* @magentoApiDataFixture Magento/CheckoutAgreements/_files/agreement_inactive_with_text_content.php
*/
public function testGetActiveAgreement()
{
$query =
<<<QUERY
{
checkoutAgreements {
agreement_id
name
content
content_height
checkbox_text
is_html
}
}
QUERY;

$response = $this->graphQlQuery($query);
$this->assertArrayHasKey('checkoutAgreements', $response);
$agreements = $response['checkoutAgreements'];
$this->assertEquals(1, count($agreements));
VitaliyBoyko marked this conversation as resolved.
Show resolved Hide resolved
$this->assertEquals('Checkout Agreement (active)', $agreements[0]['name']);
$this->assertEquals('Checkout agreement content: <b>HTML</b>', $agreements[0]['content']);
$this->assertEquals('200px', $agreements[0]['content_height']);
$this->assertEquals('Checkout agreement checkbox text.', $agreements[0]['checkbox_text']);
$this->assertEquals(true, $agreements[0]['is_html']);
}
VitaliyBoyko marked this conversation as resolved.
Show resolved Hide resolved
}