Skip to content

Commit

Permalink
Feat: pseventbus v4 employees (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
fox-john authored Sep 20, 2024
1 parent 4ac48de commit 6884b2d
Show file tree
Hide file tree
Showing 10 changed files with 442 additions and 156 deletions.
106 changes: 106 additions & 0 deletions OLD/Provider/CustomerDataProvider.php
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);
}
}
4 changes: 4 additions & 0 deletions config/common/new-repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ services:
PrestaShop\Module\PsEventbus\Repository\NewRepository\CurrencyRepository:
class: PrestaShop\Module\PsEventbus\Repository\NewRepository\CurrencyRepository
public: true

PrestaShop\Module\PsEventbus\Repository\NewRepository\EmployeeRepository:
class: PrestaShop\Module\PsEventbus\Repository\NewRepository\EmployeeRepository
public: true
7 changes: 0 additions & 7 deletions config/common/repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,6 @@ services:
public: true
arguments:
- '@=service("prestashop.adapter.legacy.context").getContext()'


PrestaShop\Module\PsEventbus\Repository\EmployeeRepository:
class: PrestaShop\Module\PsEventbus\Repository\EmployeeRepository
public: true
arguments:
- '@=service("prestashop.adapter.legacy.context").getContext()'

PrestaShop\Module\PsEventbus\Repository\ImageRepository:
class: PrestaShop\Module\PsEventbus\Repository\ImageRepository
Expand Down
6 changes: 6 additions & 0 deletions config/front/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,9 @@ services:
public: true
arguments:
- '@PrestaShop\Module\PsEventbus\Repository\NewRepository\CurrencyRepository'

PrestaShop\Module\PsEventbus\Service\ShopContent\EmployeesService:
class: PrestaShop\Module\PsEventbus\Service\ShopContent\EmployeesService
public: true
arguments:
- '@PrestaShop\Module\PsEventbus\Repository\NewRepository\EmployeeRepository'
1 change: 1 addition & 0 deletions e2e/src/helpers/shop-contents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const shopContentMapping = {
categories: "categories",
customers: "customers",
currencies: "currencies",
employees: "employees",
} as const;

type ShopContentMapping = typeof shopContentMapping;
Expand Down
36 changes: 36 additions & 0 deletions src/Decorator/CurrencyDecorator.php
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'];
}
}
}
47 changes: 47 additions & 0 deletions src/Decorator/CustomerDecorator.php
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']);
}
}
149 changes: 0 additions & 149 deletions src/Repository/EmployeeRepository.php

This file was deleted.

Loading

0 comments on commit 6884b2d

Please sign in to comment.