Skip to content

Commit

Permalink
ENGCOM-5027: GraphQl-309: [Checkout] Checkout Agreements magento#504
Browse files Browse the repository at this point in the history
 - 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
  • Loading branch information
magento-engcom-team committed May 8, 2019
2 parents beb058c + 4d7be93 commit 5c32883
Show file tree
Hide file tree
Showing 9 changed files with 401 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CheckoutAgreementsGraphQl\Model\Resolver;

use Magento\CheckoutAgreements\Model\AgreementModeOptions;
use Magento\CheckoutAgreements\Model\ResourceModel\Agreement\Collection;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\CheckoutAgreements\Api\Data\AgreementInterface;
use Magento\CheckoutAgreements\Model\ResourceModel\Agreement\CollectionFactory;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;

/**
* Checkout Agreements resolver, used for GraphQL request processing
*/
class CheckoutAgreements implements ResolverInterface
{
/**
* @var CollectionFactory
*/
private $agreementCollectionFactory;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* @var ScopeConfigInterface
*/
private $scopeConfig;

/**
* @param CollectionFactory $agreementCollectionFactory
* @param StoreManagerInterface $storeManager
* @param ScopeConfigInterface $scopeConfig
*/
public function __construct(
CollectionFactory $agreementCollectionFactory,
StoreManagerInterface $storeManager,
ScopeConfigInterface $scopeConfig
) {
$this->agreementCollectionFactory = $agreementCollectionFactory;
$this->storeManager = $storeManager;
$this->scopeConfig = $scopeConfig;
}

/**
* @inheritdoc
*/
public function resolve(
Field $field,
$context,
ResolveInfo $info,
array $value = null,
array $args = null
) {
if (!$this->scopeConfig->isSetFlag('checkout/options/enable_agreements', ScopeInterface::SCOPE_STORE)) {
return [];
}

/** @var Collection $agreementsCollection */
$agreementsCollection = $this->agreementCollectionFactory->create();
$agreementsCollection->addStoreFilter($this->storeManager->getStore()->getId());
$agreementsCollection->addFieldToFilter(AgreementInterface::IS_ACTIVE, 1);

$checkoutAgreementData = [];
/** @var AgreementInterface $checkoutAgreement */
foreach ($agreementsCollection->getItems() 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(),
AgreementInterface::MODE =>
AgreementModeOptions::MODE_AUTO === (int)$checkoutAgreement->getMode() ? 'AUTO' : 'MANUAL',
];
}
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-store": "*",
"magento/module-checkout-agreements": "*"
},
"suggest": {
"magento/module-graph-ql": "*"
},
"license": [
"OSL-3.0",
"AFL-3.0"
],
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Magento\\CheckoutAgreementsGraphQl\\": ""
}
}
}
10 changes: 10 additions & 0 deletions app/code/Magento/CheckoutAgreementsGraphQl/etc/module.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?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" />
</config>
21 changes: 21 additions & 0 deletions app/code/Magento/CheckoutAgreementsGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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 information")
}

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 text")
is_html: Boolean! @doc(description: "Is Checkout Agreement content in HTML format")
mode: CheckoutAgreementMode!
}

enum CheckoutAgreementMode {
AUTO
MANUAL
}
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 @@ -127,6 +127,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
6 changes: 3 additions & 3 deletions composer.lock

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

Loading

0 comments on commit 5c32883

Please sign in to comment.