diff --git a/apiConfig.readonly.json b/apiConfig.readonly.json index a844780..3a27873 100644 --- a/apiConfig.readonly.json +++ b/apiConfig.readonly.json @@ -1,5 +1,5 @@ { - "version": "2.2.1", + "version": "2.2.3", "tokenTimeout": 60, "apiRequestRatePerMinute": 256, "servicesDBCache": 10 diff --git a/changelog.md b/changelog.md index 6308f01..8595abe 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,10 @@ #All notable changes to `CRM CLient V2` will be documented in this file. +# version 2.2.3 +- Changed for bool casting for response parse field 'status' when is int 1 or 0 +- Changed, properties are filled from CRM after a save or update action, this will allow for props to be set on model as it is on the crm, after all checks and casts (firstname capitalized, ... etc) + # version 2.2.2 - Fixed Arcadia mail where sending parameters as query instead of Data diff --git a/composer.json b/composer.json index 9369579..a45c696 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "type": "library", "description": "LDC CRM Client V2", "license": "MIT", - "version": "2.2.2", + "version": "2.2.3", "authors": [ { "name": "Jérémy Munsch", diff --git a/src/Models/CrmClientModel.php b/src/Models/CrmClientModel.php index 7235a01..fe416ed 100644 --- a/src/Models/CrmClientModel.php +++ b/src/Models/CrmClientModel.php @@ -124,6 +124,10 @@ abstract class CrmClientModel implements JsonSerializable if (count($properties)) { foreach ($properties as $field => $value) { $type = $this->getPropType($field); + // Force boolean + if ($type === 'bool') { + $value = (\is_int($value) and ($value === 1 or $value === 0)) ? (bool)$value : $value; + } if (!$this->checkFieldType($type, $value)) { throw new TypeError("Wrong type for $field"); } diff --git a/src/Models/Customer.php b/src/Models/Customer.php index a9f3dca..1f6c07a 100644 --- a/src/Models/Customer.php +++ b/src/Models/Customer.php @@ -14,6 +14,11 @@ use TypeError; * the account validation status. You can use it as * a standalone class but beware of catching exceptions * + * Be warned that on server side data is normalized + * - firstname and lastname are 'capitalized' + * - fields are trimmed + * - non numeric chars are removed from postcode + * * @property string $hashcode The crm hashcode this is a readonly field * @property string $email Must be a rfc valid email on a valid domain name * @property string $password Required only on create, must have upper and lowers chars, @@ -453,7 +458,7 @@ class Customer extends CrmClientModel $response = static::$apiInterface->call($request); if ($status = $response->status->equals(ApiStatus::OK())) { $this->updatedValues = []; - $this->hashcode = $response->data['hashcode']; + $this->fill($response->data); } return $status; } @@ -469,6 +474,7 @@ class Customer extends CrmClientModel $response = static::$apiInterface->call($request); if ($status = $response->status->equals(ApiStatus::OK())) { $this->updatedValues = []; + $this->fill($response->data); } return $status; } @@ -512,7 +518,7 @@ class Customer extends CrmClientModel ]); $response = static::$apiInterface->call($request); - $this->status = true; + $this->__set('status', true); return $response->status->equals(ApiStatus::OK()); } @@ -527,7 +533,7 @@ class Customer extends CrmClientModel */ public function toggleOptin(): bool { - $this->opt_in = !$this->opt_in; + $this->__set('opt_in', !$this->opt_in); return $this->update(); }