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 8, 2019
1 parent 6a8edac commit c3040e6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

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;
Expand Down Expand Up @@ -65,9 +67,10 @@ public function resolve(
return [];
}

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

$checkoutAgreementData = [];
/** @var AgreementInterface $checkoutAgreement */
Expand All @@ -79,7 +82,8 @@ public function resolve(
AgreementInterface::CONTENT_HEIGHT => $checkoutAgreement->getContentHeight(),
AgreementInterface::CHECKBOX_TEXT => $checkoutAgreement->getCheckboxText(),
AgreementInterface::IS_HTML => $checkoutAgreement->getIsHtml(),
AgreementInterface::MODE => $checkoutAgreement->getMode(),
AgreementInterface::MODE =>
AgreementModeOptions::MODE_AUTO === $checkoutAgreement->getMode() ? 'AUTO' : 'MANUAL',
];
}
return $checkoutAgreementData;
Expand Down
17 changes: 11 additions & 6 deletions app/code/Magento/CheckoutAgreementsGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ type Query {
}

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")
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 tex")
is_html: Boolean @doc(description: "Is Checkout Agreement content in HTML format")
mode: Int @doc(description: "Is Checkout Agreement content in HTML format")
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
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public function testGetActiveAgreement()
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']);
self::assertEquals(0, $agreements[0]['mode']);
self::assertTrue($agreements[0]['is_html']);
self::assertEquals('AUTO', $agreements[0]['mode']);
}

/**
Expand All @@ -95,8 +95,8 @@ public function testGetActiveAgreementOnSecondStore()
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']);
self::assertEquals(0, $agreements[0]['mode']);
self::assertTrue($agreements[0]['is_html']);
self::assertEquals('AUTO', $agreements[0]['mode']);
}

/**
Expand All @@ -116,7 +116,7 @@ public function testGetActiveAgreementFromSecondStoreOnDefaultStore()

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

public function testGetAgreementNotSet()
Expand All @@ -127,7 +127,7 @@ public function testGetAgreementNotSet()

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

/**
Expand All @@ -143,7 +143,7 @@ public function testDisabledAgreements()

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

/**
Expand Down

0 comments on commit c3040e6

Please sign in to comment.