Skip to content

Commit

Permalink
Fixed #1486
Browse files Browse the repository at this point in the history
Allow addresses to be unset on an order by passing null
  • Loading branch information
lukeholder committed Jun 3, 2020
1 parent ed3e1b7 commit 7cce184
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Unreleased

### Fixed
- Fixed a bug where blank addresses were being automatically created on new carts. ([#1486](https://github.com/craftcms/commerce/issues/1486))
- Fixed a SQL error that could occur during order consolidation on PostgreSQL.

## 3.1.6 - 2020-06-02
Expand Down
26 changes: 15 additions & 11 deletions src/elements/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -2385,16 +2385,18 @@ public function getShippingAddress()
}

/**
* @param Address|array $address
* @param Address|array|null $address
*/
public function setShippingAddress($address)
{
if (!$address instanceof Address) {
$address = new Address($address);
if ($address === null) {
$this->shippingAddressId = null;
$this->_shippingAddress = null;
} else {
$address = is_array($address) ? new Address($address) : $address;
$this->shippingAddressId = $address->id;
$this->_shippingAddress = $address;
}

$this->shippingAddressId = $address->id;
$this->_shippingAddress = $address;
}

/**
Expand Down Expand Up @@ -2460,12 +2462,14 @@ public function getBillingAddress()
*/
public function setBillingAddress($address)
{
if (!$address instanceof Address) {
$address = new Address($address);
if ($address === null) {
$this->billingAddressId = null;
$this->_billingAddress = null;
} else {
$address = is_array($address) ? new Address($address) : $address;
$this->billingAddressId = $address->id;
$this->_billingAddress = $address;
}

$this->billingAddressId = $address->id;
$this->_billingAddress = $address;
}

/**
Expand Down

0 comments on commit 7cce184

Please sign in to comment.