Skip to content

Commit

Permalink
Merge pull request #3021 from craftcms/account-for-null-address-owner
Browse files Browse the repository at this point in the history
Account for null address owner
  • Loading branch information
lukeholder authored Nov 7, 2022
2 parents 03d6415 + 8b72203 commit 61341fe
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/behaviors/CustomerAddressBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@ public function afterPropagate(): void
public function getIsPrimaryBilling(): bool
{
if (!isset($this->_isPrimaryBilling)) {
if (!$this->owner->id) {

/** @var User|CustomerBehavior|null $user */
$user = $this->owner->getOwner();

if (!$this->owner->id || !$user) {
return false;
}

/** @var User|CustomerBehavior $user */
$user = $this->owner->getOwner();
$this->_isPrimaryBilling = $this->owner->id === $user->getPrimaryBillingAddressId();
}

Expand All @@ -109,12 +111,14 @@ public function setIsPrimaryBilling(bool|string $value): void
public function getIsPrimaryShipping(): bool
{
if (!isset($this->_isPrimaryShipping)) {
if (!$this->owner->id) {

/** @var User|CustomerBehavior|null $user */
$user = $this->owner->getOwner();

if (!$this->owner->id || !$user) {
return false;
}

/** @var User|CustomerBehavior $user */
$user = $this->owner->getOwner();
$this->_isPrimaryShipping = $this->owner->id === $user->getPrimaryShippingAddressId();
}

Expand Down

0 comments on commit 61341fe

Please sign in to comment.