Skip to content

Commit 4503cb3

Browse files
author
root
committed
Release 2.1.6
1 parent e17578d commit 4503cb3

File tree

13 files changed

+118
-43
lines changed

13 files changed

+118
-43
lines changed

Model/Resolver/RestoreQuote.php

+105-30
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111
namespace PostFinanceCheckout\Payment\Model\Resolver;
1212

13+
use Magento\Authorization\Model\UserContextInterface;
1314
use Magento\Checkout\Model\Session as CheckoutSession;
1415
use Magento\CustomerGraphQl\Model\Customer\GetCustomer;
1516
use Magento\Framework\Event\ManagerInterface;
@@ -79,7 +80,16 @@ class RestoreQuote implements ResolverInterface
7980
*/
8081
private $logger;
8182

82-
83+
/**
84+
* @param Session $customerSession
85+
* @param CheckoutSession $checkoutSession
86+
* @param GetCustomer $getCustomer
87+
* @param CartRepositoryInterface $cartRepository
88+
* @param OrderRepositoryInterface $orderRepository
89+
* @param MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteIdService
90+
* @param ManagerInterface $eventManager
91+
* @param LoggerInterface $logger
92+
*/
8393
public function __construct(Session $customerSession, CheckoutSession $checkoutSession,GetCustomer $getCustomer,
8494
CartRepositoryInterface $cartRepository, OrderRepositoryInterface $orderRepository,
8595
MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteIdService, ManagerInterface $eventManager, LoggerInterface $logger) {
@@ -93,43 +103,39 @@ public function __construct(Session $customerSession, CheckoutSession $checkoutS
93103
$this->logger = $logger;
94104
}
95105

106+
/**
107+
* @inheritDoc
108+
*/
96109
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
97110
{
98-
$customerId = null;
111+
try {
112+
$cartIdMasked = $args['input']['cart_id'];
99113

100-
//only perform validations if the user is anonymous.
101-
if ($this->checkoutSession->getQuote()->getCustomerId() || !$this->customerSession->getCustomer()->getId()) {
102-
/** @var ContextInterface $context */
103-
if (false === $context->getExtensionAttributes()->getIsCustomer()) {
104-
throw new GraphQlAuthorizationException(__('The current customer isn\'t authorized.'));
114+
if ($context->getUserType() === UserContextInterface::USER_TYPE_GUEST) {
115+
return $this->restoreGuestQuote($cartIdMasked);
105116
}
106117

107-
$customer = $this->getCustomer->execute($context);
108-
$customerId = $customer->getId();
109-
110-
if (!empty($this->customerSession) && $customerId !== $this->customerSession->getCustomer()->getId()) {
111-
throw new GraphQlAuthorizationException(__('The current customer isn\'t authorized.'));
118+
if ($context->getUserType() !== UserContextInterface::USER_TYPE_GUEST) {
119+
/** @var ContextInterface $context $customerId */
120+
$customerId = $this->getCustomerIdFromContext($context);
121+
return $this->restoreCustomerQuote($cartIdMasked, $customerId);
112122
}
113-
}
114-
115-
try {
116-
$cartIdMasked = $args['input']['cart_id'];
117-
return $this->restoreQuote($cartIdMasked, $customerId);
123+
return ['result' => 'There is no cart available'];
118124
} catch (NoSuchEntityException|\Exception $e) {
119125
$this->logger->critical($e);
120126
throw new GraphQlNoSuchEntityException(__($e->getMessage()));
121127
}
122128
}
123129

124130
/**
125-
* Restores a client's quote from a cart id
131+
* Restores a customer's quote from a cart id
126132
*
127133
* @param string $cartIdMasked
128134
* @param string $customerId
129135
* @return array
130136
* @throws LocalizedException
131137
*/
132-
private function restoreQuote(string $cartIdMasked, string $customerId)
138+
private function restoreCustomerQuote(string $cartIdMasked, string $customerId)
133139
{
134140
try {
135141
// Convert the masked ID to the real quote ID
@@ -144,19 +150,31 @@ private function restoreQuote(string $cartIdMasked, string $customerId)
144150
$this->guardQuoteBelongsToCurrentCustomer($order, $customerId);
145151
$this->guardQuoteIsStillActive($quote);
146152

147-
//restore a customer's quote
148-
$quote->setIsActive(1)->setReservedOrderId(null);
153+
return $this->restoreQuote($cartIdMasked, $quote, $order);
154+
} catch (NoSuchEntityException|\Exception $e) {
155+
return ['result' => 'KO. ' . $e->getMessage()];
156+
}
157+
}
149158

150-
$this->cartRepository->save($quote);
151-
$this->checkoutSession->replaceQuote($quote)->unsLastRealOrderId();
159+
/**
160+
* Restores a guest's quote from a cart id
161+
*
162+
* @param string $cartIdMasked
163+
* @return array
164+
* @throws LocalizedException
165+
*/
166+
private function restoreGuestQuote(string $cartIdMasked)
167+
{
168+
try {
169+
// Convert the masked ID to the real quote ID
170+
$quoteId = $this->maskedQuoteIdToQuoteIdService->execute($cartIdMasked);
152171

153-
$this->eventManager->dispatch('restore_quote', ['order' => $order, 'quote' => $quote]);
154-
$this->logger->debug("RESTORE-QUOTE-MUTATION::restoreQuote - Quote with id $cartIdMasked was restored");
172+
// Get the quote using the actual ID
173+
/** @var Quote $quote */
174+
$quote = $this->cartRepository->get($quoteId);
175+
$order = $this->getOrderByQuote($quote);
155176

156-
return [
157-
'result' => 'OK',
158-
'cart_id' => $cartIdMasked
159-
];
177+
return $this->restoreQuote($cartIdMasked, $quote, $order);
160178
} catch (NoSuchEntityException|\Exception $e) {
161179
return ['result' => 'KO. ' . $e->getMessage()];
162180
}
@@ -174,7 +192,7 @@ public function getOrderByQuote(Quote $quote)
174192
$orderId = $quote->getReservedOrderId();
175193

176194
if (empty($orderId)) {
177-
throw new \Exception(__('The quote does not have an associated order'));
195+
throw new \Exception(__('The cart does not have an associated order'));
178196
}
179197

180198
return $this->orderRepository->getOrderById($orderId);
@@ -212,4 +230,61 @@ private function guardQuoteIsStillActive(Quote $quote)
212230
throw new \Exception(__('The quote is still active.'));
213231
}
214232
}
233+
234+
/**
235+
* Gets the customer id from the user context
236+
* @param ContextInterface $context
237+
* @param int|null $customerId
238+
* @return int|null
239+
* @throws GraphQlAuthorizationException
240+
* @throws GraphQlNoSuchEntityException
241+
* @throws LocalizedException
242+
* @throws NoSuchEntityException
243+
* @throws \Magento\Framework\GraphQl\Exception\GraphQlAuthenticationException
244+
* @throws \Magento\Framework\GraphQl\Exception\GraphQlInputException
245+
*/
246+
public function getCustomerIdFromContext(ContextInterface $context): mixed
247+
{
248+
$customerId = null;
249+
if ($context->getUserType() === UserContextInterface::USER_TYPE_GUEST) {
250+
return $customerId;
251+
}
252+
253+
//only perform validations if the user is anonymous.
254+
if ($this->checkoutSession->getQuote()->getCustomerId() || !$this->customerSession->getCustomer()->getId()) {
255+
/** @var ContextInterface $context */
256+
if (false === $context->getExtensionAttributes()->getIsCustomer()) {
257+
throw new GraphQlAuthorizationException(__('The current customer isn\'t authorized.'));
258+
}
259+
260+
$customer = $this->getCustomer->execute($context);
261+
$customerId = $customer->getId();
262+
263+
if (!empty($this->customerSession) && $customerId !== $this->customerSession->getCustomer()->getId()) {
264+
throw new GraphQlAuthorizationException(__('The current customer isn\'t authorized.'));
265+
}
266+
}
267+
return $customerId;
268+
}
269+
270+
/**
271+
* Restore a customer or guest's quote
272+
* @param Quote $quote
273+
* @param OrderInterface|null $order
274+
* @return array<mixed>
275+
*/
276+
public function restoreQuote(string $cartIdMasked, Quote $quote, OrderInterface $order = null)
277+
{
278+
$quote->setIsActive(1)->setReservedOrderId(null);
279+
280+
$this->cartRepository->save($quote);
281+
$this->checkoutSession->replaceQuote($quote)->unsLastRealOrderId();
282+
$this->eventManager->dispatch('restore_quote', ['order' => $order, 'quote' => $quote]);
283+
$this->logger->debug("RESTORE-QUOTE-MUTATION::restoreQuote - Quote with id $cartIdMasked was restored");
284+
285+
return [
286+
'result' => 'OK',
287+
'cart_id' => $cartIdMasked
288+
];
289+
}
215290
}

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This repository contains the Magento 2 extension that enables to process payment
1212

1313
## Documentation
1414

15-
* [Documentation](https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2/2.1.5/docs/en/documentation.html)
15+
* [Documentation](https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2/2.1.6/docs/en/documentation.html)
1616

1717

1818
## Support
@@ -30,4 +30,4 @@ We do provide special integrations for the following one step checkouts:
3030

3131
## License
3232

33-
Please see the [license file](https://github.com/pfpayments/magento-2/blob/2.1.5/LICENSE) for more information.
33+
Please see the [license file](https://github.com/pfpayments/magento-2/blob/2.1.6/LICENSE) for more information.

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717
],
1818
"type" : "magento2-module",
19-
"version" : "2.1.5",
19+
"version" : "2.1.6",
2020
"require" : {
2121
"php" : "~7.1.3||~7.2.0||~7.3.0||~7.4.0||~8.0||~8.1",
2222
"magento/framework" : "^102.0.0||^103.0.0",

docs/en/documentation.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ <h2>Documentation</h2> </div>
2222
</a>
2323
</li>
2424
<li>
25-
<a href="https://github.com/pfpayments/magento-2/releases/tag/2.1.5/">
25+
<a href="https://github.com/pfpayments/magento-2/releases/tag/2.1.6/">
2626
Source
2727
</a>
2828
</li>

etc/adminhtml/system.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<resource>PostFinanceCheckout_Payment::config</resource>
1919
<group id="information" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
2020
<label>Information</label>
21-
<comment><![CDATA[If you need help setting up the PostFinance Checkout extension, check out the <a href="https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2/2.1.5/docs/en/documentation.html" target="_blank">documentation</a>.]]></comment>
21+
<comment><![CDATA[If you need help setting up the PostFinance Checkout extension, check out the <a href="https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2/2.1.6/docs/en/documentation.html" target="_blank">documentation</a>.]]></comment>
2222
<field id="version" translate="label" type="label" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
2323
<label>Module Version</label>
2424
</field>

etc/config.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<default>
1515
<postfinancecheckout_payment>
1616
<information>
17-
<version>2.1.5</version>
17+
<version>2.1.6</version>
1818
<sdk_version>3.2.0</sdk_version>
1919
</information>
2020
<general>

etc/module.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
-->
1313
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
14-
<module name="PostFinanceCheckout_Payment" setup_version="2.1.5">
14+
<module name="PostFinanceCheckout_Payment" setup_version="2.1.6">
1515
<sequence>
1616
<module name="Magento_Sales"/>
1717
<module name="Magento_Payment"/>

i18n/de_DE.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"Gift Wrap","Geschenkverpackung"
5151
"Hold Delivery","Lieferung halten"
5252
"ID required","ID erforderlich"
53-
"If you need help setting up the PostFinance Checkout extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2/2.1.5/docs/en/documentation.html"" target=""_blank"">documentation</a>.","Falls Sie Hilfe benötigen beim Einrichten der PostFinance Checkout-Erweiterung, sehen Sie sich die <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2/2.1.5/docs/en/documentation.html"" target=""_blank"">Dokumentation</a> an."
53+
"If you need help setting up the PostFinance Checkout extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2/2.1.6/docs/en/documentation.html"" target=""_blank"">documentation</a>.","Falls Sie Hilfe benötigen beim Einrichten der PostFinance Checkout-Erweiterung, sehen Sie sich die <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2/2.1.6/docs/en/documentation.html"" target=""_blank"">Dokumentation</a> an."
5454
"Inactive","Inaktiv"
5555
"Information","Informationen"
5656
"Invoice","Rechnung"

i18n/en_US.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"Gift Wrap","Gift Wrap"
5151
"Hold Delivery","Hold Delivery"
5252
"ID required","ID required"
53-
"If you need help setting up the PostFinance Checkout extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2/2.1.5/docs/en/documentation.html"" target=""_blank"">documentation</a>.","If you need help setting up the PostFinance Checkout extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2/2.1.5/docs/en/documentation.html"" target=""_blank"">documentation</a>."
53+
"If you need help setting up the PostFinance Checkout extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2/2.1.6/docs/en/documentation.html"" target=""_blank"">documentation</a>.","If you need help setting up the PostFinance Checkout extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2/2.1.6/docs/en/documentation.html"" target=""_blank"">documentation</a>."
5454
"Inactive","Inactive"
5555
"Information","Information"
5656
"Invoice","Invoice"

i18n/fr_CH.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"Gift Wrap","Papier cadeau"
5151
"Hold Delivery","Suspendre la livraison"
5252
"ID required","Pièce d'identité requise"
53-
"If you need help setting up the wallee extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2/2.1.5/docs/en/documentation.html"" target=""_blank"">documentation</a>.","Si vous avez besoin d'aide pour configurer l'extension wallee, consultez la <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2/2.1.5/docs/en/documentation.html"" target=""_blank"">documentation</a> an."
53+
"If you need help setting up the wallee extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2/2.1.6/docs/en/documentation.html"" target=""_blank"">documentation</a>.","Si vous avez besoin d'aide pour configurer l'extension wallee, consultez la <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2/2.1.6/docs/en/documentation.html"" target=""_blank"">documentation</a> an."
5454
"Inactive","Inactif"
5555
"Information","Information"
5656
"Invoice","Facture"

i18n/fr_FR.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"Gift Wrap","Papier cadeau"
5151
"Hold Delivery","Suspendre la livraison"
5252
"ID required","Pièce d'identité requise"
53-
"If you need help setting up the wallee extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2/2.1.5/docs/en/documentation.html"" target=""_blank"">documentation</a>.","Si vous avez besoin d'aide pour configurer l'extension wallee, consultez la <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2/2.1.5/docs/en/documentation.html"" target=""_blank"">documentation</a> an."
53+
"If you need help setting up the wallee extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2/2.1.6/docs/en/documentation.html"" target=""_blank"">documentation</a>.","Si vous avez besoin d'aide pour configurer l'extension wallee, consultez la <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2/2.1.6/docs/en/documentation.html"" target=""_blank"">documentation</a> an."
5454
"Inactive","Inactif"
5555
"Information","Information"
5656
"Invoice","Facture"

i18n/it_CH.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"Gift Wrap","Confezione regalo"
5151
"Hold Delivery","Sospendi la consegna"
5252
"ID required","ID richiesto"
53-
"If you need help setting up the wallee extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2/2.1.5/docs/en/documentation.html"" target=""_blank"">documentation</a>.","Se hai bisogno di aiuto per configurare l'estensione wallee, consulta la <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2/2.1.5/docs/en/documentation.html"" target=""_blank"">documentazione</a> an."
53+
"If you need help setting up the wallee extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2/2.1.6/docs/en/documentation.html"" target=""_blank"">documentation</a>.","Se hai bisogno di aiuto per configurare l'estensione wallee, consulta la <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2/2.1.6/docs/en/documentation.html"" target=""_blank"">documentazione</a> an."
5454
"Inactive","Inattivo"
5555
"Information","Informazione"
5656
"Invoice","Fattura"

i18n/it_IT.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"Gift Wrap","Confezione regalo"
5151
"Hold Delivery","Sospendi la consegna"
5252
"ID required","ID richiesto"
53-
"If you need help setting up the wallee extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2/2.1.5/docs/en/documentation.html"" target=""_blank"">documentation</a>.","Se hai bisogno di aiuto per configurare l'estensione wallee, consulta la <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2/2.1.5/docs/en/documentation.html"" target=""_blank"">documentazione</a> an."
53+
"If you need help setting up the wallee extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2/2.1.6/docs/en/documentation.html"" target=""_blank"">documentation</a>.","Se hai bisogno di aiuto per configurare l'estensione wallee, consulta la <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2/2.1.6/docs/en/documentation.html"" target=""_blank"">documentazione</a> an."
5454
"Inactive","Inattivo"
5555
"Information","Informazione"
5656
"Invoice","Fattura"

0 commit comments

Comments
 (0)