11<?php
22/**
3- * Copyright 2025 Adobe
3+ * Copyright 2022 Adobe
44 * All Rights Reserved.
55 */
66declare (strict_types=1 );
@@ -74,7 +74,6 @@ public function __construct(
7474 /**
7575 * Cleans shipping addresses and item assignments after MultiShipping flow
7676 *
77- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
7877 * @param Cart|UpdateItemQty $subject
7978 * @param RequestInterface $request
8079 * @throws LocalizedException
@@ -87,24 +86,7 @@ public function clearAddressItem($subject, $request)
8786 $ isMultipleShippingAddressesPresent = $ quote ->isMultipleShippingAddresses ();
8887 if ($ isMultipleShippingAddressesPresent || $ this ->isDisableMultishippingRequired ($ request , $ quote )) {
8988 $ 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 );
10890
10991 if ($ isMultipleShippingAddressesPresent ) {
11092 $ this ->checkoutSession ->setMultiShippingAddressesFlag (true );
@@ -121,6 +103,35 @@ public function clearAddressItem($subject, $request)
121103 }
122104 }
123105
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+
124135 /**
125136 * Checks whether quote has virtual items
126137 *
0 commit comments