Skip to content

Commit

Permalink
Merge pull request #25 from cyl3x/fix/customer-active-addresses
Browse files Browse the repository at this point in the history
Fix: Customer active addresses
  • Loading branch information
lernhart authored Sep 12, 2024
2 parents 0fdf101 + 67c06a3 commit c5514e2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Context/SalesChannelContext/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,21 @@ public function getDefaultShippingAddress(): Address

public function getActiveBillingAddress(): Address
{
\assert(is_array($this->data['activeBillingAddress']));
return new Address($this->data['activeBillingAddress']);
if (\array_key_exists('activeBillingAddress', $this->data)) {
\assert(is_array($this->data['activeBillingAddress']));
return new Address($this->data['activeBillingAddress']);
}

return $this->getDefaultBillingAddress();
}

public function getActiveShippingAddress(): Address
{
\assert(is_array($this->data['activeShippingAddress']));
return new Address($this->data['activeShippingAddress']);
if (\array_key_exists('activeShippingAddress', $this->data)) {
\assert(is_array($this->data['activeShippingAddress']));
return new Address($this->data['activeShippingAddress']);
}

return $this->getDefaultShippingAddress();
}
}
11 changes: 11 additions & 0 deletions tests/Context/SalesChannelContext/CustomerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ public function testConstruct(): void
static::assertSame('test', $customer->getActiveShippingAddress()->getId());
}

public function testActiveAddresses(): void
{
$customer = new Customer([
'defaultBillingAddress' => ['id' => 'test'],
'defaultShippingAddress' => ['id' => 'test'],
]);

static::assertSame('test', $customer->getActiveBillingAddress()->getId());
static::assertSame('test', $customer->getActiveShippingAddress()->getId());
}

public function testConstructNullables(): void
{
$customer = new Customer([
Expand Down

0 comments on commit c5514e2

Please sign in to comment.