-
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.
Merge pull request #9 from donmo-roundup/integration-improvements
Integration improvements
- Loading branch information
Showing
9 changed files
with
231 additions
and
72 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Donmo\Roundup\Model\Resolver; | ||
|
||
use Donmo\Roundup\Logger\Logger; | ||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use Magento\Quote\Model\MaskedQuoteIdToQuoteIdInterface; | ||
|
||
|
||
use Magento\Quote\Api\CartRepositoryInterface; | ||
|
||
class AddDonationToQuote implements ResolverInterface | ||
{ | ||
private Logger $logger; | ||
private MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId; | ||
private CartRepositoryInterface $cartRepository; | ||
|
||
public function __construct( | ||
Logger $logger, | ||
CartRepositoryInterface $cartRepository, | ||
MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId | ||
) { | ||
$this->logger = $logger; | ||
$this->cartRepository = $cartRepository; | ||
$this->maskedQuoteIdToQuoteId = $maskedQuoteIdToQuoteId; | ||
} | ||
|
||
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) | ||
{ | ||
$donationAmount = $args['donationAmount']; | ||
$maskedId = $args['cartId']; | ||
|
||
$quoteId = $this->maskedQuoteIdToQuoteId->execute($maskedId); | ||
|
||
$quote = $this->cartRepository->get($quoteId); | ||
|
||
$quote->setDonmodonation($donationAmount)->collectTotals(); | ||
$this->cartRepository->save($quote); | ||
|
||
return ['message' => 'success']; | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
namespace Donmo\Roundup\Model\Resolver; | ||
|
||
use Donmo\Roundup\Logger\Logger; | ||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use Magento\Quote\Model\Quote; | ||
|
||
class DonationResolver implements ResolverInterface | ||
{ | ||
private Logger $logger; | ||
|
||
public function __construct(Logger $logger) | ||
{ | ||
$this->logger = $logger; | ||
} | ||
|
||
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) | ||
{ | ||
/** @var Quote $quote */ | ||
$quote = $value['model']; | ||
|
||
$donmoDonation = $quote->getDonmodonation(); | ||
|
||
$currency = $quote->getQuoteCurrencyCode(); | ||
|
||
return ['value' => $donmoDonation, 'currency' => $currency]; | ||
} | ||
} |
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,44 @@ | ||
<?php | ||
|
||
namespace Donmo\Roundup\Model\Resolver; | ||
|
||
use Donmo\Roundup\Logger\Logger; | ||
|
||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use Magento\Quote\Api\CartRepositoryInterface; | ||
use Magento\Quote\Model\MaskedQuoteIdToQuoteIdInterface; | ||
|
||
class RemoveDonationFromQuote implements ResolverInterface | ||
{ | ||
private Logger $logger; | ||
private CartRepositoryInterface $cartRepository; | ||
private MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId; | ||
|
||
|
||
public function __construct( | ||
Logger $logger, | ||
CartRepositoryInterface $cartRepository, | ||
MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId | ||
) { | ||
$this->logger = $logger; | ||
$this->cartRepository = $cartRepository; | ||
$this->maskedQuoteIdToQuoteId = $maskedQuoteIdToQuoteId; | ||
} | ||
|
||
|
||
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) | ||
{ | ||
$maskedId = $args['cartId']; | ||
|
||
$quoteId = $this->maskedQuoteIdToQuoteId->execute($maskedId); | ||
|
||
$quote = $this->cartRepository->get($quoteId); | ||
|
||
$quote->setDonmodonation(0)->collectTotals(); | ||
$this->cartRepository->save($quote); | ||
|
||
return ['message' => 'success']; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
type CartPrices @doc(description: "Contains details about the final price of items in the cart, including discount and tax information.") { | ||
donmo_donation: Money | ||
@doc(description: "Donmo Roundup donation") | ||
@resolver(class: "\\Donmo\\Roundup\\Model\\Resolver\\DonationResolver") | ||
} | ||
|
||
type Mutation { | ||
addDonationToQuote(cartId: String!, donationAmount: Float!): DonmoDonationOutput @resolver(class: "\\Donmo\\Roundup\\Model\\Resolver\\AddDonationToQuote") @doc(description:"Add Donmo donation to quote") | ||
|
||
removeDonationFromQuote(cartId: String!): DonmoDonationOutput @resolver(class: "\\Donmo\\Roundup\\Model\\Resolver\\RemoveDonationFromQuote") @doc(description:"Remove Donmo donation from quote") | ||
} | ||
|
||
type DonmoDonationOutput { | ||
message: String @doc(description: "Result message") | ||
} | ||
|
Oops, something went wrong.