diff --git a/src/QUI/ERP/User.php b/src/QUI/ERP/User.php index 9ab8bb0430153320a83e163aa614d8b6ec3545ce..ae6476af592ab30530fe3c88ca2b84cdb07fb726 100644 --- a/src/QUI/ERP/User.php +++ b/src/QUI/ERP/User.php @@ -7,7 +7,6 @@ namespace QUI\ERP; use QUI; -use QUI\Countries\Country; use QUI\ERP\Customer\NumberRange as CustomerNumberRange; use QUI\Groups\Group; use QUI\Interfaces\Users\User as UserInterface; @@ -87,7 +86,6 @@ class User extends QUI\QDOM implements UserInterface * User constructor. * * @param array $attributes - * @throws QUI\ERP\Exception */ public function __construct(array $attributes) { @@ -152,6 +150,24 @@ public function __construct(array $attributes) } $this->isNetto = $this->isNetto(); + + // if no customer number exists, check whether a customer exists and the customer has a customer number + // this is a fallback (by hen & mor) + if (!$this->getAttribute('customerId')) { + if ($this->uuid) { + try { + $User = QUI::getUsers()->get($this->uuid); + $this->setAttribute('customerId', $User->getAttribute('customerId')); + } catch (QUI\Exception) { + } + } elseif ($this->id) { + try { + $User = QUI::getUsers()->get($this->id); + $this->setAttribute('customerId', $User->getAttribute('customerId')); + } catch (QUI\Exception) { + } + } + } } /** @@ -221,6 +237,7 @@ public static function convertUserToErpUser(UserInterface $User): User return new self([ 'id' => $User->getId(), + 'customerId' => $User->getAttribute('customerId'), 'uuid' => $User->getUUID(), 'country' => $country, 'username' => $User->getUsername(), diff --git a/src/QUI/ERP/Utils/User.php b/src/QUI/ERP/Utils/User.php index de4e78d7923ad7014e74fc7f8be5257d773eb497..28db19f26b963cd31b7b369660420d1ff94fdc85 100644 --- a/src/QUI/ERP/Utils/User.php +++ b/src/QUI/ERP/Utils/User.php @@ -324,6 +324,7 @@ public static function filterCustomerAttributes(array $attributes = []): array $needle = [ 'uuid', 'id', + 'customerId', 'email', 'lang', 'usergroup',