Skip to content

Commit d977fe1

Browse files
author
Mike Weis
committed
MAGETWO-31933: Can't change shipping address when creating order in backend
- fixed
1 parent d2f9cd1 commit d977fe1

File tree

1 file changed

+30
-1
lines changed
  • app/code/Magento/Backend/Model/Session

1 file changed

+30
-1
lines changed

app/code/Magento/Backend/Model/Session/Quote.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,18 @@ public function getQuote()
148148
}
149149

150150
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+
);
151161
$customer = $this->customerRepository->getById($this->getCustomerId());
152-
$this->_quote->assignCustomer($customer);
162+
$this->_quote->assignCustomerWithAddressChange($customer, $billingAddress, $shippingAddress);
153163
}
154164
}
155165
$this->_quote->setIgnoreOldQty(true);
@@ -159,6 +169,25 @@ public function getQuote()
159169
return $this->_quote;
160170
}
161171

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+
162191
/**
163192
* Retrieve store model object
164193
*

0 commit comments

Comments
 (0)