Skip to content

Commit 5c32883

Browse files
ENGCOM-5027: GraphQl-309: [Checkout] Checkout Agreements magento#504
- Merge Pull Request magento/graphql-ce#504 from magento/graphql-ce:graphQl-309-checkout-agreement-coverage - Merged commits: 1. 17b7c0a 2. d3190fe 3. 4faf980 4. f17893d 5. 6a8c89b 6. f90a620 7. 6b93033 8. cc5e217 9. c94a655 10. d82262c 11. 7305a43 12. 6a8edac 13. c3040e6 14. c1c1dc0 15. 4d7be93
2 parents beb058c + 4d7be93 commit 5c32883

File tree

9 files changed

+401
-3
lines changed

9 files changed

+401
-3
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CheckoutAgreementsGraphQl\Model\Resolver;
9+
10+
use Magento\CheckoutAgreements\Model\AgreementModeOptions;
11+
use Magento\CheckoutAgreements\Model\ResourceModel\Agreement\Collection;
12+
use Magento\Framework\GraphQl\Config\Element\Field;
13+
use Magento\Framework\GraphQl\Query\ResolverInterface;
14+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
15+
use Magento\CheckoutAgreements\Api\Data\AgreementInterface;
16+
use Magento\CheckoutAgreements\Model\ResourceModel\Agreement\CollectionFactory;
17+
use Magento\Framework\App\Config\ScopeConfigInterface;
18+
use Magento\Store\Model\ScopeInterface;
19+
use Magento\Store\Model\StoreManagerInterface;
20+
21+
/**
22+
* Checkout Agreements resolver, used for GraphQL request processing
23+
*/
24+
class CheckoutAgreements implements ResolverInterface
25+
{
26+
/**
27+
* @var CollectionFactory
28+
*/
29+
private $agreementCollectionFactory;
30+
31+
/**
32+
* @var StoreManagerInterface
33+
*/
34+
private $storeManager;
35+
36+
/**
37+
* @var ScopeConfigInterface
38+
*/
39+
private $scopeConfig;
40+
41+
/**
42+
* @param CollectionFactory $agreementCollectionFactory
43+
* @param StoreManagerInterface $storeManager
44+
* @param ScopeConfigInterface $scopeConfig
45+
*/
46+
public function __construct(
47+
CollectionFactory $agreementCollectionFactory,
48+
StoreManagerInterface $storeManager,
49+
ScopeConfigInterface $scopeConfig
50+
) {
51+
$this->agreementCollectionFactory = $agreementCollectionFactory;
52+
$this->storeManager = $storeManager;
53+
$this->scopeConfig = $scopeConfig;
54+
}
55+
56+
/**
57+
* @inheritdoc
58+
*/
59+
public function resolve(
60+
Field $field,
61+
$context,
62+
ResolveInfo $info,
63+
array $value = null,
64+
array $args = null
65+
) {
66+
if (!$this->scopeConfig->isSetFlag('checkout/options/enable_agreements', ScopeInterface::SCOPE_STORE)) {
67+
return [];
68+
}
69+
70+
/** @var Collection $agreementsCollection */
71+
$agreementsCollection = $this->agreementCollectionFactory->create();
72+
$agreementsCollection->addStoreFilter($this->storeManager->getStore()->getId());
73+
$agreementsCollection->addFieldToFilter(AgreementInterface::IS_ACTIVE, 1);
74+
75+
$checkoutAgreementData = [];
76+
/** @var AgreementInterface $checkoutAgreement */
77+
foreach ($agreementsCollection->getItems() as $checkoutAgreement) {
78+
$checkoutAgreementData[] = [
79+
AgreementInterface::AGREEMENT_ID => $checkoutAgreement->getAgreementId(),
80+
AgreementInterface::CONTENT => $checkoutAgreement->getContent(),
81+
AgreementInterface::NAME => $checkoutAgreement->getName(),
82+
AgreementInterface::CONTENT_HEIGHT => $checkoutAgreement->getContentHeight(),
83+
AgreementInterface::CHECKBOX_TEXT => $checkoutAgreement->getCheckboxText(),
84+
AgreementInterface::IS_HTML => $checkoutAgreement->getIsHtml(),
85+
AgreementInterface::MODE =>
86+
AgreementModeOptions::MODE_AUTO === (int)$checkoutAgreement->getMode() ? 'AUTO' : 'MANUAL',
87+
];
88+
}
89+
return $checkoutAgreementData;
90+
}
91+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# CheckoutAgreementsGraphQl
2+
3+
**CheckoutAgreementsGraphQl** provides type information for the GraphQl module
4+
to generate Checkout Agreements fields for Checkout Agreements information endpoints.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "magento/module-checkout-agreements-graph-ql",
3+
"description": "N/A",
4+
"type": "magento2-module",
5+
"require": {
6+
"php": "~7.1.3||~7.2.0",
7+
"magento/framework": "*",
8+
"magento/module-store": "*",
9+
"magento/module-checkout-agreements": "*"
10+
},
11+
"suggest": {
12+
"magento/module-graph-ql": "*"
13+
},
14+
"license": [
15+
"OSL-3.0",
16+
"AFL-3.0"
17+
],
18+
"autoload": {
19+
"files": [
20+
"registration.php"
21+
],
22+
"psr-4": {
23+
"Magento\\CheckoutAgreementsGraphQl\\": ""
24+
}
25+
}
26+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9+
<module name="Magento_CheckoutAgreementsGraphQl" />
10+
</config>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright © Magento, Inc. All rights reserved.
2+
# See COPYING.txt for license details.
3+
4+
type Query {
5+
checkoutAgreements: [CheckoutAgreement] @resolver(class: "Magento\\CheckoutAgreementsGraphQl\\Model\\Resolver\\CheckoutAgreements") @doc(description: "The Checkout Agreements information")
6+
}
7+
8+
type CheckoutAgreement @doc(description: "Defines all Checkout Agreement information") {
9+
agreement_id: Int! @doc(description: "Checkout Agreement identifier")
10+
name: String! @doc(description: "Checkout Agreement name")
11+
content: String! @doc(description: "Checkout Agreement content")
12+
content_height: String @doc(description: "Checkout Agreement content height")
13+
checkbox_text: String! @doc(description: "Checkout Agreement checkbox text")
14+
is_html: Boolean! @doc(description: "Is Checkout Agreement content in HTML format")
15+
mode: CheckoutAgreementMode!
16+
}
17+
18+
enum CheckoutAgreementMode {
19+
AUTO
20+
MANUAL
21+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Framework\Component\ComponentRegistrar;
9+
10+
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_CheckoutAgreementsGraphQl', __DIR__);

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
"magento/module-catalog-widget": "*",
128128
"magento/module-checkout": "*",
129129
"magento/module-checkout-agreements": "*",
130+
"magento/module-checkout-agreements-graph-ql": "*",
130131
"magento/module-cms": "*",
131132
"magento/module-cms-url-rewrite": "*",
132133
"magento/module-config": "*",

composer.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)