-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vitaliy Boyko
committed
Feb 11, 2019
1 parent
92118f5
commit fe8cc05
Showing
3 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...ode/Magento/QuoteGraphQl/Model/Cart/PaymentMethod/AvailablePaymentMethodsDataProvider.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,53 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\QuoteGraphQl\Model\Cart\PaymentMethod; | ||
|
||
use Magento\Checkout\Api\PaymentInformationManagementInterface; | ||
use Magento\Quote\Api\Data\CartInterface; | ||
|
||
/** | ||
* Get array of available payment methods. | ||
*/ | ||
class AvailablePaymentMethodsDataProvider | ||
{ | ||
/** | ||
* @var PaymentInformationManagementInterface | ||
*/ | ||
private $informationManagement; | ||
|
||
/** | ||
* AvailablePaymentMethodsDataProvider constructor. | ||
* @param PaymentInformationManagementInterface $informationManagement | ||
*/ | ||
public function __construct(PaymentInformationManagementInterface $informationManagement) | ||
{ | ||
$this->informationManagement = $informationManagement; | ||
} | ||
|
||
/** | ||
* Collect and return information about available payment methods | ||
* | ||
* @param CartInterface $cart | ||
* @return array | ||
*/ | ||
public function getPaymentMethods(CartInterface $cart): array | ||
{ | ||
$paymentInformation = $this->informationManagement->getPaymentInformation($cart->getId()); | ||
$paymentMethods = $paymentInformation->getPaymentMethods(); | ||
|
||
$paymentMethodsNested = []; | ||
foreach ($paymentMethods as $paymentMethod) { | ||
$paymentMethodsNested[] = [ | ||
'title' => $paymentMethod->getTitle(), | ||
'code' => $paymentMethod->getCode() | ||
]; | ||
} | ||
|
||
return $paymentMethodsNested; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
app/code/Magento/QuoteGraphQl/Model/Resolver/AvailablePaymentMethodsResolver.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,48 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\QuoteGraphQl\Model\Resolver; | ||
|
||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use Magento\QuoteGraphQl\Model\Cart\PaymentMethod\AvailablePaymentMethodsDataProvider; | ||
|
||
/** | ||
* Get list of active payment methods resolver. | ||
*/ | ||
class AvailablePaymentMethodsResolver implements ResolverInterface | ||
{ | ||
/** | ||
* @var AvailablePaymentMethodsDataProvider | ||
*/ | ||
private $addressDataProvider; | ||
|
||
/** | ||
* @param AvailablePaymentMethodsDataProvider $addressDataProvider | ||
*/ | ||
public function __construct( | ||
AvailablePaymentMethodsDataProvider $addressDataProvider | ||
) { | ||
$this->addressDataProvider = $addressDataProvider; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) | ||
{ | ||
if (!isset($value['model'])) { | ||
throw new LocalizedException(__('"model" value should be specified')); | ||
} | ||
|
||
$cart = $value['model']; | ||
|
||
return $this->addressDataProvider->getPaymentMethods($cart); | ||
} | ||
} |
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