-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4185 from magento-engcom/graphql-develop-prs
[Magento Community Engineering] Community Contributions - GraphQL
- Loading branch information
Showing
43 changed files
with
1,468 additions
and
78 deletions.
There are no files selected for viewing
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
61 changes: 61 additions & 0 deletions
61
app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductFieldsSelector.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,61 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogGraphQl\Model\Resolver\Product; | ||
|
||
use Magento\Framework\GraphQl\Query\FieldTranslator; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
|
||
/** | ||
* Select Product Fields From Resolve Info | ||
*/ | ||
class ProductFieldsSelector | ||
{ | ||
/** | ||
* @var FieldTranslator | ||
*/ | ||
private $fieldTranslator; | ||
|
||
/** | ||
* @param FieldTranslator $fieldTranslator | ||
*/ | ||
public function __construct(FieldTranslator $fieldTranslator) | ||
{ | ||
$this->fieldTranslator = $fieldTranslator; | ||
} | ||
|
||
/** | ||
* Return field names for all requested product fields. | ||
* | ||
* @param ResolveInfo $info | ||
* @param string $productNodeName | ||
* @return string[] | ||
*/ | ||
public function getProductFieldsFromInfo(ResolveInfo $info, string $productNodeName = 'product') : array | ||
{ | ||
$fieldNames = []; | ||
foreach ($info->fieldNodes as $node) { | ||
if ($node->name->value !== $productNodeName) { | ||
continue; | ||
} | ||
foreach ($node->selectionSet->selections as $selectionNode) { | ||
if ($selectionNode->kind === 'InlineFragment') { | ||
foreach ($selectionNode->selectionSet->selections as $inlineSelection) { | ||
if ($inlineSelection->kind === 'InlineFragment') { | ||
continue; | ||
} | ||
$fieldNames[] = $this->fieldTranslator->translate($inlineSelection->name->value); | ||
} | ||
continue; | ||
} | ||
$fieldNames[] = $this->fieldTranslator->translate($selectionNode->name->value); | ||
} | ||
} | ||
|
||
return $fieldNames; | ||
} | ||
} |
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
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
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__); |
Oops, something went wrong.