Skip to content

Commit 59a2120

Browse files
committed
Merge branch 'ACP2E-2470-2' of https://github.com/adobe-commerce-tier-4/magento2ce into 04-29-24-Tier4-Bugfix-Delivery
2 parents 1f7a78a + f0b5bdc commit 59a2120

14 files changed

+255
-348
lines changed

app/code/Magento/Persistent/Model/Checkout/GuestPaymentInformationManagementPlugin.php

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,60 +7,43 @@
77
namespace Magento\Persistent\Model\Checkout;
88

99
use Magento\Checkout\Model\GuestPaymentInformationManagement;
10-
use Magento\Checkout\Model\Session;
1110

1211
/**
13-
* Plugin to convert shopping cart from persistent cart to guest cart before order save when customer not logged in
14-
*
1512
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1613
*/
1714
class GuestPaymentInformationManagementPlugin
1815
{
1916
/**
20-
* Persistence Session Helper
21-
*
2217
* @var \Magento\Persistent\Helper\Session
2318
*/
2419
private $persistenceSessionHelper;
2520

2621
/**
27-
* Persistence Data Helper
28-
*
2922
* @var \Magento\Persistent\Helper\Data
3023
*/
3124
private $persistenceDataHelper;
3225

3326
/**
34-
* Customer Session
35-
*
3627
* @var \Magento\Customer\Model\Session
3728
*/
3829
private $customerSession;
3930

4031
/**
41-
* Checkout Session
42-
*
4332
* @var \Magento\Checkout\Model\Session
4433
*/
4534
private $checkoutSession;
4635

4736
/**
48-
* Quote Manager
49-
*
5037
* @var \Magento\Persistent\Model\QuoteManager
5138
*/
5239
private $quoteManager;
5340

5441
/**
55-
* Cart Repository
56-
*
5742
* @var \Magento\Quote\Api\CartRepositoryInterface
5843
*/
5944
private $cartRepository;
6045

6146
/**
62-
* Initialize dependencies
63-
*
6447
* @param \Magento\Persistent\Helper\Data $persistenceDataHelper
6548
* @param \Magento\Persistent\Helper\Session $persistenceSessionHelper
6649
* @param \Magento\Customer\Model\Session $customerSession
@@ -85,7 +68,7 @@ public function __construct(
8568
}
8669

8770
/**
88-
* Convert customer cart to guest cart before order is placed if customer is not logged in
71+
* Update customer email with the provided one
8972
*
9073
* @param GuestPaymentInformationManagement $subject
9174
* @param string $cartId
@@ -107,12 +90,9 @@ public function beforeSavePaymentInformation(
10790
&& $this->persistenceDataHelper->isShoppingCartPersist()
10891
&& $this->quoteManager->isPersistent()
10992
) {
110-
$this->customerSession->setCustomerId(null);
111-
$this->customerSession->setCustomerGroupId(null);
112-
$this->quoteManager->convertCustomerCartToGuest();
11393
$quoteId = $this->checkoutSession->getQuoteId();
11494
$quote = $this->cartRepository->get($quoteId);
115-
$quote->setCustomerEmail($email);
95+
$quote->setCustomerIsGuest(true);
11696
$quote->getAddressesCollection()->walk('setEmail', ['email' => $email]);
11797
$this->cartRepository->save($quote);
11898
}

app/code/Magento/Persistent/Model/Checkout/GuestShippingInformationManagementPlugin.php

Lines changed: 0 additions & 100 deletions
This file was deleted.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/************************************************************************
3+
*
4+
* Copyright 2024 Adobe
5+
* All Rights Reserved.
6+
*
7+
* NOTICE: All information contained herein is, and remains
8+
* the property of Adobe and its suppliers, if any. The intellectual
9+
* and technical concepts contained herein are proprietary to Adobe
10+
* and its suppliers and are protected by all applicable intellectual
11+
* property laws, including trade secret and copyright laws.
12+
* Dissemination of this information or reproduction of this material
13+
* is strictly forbidden unless prior written permission is obtained
14+
* from Adobe.
15+
* **********************************************************************
16+
*/
17+
declare(strict_types=1);
18+
19+
namespace Magento\Persistent\Model\Plugin;
20+
21+
use Magento\Customer\Model\Session as CustomerSession;
22+
use Magento\Persistent\Helper\Session as PersistentSession;
23+
use Magento\Persistent\Model\QuoteManager;
24+
use Magento\Quote\Model\Quote;
25+
use Magento\Quote\Model\QuoteManagement;
26+
27+
/**
28+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
29+
*/
30+
class ConvertCustomerCartToGuest
31+
{
32+
/**
33+
* @param CustomerSession $customerSession
34+
* @param PersistentSession $persistentSession
35+
* @param QuoteManager $quoteManager
36+
*/
37+
public function __construct(
38+
private readonly CustomerSession $customerSession,
39+
private readonly PersistentSession $persistentSession,
40+
private readonly QuoteManager $quoteManager
41+
) {
42+
}
43+
44+
/**
45+
* Convert customer cart to guest cart before order is placed if customer is not logged in
46+
*
47+
* @param QuoteManagement $subject
48+
* @param Quote $quote
49+
* @param array $orderData
50+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
51+
*/
52+
public function beforeSubmit(QuoteManagement $subject, Quote $quote, array $orderData = []): void
53+
{
54+
if ($quote->getIsPersistent() && $quote->getCustomerId() && $quote->getCustomerIsGuest()) {
55+
$this->customerSession->setCustomerId(null);
56+
$this->customerSession->setCustomerGroupId(null);
57+
$this->persistentSession->getSession()->removePersistentCookie();
58+
$this->persistentSession->setSession(null);
59+
$this->quoteManager->convertCustomerCartToGuest($quote);
60+
}
61+
}
62+
}

app/code/Magento/Persistent/Model/QuoteManager.php

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,16 @@
2323
class QuoteManager
2424
{
2525
/**
26-
* Persistent session
27-
*
2826
* @var \Magento\Persistent\Helper\Session
2927
*/
3028
protected $persistentSession;
3129

3230
/**
33-
* Checkout session
34-
*
3531
* @var \Magento\Checkout\Model\Session
3632
*/
3733
protected $checkoutSession;
3834

3935
/**
40-
* Persistent data
41-
*
4236
* @var Data
4337
*/
4438
protected $persistentData;
@@ -163,30 +157,24 @@ private function cleanCustomerData($quote)
163157
* Converts persistent cart tied to logged out customer to a guest cart, retaining customer information required for
164158
* checkout
165159
*
160+
* @param Quote $quote
166161
* @return void
167162
*/
168-
public function convertCustomerCartToGuest()
163+
public function convertCustomerCartToGuest(Quote $quote)
169164
{
170-
$quoteId = $this->checkoutSession->getQuoteId();
171-
/** @var $quote Quote */
172-
$quote = $this->quoteRepository->get($quoteId);
173-
if ($quote && $quote->getId()) {
174-
$this->_setQuotePersistent = false;
175-
$quote->setIsActive(true)
176-
->setCustomerId(null)
177-
->setCustomerEmail(null)
178-
->setCustomerFirstname(null)
179-
->setCustomerLastname(null)
180-
->setIsPersistent(false);
181-
$quote->getAddressesCollection()->walk('setCustomerAddressId', ['customerAddressId' => null]);
182-
$quote->getAddressesCollection()->walk('setCustomerId', ['customerId' => null]);
183-
$quote->getAddressesCollection()->walk('setEmail', ['email' => null]);
184-
$quote->collectTotals();
185-
$quote->getCustomer()->setId(null);
186-
$this->persistentSession->getSession()->removePersistentCookie();
187-
$this->persistentSession->setSession(null);
188-
$this->quoteRepository->save($quote);
189-
}
165+
$this->_setQuotePersistent = false;
166+
$billingAddress = $quote->getBillingAddress();
167+
$quote->setCustomerId(null)
168+
->setCustomerGroupId(GroupInterface::NOT_LOGGED_IN_ID)
169+
->setCustomerEmail($billingAddress->getEmail())
170+
->setCustomerFirstname($billingAddress->getFirstname())
171+
->setCustomerLastname($billingAddress->getLastname())
172+
->setIsPersistent(false);
173+
$quote->getAddressesCollection()->walk('setCustomerAddressId', ['customerAddressId' => null]);
174+
$quote->getAddressesCollection()->walk('setCustomerId', ['customerId' => null]);
175+
$quote->collectTotals();
176+
$quote->getCustomer()->setId(null);
177+
$this->quoteRepository->save($quote);
190178
}
191179

192180
/**

0 commit comments

Comments
 (0)