-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: pseventbus v4 employees (#369)
- Loading branch information
Showing
10 changed files
with
442 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
namespace PrestaShop\Module\PsEventbus\Provider; | ||
|
||
use PrestaShop\Module\PsEventbus\Config\Config; | ||
use PrestaShop\Module\PsEventbus\Decorator\CustomerDecorator; | ||
use PrestaShop\Module\PsEventbus\Repository\CustomerRepository; | ||
|
||
class CustomerDataProvider implements PaginatedApiDataProviderInterface | ||
{ | ||
/** | ||
* @var CustomerRepository | ||
*/ | ||
private $customerRepository; | ||
/** | ||
* @var CustomerDecorator | ||
*/ | ||
private $customerDecorator; | ||
|
||
public function __construct(CustomerRepository $customerRepository, CustomerDecorator $customerDecorator) | ||
{ | ||
$this->customerRepository = $customerRepository; | ||
$this->customerDecorator = $customerDecorator; | ||
} | ||
|
||
/** | ||
* @param int $offset | ||
* @param int $limit | ||
* @param string $langIso | ||
* | ||
* @return array<mixed> | ||
* | ||
* @@throws \PrestaShopDatabaseException | ||
*/ | ||
public function getFormattedData($offset, $limit, $langIso) | ||
{ | ||
$customers = $this->customerRepository->getCustomers($offset, $limit); | ||
|
||
if (!is_array($customers)) { | ||
return []; | ||
} | ||
|
||
$this->customerDecorator->decorateCustomers($customers); | ||
|
||
return array_map(function ($customer) { | ||
return [ | ||
'id' => "{$customer['id_customer']}", | ||
'collection' => Config::COLLECTION_CUSTOMERS, | ||
'properties' => $customer, | ||
]; | ||
}, $customers); | ||
} | ||
|
||
/** | ||
* @param int $offset | ||
* @param string $langIso | ||
* | ||
* @return int | ||
*/ | ||
public function getRemainingObjectsCount($offset, $langIso) | ||
{ | ||
return (int) $this->customerRepository->getRemainingCustomersCount($offset); | ||
} | ||
|
||
/** | ||
* @param int $limit | ||
* @param string $langIso | ||
* @param array<mixed> $objectIds | ||
* | ||
* @return array<mixed> | ||
* | ||
* @@throws \PrestaShopDatabaseException | ||
*/ | ||
public function getFormattedDataIncremental($limit, $langIso, $objectIds) | ||
{ | ||
$customers = $this->customerRepository->getCustomersIncremental($limit, $objectIds); | ||
|
||
if (!is_array($customers)) { | ||
return []; | ||
} | ||
|
||
$this->customerDecorator->decorateCustomers($customers); | ||
|
||
return array_map(function ($customer) { | ||
return [ | ||
'id' => "{$customer['id_customer']}", | ||
'collection' => Config::COLLECTION_CUSTOMERS, | ||
'properties' => $customer, | ||
]; | ||
}, $customers); | ||
} | ||
|
||
/** | ||
* @param int $offset | ||
* @param int $limit | ||
* @param string $langIso | ||
* | ||
* @return array<mixed> | ||
* | ||
* @@throws \PrestaShopDatabaseException | ||
*/ | ||
public function getQueryForDebug($offset, $limit, $langIso) | ||
{ | ||
return $this->customerRepository->getQueryForDebug($offset, $limit); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace PrestaShop\Module\PsEventbus\Decorator; | ||
|
||
class CurrencyDecorator | ||
{ | ||
/** | ||
* @param array<mixed> $currencies | ||
* | ||
* @return void | ||
*/ | ||
public function decorateCurrencies(&$currencies) | ||
{ | ||
foreach ($currencies as &$currency) { | ||
$this->castPropertyValues($currency); | ||
} | ||
} | ||
|
||
/** | ||
* @param array<mixed> $currency | ||
* | ||
* @return void | ||
*/ | ||
private function castPropertyValues(&$currency) | ||
{ | ||
$currency['id_currency'] = (int) $currency['id_currency']; | ||
$currency['conversion_rate'] = (float) $currency['conversion_rate']; | ||
$currency['deleted'] = (bool) $currency['deleted']; | ||
$currency['active'] = (bool) $currency['active']; | ||
|
||
// https://github.com/PrestaShop/PrestaShop/commit/37807f66b40b0cebb365ef952e919be15e9d6b2f#diff-3f41d3529ffdbfd1b994927eb91826a32a0560697025a734cf128a2c8e092a45R124 | ||
if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '1.7.6.0', '>=')) { | ||
$currency['precision'] = (int) $currency['precision']; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace PrestaShop\Module\PsEventbus\Decorator; | ||
|
||
class CustomerDecorator | ||
{ | ||
/** | ||
* @param array<mixed> $customers | ||
* | ||
* @return void | ||
*/ | ||
public function decorateCustomers(&$customers) | ||
{ | ||
foreach ($customers as &$customer) { | ||
$this->castPropertyValues($customer); | ||
$this->hashEmail($customer); | ||
} | ||
} | ||
|
||
/** | ||
* @param array<mixed> $customer | ||
* | ||
* @return void | ||
*/ | ||
private function castPropertyValues(&$customer) | ||
{ | ||
$customer['id_customer'] = (int) $customer['id_customer']; | ||
$customer['id_lang'] = (int) $customer['id_lang']; | ||
$customer['newsletter'] = (bool) $customer['newsletter']; | ||
$customer['newsletter_date_add'] = (string) $customer['newsletter_date_add']; | ||
$customer['optin'] = (bool) $customer['optin']; | ||
$customer['active'] = (bool) $customer['active']; | ||
$customer['is_guest'] = (bool) $customer['is_guest']; | ||
$customer['deleted'] = (bool) $customer['deleted']; | ||
} | ||
|
||
/** | ||
* @param array<mixed> $customer | ||
* | ||
* @return void | ||
*/ | ||
private function hashEmail(&$customer) | ||
{ | ||
$customer['email_hash'] = hash('sha256', $customer['email'] . 'dUj4GMBD6689pL9pyr'); | ||
unset($customer['email']); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.