1
1
<?php
2
2
/**
3
- * Copyright 2025 Adobe
3
+ * Copyright 2022 Adobe
4
4
* All Rights Reserved.
5
5
*/
6
6
declare (strict_types=1 );
@@ -74,7 +74,6 @@ public function __construct(
74
74
/**
75
75
* Cleans shipping addresses and item assignments after MultiShipping flow
76
76
*
77
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
78
77
* @param Cart|UpdateItemQty $subject
79
78
* @param RequestInterface $request
80
79
* @throws LocalizedException
@@ -87,24 +86,7 @@ public function clearAddressItem($subject, $request)
87
86
$ isMultipleShippingAddressesPresent = $ quote ->isMultipleShippingAddresses ();
88
87
if ($ isMultipleShippingAddressesPresent || $ this ->isDisableMultishippingRequired ($ request , $ quote )) {
89
88
$ this ->disableMultishipping ->execute ($ quote );
90
- $ currentShippingAddress = $ quote ->getShippingAddress ();
91
- foreach ($ quote ->getAllShippingAddresses () as $ address ) {
92
- if ($ address ->getId () == $ currentShippingAddress ->getId ()) {
93
- continue ;
94
- }
95
- $ quote ->removeAddress ($ address ->getId ());
96
- }
97
-
98
- if ($ currentShippingAddress ) {
99
- $ quote ->addShippingAddress ($ currentShippingAddress );
100
- } else {
101
- $ shippingAddress = $ quote ->getShippingAddress ();
102
- $ defaultShipping = $ quote ->getCustomer ()->getDefaultShipping ();
103
- if ($ defaultShipping ) {
104
- $ defaultCustomerAddress = $ this ->addressRepository ->getById ($ defaultShipping );
105
- $ shippingAddress ->importCustomerAddressData ($ defaultCustomerAddress );
106
- }
107
- }
89
+ $ this ->setDefaultShippingAddress ($ quote );
108
90
109
91
if ($ isMultipleShippingAddressesPresent ) {
110
92
$ this ->checkoutSession ->setMultiShippingAddressesFlag (true );
@@ -121,6 +103,35 @@ public function clearAddressItem($subject, $request)
121
103
}
122
104
}
123
105
106
+ /**
107
+ * Determine shipping address from current multi-shipping configuration
108
+ *
109
+ * @param Quote $quote
110
+ * @return void
111
+ * @throws LocalizedException
112
+ */
113
+ private function setDefaultShippingAddress (Quote $ quote ): void
114
+ {
115
+ $ currentShippingAddress = $ quote ->getShippingAddress ();
116
+ foreach ($ quote ->getAllShippingAddresses () as $ address ) {
117
+ if ($ address ->getId () === $ currentShippingAddress ->getId ()) {
118
+ continue ;
119
+ }
120
+ $ quote ->removeAddress ($ address ->getId ());
121
+ }
122
+
123
+ if ($ currentShippingAddress ) {
124
+ $ quote ->addShippingAddress ($ currentShippingAddress );
125
+ } else {
126
+ $ shippingAddress = $ quote ->getShippingAddress ();
127
+ $ defaultShipping = $ quote ->getCustomer ()->getDefaultShipping ();
128
+ if ($ defaultShipping ) {
129
+ $ defaultCustomerAddress = $ this ->addressRepository ->getById ($ defaultShipping );
130
+ $ shippingAddress ->importCustomerAddressData ($ defaultCustomerAddress );
131
+ }
132
+ }
133
+ }
134
+
124
135
/**
125
136
* Checks whether quote has virtual items
126
137
*
0 commit comments