Skip to content

Commit

Permalink
Fix customer without address on Get customer & login (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
leanormandon authored Feb 2, 2024
1 parent b20a257 commit c9a047b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
5 changes: 2 additions & 3 deletions Config/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="http://thelia.net/schema/dic/module"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<module xmlns="http://thelia.net/schema/dic/module" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://thelia.net/schema/dic/module http://thelia.net/schema/dic/module/module-2_2.xsd">
<fullnamespace>OpenApi\OpenApi</fullnamespace>
<descriptive locale="en_US">
Expand All @@ -20,7 +19,7 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>2.2.11</version>
<version>2.2.12</version>
<authors>
<author>
<name>Vincent Lopes-Vicente</name>
Expand Down
10 changes: 5 additions & 5 deletions Controller/Front/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ public function customerLogin(

$customer = CustomerQuery::create()
->filterByEmail($data['email'])
->findOne()
;
->findOne();

if ($customer === null || !$customer->checkPassword($data['password'])) {
throw new \Exception(Translator::getInstance()->trans('Your username/password pair, does not correspond to any account', [], OpenApi::DOMAIN_NAME));
throw new \Exception(Translator::getInstance()->trans('Your username/password pair, does not correspond to any account',
[], OpenApi::DOMAIN_NAME));
}

$dispatcher->dispatch(new CustomerLoginEvent($customer), TheliaEvents::CUSTOMER_LOGIN);

/* If the rememberMe property is set to true, we create a new cookie to store the information */
if (true === (bool) $data['rememberMe']) {
if (true === (bool)$data['rememberMe']) {
(new CookieTokenProvider())->createCookie(
$customer,
ConfigQuery::read('customer_remember_me_cookie_name', 'crmcn'),
Expand All @@ -108,7 +108,7 @@ public function customerLogin(

/** @var OpenApiCustomer $openApiCustomer */
$openApiCustomer = $modelFactory->buildModel('Customer', $customer);
$openApiCustomer->setDefaultAddressId($customer->getDefaultAddress()->getId());
$openApiCustomer->setDefaultAddressId($customer->getDefaultAddress()?->getId());

return OpenApiService::jsonResponse($openApiCustomer);
}
Expand Down
2 changes: 1 addition & 1 deletion Model/Api/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Customer extends BaseApiModel
public function createFromTheliaModel($theliaModel, $locale = null): void
{
parent::createFromTheliaModel($theliaModel, $locale);
$this->setDefaultAddressId($theliaModel->getDefaultAddress()->getId());
$this->setDefaultAddressId($theliaModel->getDefaultAddress()?->getId());
}

/**
Expand Down

0 comments on commit c9a047b

Please sign in to comment.