Skip to content

Commit

Permalink
GraphQl-309: [Checkout] Checkout Agreements
Browse files Browse the repository at this point in the history
  • Loading branch information
naydav committed May 2, 2019
1 parent cc5e217 commit c94a655
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,48 @@

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;
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 CheckoutAgreementsDataProvider
* @var CollectionFactory
*/
private $checkoutAgreementsDataProvider;
private $agreementCollectionFactory;

/**
* @param CheckoutAgreementsDataProvider $checkoutAgreementsDataProvider
* @var StoreManagerInterface
*/
private $storeManager;

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

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

/**
Expand All @@ -41,8 +61,26 @@ public function resolve(
array $value = null,
array $args = null
) {
$checkoutAgreementsData = $this->checkoutAgreementsDataProvider->getData();
if (!$this->scopeConfig->isSetFlag('checkout/options/enable_agreements', ScopeInterface::SCOPE_STORE)) {
return [];
}

$agreementsCollection = $this->agreementCollectionFactory->create();
$agreementsCollection->addStoreFilter($this->storeManager->getStore()->getId());
$agreementsCollection->addFieldToFilter('is_active', 1);

return $checkoutAgreementsData;
$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(),
];
}
return $checkoutAgreementData;
}
}

This file was deleted.

3 changes: 1 addition & 2 deletions app/code/Magento/CheckoutAgreementsGraphQl/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"magento/module-checkout-agreements": "*"
},
"suggest": {
"magento/module-graph-ql": "*",
"magento/module-store-graph-ql": "*"
"magento/module-graph-ql": "*"
},
"license": [
"OSL-3.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
declare(strict_types=1);

namespace Magento\GraphQl\CheckoutAgreements\Api;
namespace Magento\GraphQl\CheckoutAgreements;

use Magento\CheckoutAgreements\Api\Data\AgreementInterface;
use Magento\CheckoutAgreements\Model\Agreement as AgreementModel;
Expand All @@ -20,8 +20,14 @@
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\GraphQlAbstract;

class CheckoutAgreementsListTest extends GraphQlAbstract
/**
* Get checkout agreements test
*/
class GetCheckoutAgreementsTest extends GraphQlAbstract
{
/**
* @var string
*/
private $agreementsXmlConfigPath = 'checkout/options/enable_agreements';

/**
Expand Down Expand Up @@ -55,14 +61,14 @@ public function testGetActiveAgreement()

$response = $this->graphQlQuery($query);

$this->assertArrayHasKey('checkoutAgreements', $response);
self::assertArrayHasKey('checkoutAgreements', $response);
$agreements = $response['checkoutAgreements'];
$this->assertCount(1, $agreements);
$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']);
self::assertCount(1, $agreements);
self::assertEquals('Checkout Agreement (active)', $agreements[0]['name']);
self::assertEquals('Checkout agreement content: <b>HTML</b>', $agreements[0]['content']);
self::assertEquals('200px', $agreements[0]['content_height']);
self::assertEquals('Checkout agreement checkbox text.', $agreements[0]['checkbox_text']);
self::assertEquals(true, $agreements[0]['is_html']);
}

/**
Expand All @@ -81,14 +87,14 @@ public function testGetActiveAgreementOnSecondStore()
$headerMap['Store'] = $secondStoreCode;
$response = $this->graphQlQuery($query, [], '', $headerMap);

$this->assertArrayHasKey('checkoutAgreements', $response);
self::assertArrayHasKey('checkoutAgreements', $response);
$agreements = $response['checkoutAgreements'];
$this->assertCount(1, $agreements);
$this->assertEquals($agreementsName, $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']);
self::assertCount(1, $agreements);
self::assertEquals($agreementsName, $agreements[0]['name']);
self::assertEquals('Checkout agreement content: <b>HTML</b>', $agreements[0]['content']);
self::assertEquals('200px', $agreements[0]['content_height']);
self::assertEquals('Checkout agreement checkbox text.', $agreements[0]['checkbox_text']);
self::assertEquals(true, $agreements[0]['is_html']);
}

/**
Expand All @@ -106,9 +112,9 @@ public function testGetActiveAgreementFromSecondStoreOnDefaultStore()

$response = $this->graphQlQuery($query);

$this->assertArrayHasKey('checkoutAgreements', $response);
self::assertArrayHasKey('checkoutAgreements', $response);
$agreements = $response['checkoutAgreements'];
$this->assertCount(0, $agreements);
self::assertCount(0, $agreements);
}

public function testGetAgreementNotSet()
Expand All @@ -117,9 +123,9 @@ public function testGetAgreementNotSet()

$response = $this->graphQlQuery($query);

$this->assertArrayHasKey('checkoutAgreements', $response);
self::assertArrayHasKey('checkoutAgreements', $response);
$agreements = $response['checkoutAgreements'];
$this->assertCount(0, $agreements);
self::assertCount(0, $agreements);
}

/**
Expand All @@ -133,9 +139,9 @@ public function testDisabledAgreements()

$response = $this->graphQlQuery($query);

$this->assertArrayHasKey('checkoutAgreements', $response);
self::assertArrayHasKey('checkoutAgreements', $response);
$agreements = $response['checkoutAgreements'];
$this->assertCount(0, $agreements);
self::assertCount(0, $agreements);
}

/**
Expand Down

0 comments on commit c94a655

Please sign in to comment.