1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2022 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
declare (strict_types=1 );
7
7
@@ -86,16 +86,8 @@ public function clearAddressItem($subject, $request)
86
86
$ isMultipleShippingAddressesPresent = $ quote ->isMultipleShippingAddresses ();
87
87
if ($ isMultipleShippingAddressesPresent || $ this ->isDisableMultishippingRequired ($ request , $ quote )) {
88
88
$ this ->disableMultishipping ->execute ($ quote );
89
- foreach ($ quote ->getAllShippingAddresses () as $ address ) {
90
- $ quote ->removeAddress ($ address ->getId ());
91
- }
89
+ $ this ->setDefaultShippingAddress ($ quote );
92
90
93
- $ shippingAddress = $ quote ->getShippingAddress ();
94
- $ defaultShipping = $ quote ->getCustomer ()->getDefaultShipping ();
95
- if ($ defaultShipping ) {
96
- $ defaultCustomerAddress = $ this ->addressRepository ->getById ($ defaultShipping );
97
- $ shippingAddress ->importCustomerAddressData ($ defaultCustomerAddress );
98
- }
99
91
if ($ isMultipleShippingAddressesPresent ) {
100
92
$ this ->checkoutSession ->setMultiShippingAddressesFlag (true );
101
93
}
@@ -111,6 +103,35 @@ public function clearAddressItem($subject, $request)
111
103
}
112
104
}
113
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
+
114
135
/**
115
136
* Checks whether quote has virtual items
116
137
*
0 commit comments