forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
9 changed files
with
401 additions
and
3 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/CheckoutAgreements.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\\": "" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
21
app/code/Magento/CheckoutAgreementsGraphQl/etc/schema.graphqls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
10
app/code/Magento/CheckoutAgreementsGraphQl/registration.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.