Skip to content

Commit 8769d00

Browse files
feat: add plugin for guest compatibility
1 parent dd16f6f commit 8769d00

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

Plugin/CartPlugin.php

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
namespace Alma\GraphQL\Plugin;
3+
4+
use Alma\MonthlyPayments\Helpers\Logger;
5+
use Magento\Framework\GraphQl\Config\Element\Field;
6+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
7+
use Magento\QuoteGraphQl\Model\Resolver\Cart;
8+
use Alma\GraphQL\Helpers\QuoteHelper;
9+
use \Magento\Framework\GraphQl\Query\ResolverInterface;
10+
11+
class CartPlugin
12+
{
13+
/**
14+
* @var Logger
15+
*/
16+
private $logger;
17+
/**
18+
* @var QuoteHelper
19+
*/
20+
private $quoteHelper;
21+
22+
/**
23+
* @param Logger $logger
24+
* @param QuoteHelper $quoteHelper
25+
*/
26+
public function __construct(
27+
Logger $logger,
28+
QuoteHelper $quoteHelper
29+
)
30+
{
31+
$this->logger = $logger;
32+
$this->quoteHelper = $quoteHelper;
33+
34+
}
35+
36+
/**
37+
* @param Cart $cart
38+
* @param $result
39+
* @param Field $field
40+
* @param $context
41+
* @param ResolveInfo $info
42+
* @param array|null $value
43+
* @param array|null $args
44+
* @return mixed
45+
*/
46+
public function afterResolve(
47+
ResolverInterface $cart,
48+
$result,
49+
Field $field,
50+
$context,
51+
ResolveInfo $info,
52+
array $value = null,
53+
array $args = null
54+
)
55+
{
56+
$cart = $result['model'];
57+
$cartId = (int) $cart->getId();
58+
$this->quoteHelper->setEligibilityQuoteId($cartId);
59+
return $result;
60+
}
61+
}

etc/graphql/di.xml

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
2+
<type name="Magento\QuoteGraphQl\Model\Resolver\Cart">
3+
<plugin name="addQuotePlugin" type="Alma\GraphQL\Plugin\CartPlugin"/>
4+
</type>
25
<type name="Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderPool">
36
<arguments>
47
<argument name="dataProviders" xsi:type="array">

0 commit comments

Comments
 (0)