Skip to content

Commit 73e25d4

Browse files
committed
Merge branch 'ACP2E-1339' of https://github.com/magento-l3/magento2ce into PR01262023
2 parents dffeadd + 3c293b5 commit 73e25d4

8 files changed

+466
-3
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Checkout\Plugin\Api;
9+
10+
use Magento\Checkout\Helper\Data as CheckoutHelper;
11+
use Magento\Framework\Exception\CouldNotSaveException;
12+
use Magento\Quote\Api\CartRepositoryInterface;
13+
use Magento\Quote\Api\Data\AddressInterface;
14+
use Magento\Quote\Api\GuestBillingAddressManagementInterface;
15+
use Magento\Quote\Model\QuoteIdMask;
16+
use Magento\Quote\Model\QuoteIdMaskFactory;
17+
18+
class VerifyIsGuestCheckoutEnabledBeforeAssignBillingAddress
19+
{
20+
/**
21+
* @var CheckoutHelper
22+
*/
23+
private CheckoutHelper $checkoutHelper;
24+
25+
/**
26+
* @var QuoteIdMaskFactory
27+
*/
28+
private QuoteIdMaskFactory $quoteIdMaskFactory;
29+
30+
/**
31+
* @var CartRepositoryInterface
32+
*/
33+
private CartRepositoryInterface $cartRepository;
34+
35+
/**
36+
* @param CheckoutHelper $checkoutHelper
37+
* @param QuoteIdMaskFactory $quoteIdMaskFactory
38+
* @param CartRepositoryInterface $cartRepository
39+
*/
40+
public function __construct(
41+
CheckoutHelper $checkoutHelper,
42+
QuoteIdMaskFactory $quoteIdMaskFactory,
43+
CartRepositoryInterface $cartRepository
44+
) {
45+
$this->checkoutHelper = $checkoutHelper;
46+
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
47+
$this->cartRepository = $cartRepository;
48+
}
49+
50+
/**
51+
* Checks whether guest checkout is enabled before assigning billing address
52+
*
53+
* @param GuestBillingAddressManagementInterface $subject
54+
* @param string $cartId
55+
* @param AddressInterface $address
56+
* @param bool $useForShipping
57+
* @return void
58+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
59+
*/
60+
public function beforeAssign(
61+
GuestBillingAddressManagementInterface $subject,
62+
$cartId,
63+
AddressInterface $address,
64+
$useForShipping = false
65+
): void {
66+
/** @var $quoteIdMask QuoteIdMask */
67+
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
68+
$quote = $this->cartRepository->get($quoteIdMask->getQuoteId());
69+
if (!$this->checkoutHelper->isAllowedGuestCheckout($quote)) {
70+
throw new CouldNotSaveException(__('Sorry, guest checkout is not available.'));
71+
}
72+
}
73+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Checkout\Plugin\Api;
9+
10+
use Magento\Checkout\Helper\Data as CheckoutHelper;
11+
use Magento\Framework\Exception\CouldNotSaveException;
12+
use Magento\Quote\Api\CartRepositoryInterface;
13+
use Magento\Quote\Api\Data\PaymentInterface;
14+
use Magento\Quote\Api\GuestCartManagementInterface;
15+
use Magento\Quote\Model\QuoteIdMask;
16+
use Magento\Quote\Model\QuoteIdMaskFactory;
17+
18+
class VerifyIsGuestCheckoutEnabledBeforePlaceOrder
19+
{
20+
/**
21+
* @var CheckoutHelper
22+
*/
23+
private CheckoutHelper $checkoutHelper;
24+
25+
/**
26+
* @var QuoteIdMaskFactory
27+
*/
28+
private QuoteIdMaskFactory $quoteIdMaskFactory;
29+
30+
/**
31+
* @var CartRepositoryInterface
32+
*/
33+
private CartRepositoryInterface $cartRepository;
34+
35+
/**
36+
* @param CheckoutHelper $checkoutHelper
37+
* @param QuoteIdMaskFactory $quoteIdMaskFactory
38+
* @param CartRepositoryInterface $cartRepository
39+
*/
40+
public function __construct(
41+
CheckoutHelper $checkoutHelper,
42+
QuoteIdMaskFactory $quoteIdMaskFactory,
43+
CartRepositoryInterface $cartRepository
44+
) {
45+
$this->checkoutHelper = $checkoutHelper;
46+
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
47+
$this->cartRepository = $cartRepository;
48+
}
49+
50+
/**
51+
* Checks whether guest checkout is enabled before placing order
52+
*
53+
* @param GuestCartManagementInterface $subject
54+
* @param string $cartId
55+
* @param PaymentInterface|null $paymentMethod
56+
* @return void
57+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
58+
*/
59+
public function beforePlaceOrder(
60+
GuestCartManagementInterface $subject,
61+
$cartId,
62+
PaymentInterface $paymentMethod = null
63+
): void {
64+
/** @var $quoteIdMask QuoteIdMask */
65+
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
66+
$quote = $this->cartRepository->get($quoteIdMask->getQuoteId());
67+
if (!$this->checkoutHelper->isAllowedGuestCheckout($quote)) {
68+
throw new CouldNotSaveException(__('Sorry, guest checkout is not available.'));
69+
}
70+
}
71+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Checkout\Plugin\Api;
9+
10+
use Magento\Checkout\Api\GuestPaymentInformationManagementInterface;
11+
use Magento\Checkout\Helper\Data as CheckoutHelper;
12+
use Magento\Framework\Exception\CouldNotSaveException;
13+
use Magento\Quote\Api\CartRepositoryInterface;
14+
use Magento\Quote\Api\Data\AddressInterface;
15+
use Magento\Quote\Api\Data\PaymentInterface;
16+
use Magento\Quote\Model\QuoteIdMask;
17+
use Magento\Quote\Model\QuoteIdMaskFactory;
18+
19+
class VerifyIsGuestCheckoutEnabledBeforeSavePaymentInformation
20+
{
21+
/**
22+
* @var CheckoutHelper
23+
*/
24+
private CheckoutHelper $checkoutHelper;
25+
26+
/**
27+
* @var QuoteIdMaskFactory
28+
*/
29+
private QuoteIdMaskFactory $quoteIdMaskFactory;
30+
31+
/**
32+
* @var CartRepositoryInterface
33+
*/
34+
private CartRepositoryInterface $cartRepository;
35+
36+
/**
37+
* @param CheckoutHelper $checkoutHelper
38+
* @param QuoteIdMaskFactory $quoteIdMaskFactory
39+
* @param CartRepositoryInterface $cartRepository
40+
*/
41+
public function __construct(
42+
CheckoutHelper $checkoutHelper,
43+
QuoteIdMaskFactory $quoteIdMaskFactory,
44+
CartRepositoryInterface $cartRepository
45+
) {
46+
$this->checkoutHelper = $checkoutHelper;
47+
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
48+
$this->cartRepository = $cartRepository;
49+
}
50+
51+
/**
52+
* Checks whether guest checkout is enabled before saving payment information
53+
*
54+
* @param GuestPaymentInformationManagementInterface $subject
55+
* @param string $cartId
56+
* @param string $email
57+
* @param PaymentInterface $paymentMethod
58+
* @param AddressInterface|null $billingAddress
59+
* @return void
60+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
61+
*/
62+
public function beforeSavePaymentInformation(
63+
GuestPaymentInformationManagementInterface $subject,
64+
$cartId,
65+
$email,
66+
PaymentInterface $paymentMethod,
67+
AddressInterface $billingAddress = null
68+
): void {
69+
/** @var $quoteIdMask QuoteIdMask */
70+
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
71+
$quote = $this->cartRepository->get($quoteIdMask->getQuoteId());
72+
if (!$this->checkoutHelper->isAllowedGuestCheckout($quote)) {
73+
throw new CouldNotSaveException(__('Sorry, guest checkout is not available.'));
74+
}
75+
}
76+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Checkout\Plugin\Api;
9+
10+
use Magento\Checkout\Api\Data\ShippingInformationInterface;
11+
use Magento\Checkout\Api\GuestShippingInformationManagementInterface;
12+
use Magento\Checkout\Helper\Data as CheckoutHelper;
13+
use Magento\Framework\Exception\CouldNotSaveException;
14+
use Magento\Quote\Api\CartRepositoryInterface;
15+
use Magento\Quote\Model\QuoteIdMask;
16+
use Magento\Quote\Model\QuoteIdMaskFactory;
17+
18+
class VerifyIsGuestCheckoutEnabledBeforeSaveShippingInformation
19+
{
20+
/**
21+
* @var CheckoutHelper
22+
*/
23+
private CheckoutHelper $checkoutHelper;
24+
25+
/**
26+
* @var QuoteIdMaskFactory
27+
*/
28+
private QuoteIdMaskFactory $quoteIdMaskFactory;
29+
30+
/**
31+
* @var CartRepositoryInterface
32+
*/
33+
private CartRepositoryInterface $cartRepository;
34+
35+
/**
36+
* @param CheckoutHelper $checkoutHelper
37+
* @param QuoteIdMaskFactory $quoteIdMaskFactory
38+
* @param CartRepositoryInterface $cartRepository
39+
*/
40+
public function __construct(
41+
CheckoutHelper $checkoutHelper,
42+
QuoteIdMaskFactory $quoteIdMaskFactory,
43+
CartRepositoryInterface $cartRepository
44+
) {
45+
$this->checkoutHelper = $checkoutHelper;
46+
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
47+
$this->cartRepository = $cartRepository;
48+
}
49+
50+
/**
51+
* Checks whether guest checkout is enabled before saving shipping information
52+
*
53+
* @param GuestShippingInformationManagementInterface $subject
54+
* @param string $cartId
55+
* @param ShippingInformationInterface $addressInformation
56+
* @return void
57+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
58+
*/
59+
public function beforeSaveAddressInformation(
60+
GuestShippingInformationManagementInterface $subject,
61+
$cartId,
62+
ShippingInformationInterface $addressInformation
63+
): void {
64+
/** @var $quoteIdMask QuoteIdMask */
65+
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
66+
$quote = $this->cartRepository->get($quoteIdMask->getQuoteId());
67+
if (!$this->checkoutHelper->isAllowedGuestCheckout($quote)) {
68+
throw new CouldNotSaveException(__('Sorry, guest checkout is not available.'));
69+
}
70+
}
71+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Checkout\Plugin\Api;
9+
10+
use Magento\Checkout\Helper\Data as CheckoutHelper;
11+
use Magento\Framework\Exception\CouldNotSaveException;
12+
use Magento\Quote\Api\CartRepositoryInterface;
13+
use Magento\Quote\Api\Data\PaymentInterface;
14+
use Magento\Quote\Api\GuestPaymentMethodManagementInterface;
15+
use Magento\Quote\Model\QuoteIdMask;
16+
use Magento\Quote\Model\QuoteIdMaskFactory;
17+
18+
class VerifyIsGuestCheckoutEnabledBeforeSetPaymentMethod
19+
{
20+
/**
21+
* @var CheckoutHelper
22+
*/
23+
private CheckoutHelper $checkoutHelper;
24+
25+
/**
26+
* @var QuoteIdMaskFactory
27+
*/
28+
private QuoteIdMaskFactory $quoteIdMaskFactory;
29+
30+
/**
31+
* @var CartRepositoryInterface
32+
*/
33+
private CartRepositoryInterface $cartRepository;
34+
35+
/**
36+
* @param CheckoutHelper $checkoutHelper
37+
* @param QuoteIdMaskFactory $quoteIdMaskFactory
38+
* @param CartRepositoryInterface $cartRepository
39+
*/
40+
public function __construct(
41+
CheckoutHelper $checkoutHelper,
42+
QuoteIdMaskFactory $quoteIdMaskFactory,
43+
CartRepositoryInterface $cartRepository
44+
) {
45+
$this->checkoutHelper = $checkoutHelper;
46+
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
47+
$this->cartRepository = $cartRepository;
48+
}
49+
50+
/**
51+
* Checks whether guest checkout is enabled before setting payment method
52+
*
53+
* @param GuestPaymentMethodManagementInterface $subject
54+
* @param string $cartId
55+
* @param PaymentInterface $method
56+
* @return void
57+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
58+
*/
59+
public function beforeSet(
60+
GuestPaymentMethodManagementInterface $subject,
61+
$cartId,
62+
PaymentInterface $method
63+
): void {
64+
/** @var $quoteIdMask QuoteIdMask */
65+
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
66+
$quote = $this->cartRepository->get($quoteIdMask->getQuoteId());
67+
if (!$this->checkoutHelper->isAllowedGuestCheckout($quote)) {
68+
throw new CouldNotSaveException(__('Sorry, guest checkout is not available.'));
69+
}
70+
}
71+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<type name="Magento\Checkout\Api\GuestPaymentInformationManagementInterface">
10+
<plugin name="verify_is_guest_checkout_enabled" type="Magento\Checkout\Plugin\Api\VerifyIsGuestCheckoutEnabledBeforeSavePaymentInformation"/>
11+
</type>
12+
<type name="Magento\Checkout\Api\GuestShippingInformationManagementInterface">
13+
<plugin name="verify_is_guest_checkout_enabled" type="Magento\Checkout\Plugin\Api\VerifyIsGuestCheckoutEnabledBeforeSaveShippingInformation"/>
14+
</type>
15+
<type name="Magento\Quote\Api\GuestCartManagementInterface">
16+
<plugin name="verify_is_guest_checkout_enabled" type="Magento\Checkout\Plugin\Api\VerifyIsGuestCheckoutEnabledBeforePlaceOrder"/>
17+
</type>
18+
<type name="Magento\Quote\Api\GuestPaymentMethodManagementInterface">
19+
<plugin name="verify_is_guest_checkout_enabled" type="Magento\Checkout\Plugin\Api\VerifyIsGuestCheckoutEnabledBeforeSetPaymentMethod"/>
20+
</type>
21+
<type name="Magento\Quote\Api\GuestBillingAddressManagementInterface">
22+
<plugin name="verify_is_guest_checkout_enabled" type="Magento\Checkout\Plugin\Api\VerifyIsGuestCheckoutEnabledBeforeAssignBillingAddress"/>
23+
</type>
24+
</config>

0 commit comments

Comments
 (0)