@@ -148,8 +148,18 @@ public function getQuote()
148
148
}
149
149
150
150
if ($ this ->getCustomerId ()) {
151
+ // on a new quote, this will return an empty array
152
+ $ addresses = $ this ->_quote ->getAllAddresses ();
153
+ $ billingAddress = $ this ->findAddressByType (
154
+ $ addresses ,
155
+ \Magento \Quote \Model \Quote \Address::ADDRESS_TYPE_BILLING
156
+ );
157
+ $ shippingAddress = $ this ->findAddressByType (
158
+ $ addresses ,
159
+ \Magento \Quote \Model \Quote \Address::ADDRESS_TYPE_SHIPPING
160
+ );
151
161
$ customer = $ this ->customerRepository ->getById ($ this ->getCustomerId ());
152
- $ this ->_quote ->assignCustomer ($ customer );
162
+ $ this ->_quote ->assignCustomerWithAddressChange ($ customer, $ billingAddress , $ shippingAddress );
153
163
}
154
164
}
155
165
$ this ->_quote ->setIgnoreOldQty (true );
@@ -159,6 +169,25 @@ public function getQuote()
159
169
return $ this ->_quote ;
160
170
}
161
171
172
+ /**
173
+ * Returns the type of address requested, or null if no type of address is found
174
+ *
175
+ * @param \Magento\Quote\Model\Quote\Address[] $addresses
176
+ * @param string $type ex: 'billing' or 'shipping'
177
+ * @return \Magento\Quote\Model\Quote\Address|null
178
+ */
179
+ protected function findAddressByType ($ addresses , $ type )
180
+ {
181
+ $ theAddress = null ;
182
+ foreach ($ addresses as $ address ) {
183
+ if ($ address ->getAddressType () == $ type ) {
184
+ $ theAddress = $ address ;
185
+ break ;
186
+ }
187
+ }
188
+ return $ theAddress ;
189
+ }
190
+
162
191
/**
163
192
* Retrieve store model object
164
193
*
0 commit comments