From e55e7fa2b8ba29e3080c0a45f8e00e4cdad86c1f Mon Sep 17 00:00:00 2001 From: "John.R" Date: Thu, 5 Sep 2024 09:52:14 +0200 Subject: [PATCH 1/5] fix: use import --- .../NewRepository/AbstractRepository.php | 27 +++--- .../{ => NewRepository}/CarrierRepository.php | 89 +++++++++++++++---- .../NewRepository/OrderCartRuleRepository.php | 20 +++-- .../NewRepository/OrderDetailRepository.php | 27 +++--- .../NewRepository/OrderHistoryRepository.php | 24 ++--- .../NewRepository/OrderRepository.php | 20 +++-- .../NewRepository/RepositoryInterface.php | 4 +- src/Service/HealthCheckService.php | 7 +- src/Service/SynchronizationService.php | 19 ++-- 9 files changed, 161 insertions(+), 76 deletions(-) rename src/Repository/{ => NewRepository}/CarrierRepository.php (75%) diff --git a/src/Repository/NewRepository/AbstractRepository.php b/src/Repository/NewRepository/AbstractRepository.php index a54de804..e941c0a2 100644 --- a/src/Repository/NewRepository/AbstractRepository.php +++ b/src/Repository/NewRepository/AbstractRepository.php @@ -3,45 +3,50 @@ namespace PrestaShop\Module\PsEventbus\Repository\NewRepository; use PrestaShop\Module\PsEventbus\Service\CommonService; +use PrestaShopException; +use PrestaShopDatabaseException; +use Db; +use Context; +use DbQuery; abstract class AbstractRepository { /** - * @var \Context + * @var Context */ private $context; /** - * @var \Db + * @var Db */ private $db; /** - * @var \DbQuery + * @var DbQuery */ protected $query; public function __construct() { - $context = \Context::getContext(); + $context = Context::getContext(); if ($context == null) { - throw new \PrestaShopException('Context not found'); + throw new PrestaShopException('Context not found'); } $this->context = $context; - $this->db = \Db::getInstance(); + $this->db = Db::getInstance(); } /** * @return int * - * @throws \PrestaShopException + * @throws PrestaShopException */ public function getShopId() { if ($this->context->shop === null) { - throw new \PrestaShopException('No shop context'); + throw new PrestaShopException('No shop context'); } return (int) $this->context->shop->id; @@ -52,8 +57,8 @@ public function getShopId() * * @return array * - * @throws \PrestaShopException - * @throws \PrestaShopDatabaseException + * @throws PrestaShopException + * @throws PrestaShopDatabaseException */ protected function runQuery($debug) { @@ -69,7 +74,7 @@ protected function runQuery($debug) /** * @return void * - * @throws \PrestaShopException + * @throws PrestaShopException */ private function debugQuery() { diff --git a/src/Repository/CarrierRepository.php b/src/Repository/NewRepository/CarrierRepository.php similarity index 75% rename from src/Repository/CarrierRepository.php rename to src/Repository/NewRepository/CarrierRepository.php index f36d8c89..c0e4951f 100644 --- a/src/Repository/CarrierRepository.php +++ b/src/Repository/NewRepository/CarrierRepository.php @@ -1,34 +1,91 @@ shop === null) { + throw new PrestaShopException('No shop context'); + } + + $this->query = new DbQuery(); + + $this->query->from('carrier', 'c'); + $this->query->select('c.id_carrier'); + $this->query->leftJoin('carrier_lang', 'cl', 'cl.id_carrier = c.id_carrier AND cl.id_lang = ' . $langId); + $this->query->leftJoin('carrier_shop', 'cs', 'cs.id_carrier = c.id_carrier'); + $this->query->where('cs.id_shop = ' . $context->shop->id); + $this->query->where('deleted=0'); + } + /** - * @var \Context + * @param int $offset + * @param int $limit + * @param string $langIso + * @param bool $debug + * + * @return array + * + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException */ - private $context; + public function getContentsForFull($offset, $limit, $langIso, $debug) + { + + } /** - * @var int + * @param int $limit + * @param array $contentIds + * @param string $langIso + * @param bool $debug + * + * @return array + * + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException */ - private $shopId; - - public function __construct(\Context $context) + public function getContentsForIncremental($limit, $contentIds, $langIso, $debug) { - $this->db = \Db::getInstance(); - $this->context = $context; - if ($this->context->shop === null) { - throw new \PrestaShopException('No shop context'); - } + } + + /** + * @param int $offset + * @param string $langIso + * @param bool $debug + * + * @return int + * + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException + */ + public function countFullSyncContentLeft($offset, $langIso, $debug) + { - $this->shopId = (int) $this->context->shop->id; } /** diff --git a/src/Repository/NewRepository/OrderCartRuleRepository.php b/src/Repository/NewRepository/OrderCartRuleRepository.php index b7cfe543..b5d0b84b 100644 --- a/src/Repository/NewRepository/OrderCartRuleRepository.php +++ b/src/Repository/NewRepository/OrderCartRuleRepository.php @@ -2,6 +2,10 @@ namespace PrestaShop\Module\PsEventbus\Repository\NewRepository; +use PrestaShopException; +use PrestaShopDatabaseException; +use DbQuery; + class OrderCartRuleRepository extends AbstractRepository implements RepositoryInterface { const TABLE_NAME = 'order_cart_rule'; @@ -11,11 +15,11 @@ class OrderCartRuleRepository extends AbstractRepository implements RepositoryIn * * @return mixed * - * @throws \PrestaShopException + * @throws PrestaShopException */ public function generateBaseQuery($langIso) { - $this->query = new \DbQuery(); + $this->query = new DbQuery(); $this->query ->from(self::TABLE_NAME, 'ocr'); @@ -43,8 +47,8 @@ public function generateBaseQuery($langIso) * * @return array * - * @throws \PrestaShopException - * @throws \PrestaShopDatabaseException + * @throws PrestaShopException + * @throws PrestaShopDatabaseException */ public function getContentsForFull($offset, $limit, $langIso, $debug) { @@ -63,8 +67,8 @@ public function getContentsForFull($offset, $limit, $langIso, $debug) * * @return array * - * @throws \PrestaShopException - * @throws \PrestaShopDatabaseException + * @throws PrestaShopException + * @throws PrestaShopDatabaseException */ public function getContentsForIncremental($limit, $contentIds, $langIso, $debug) { @@ -84,8 +88,8 @@ public function getContentsForIncremental($limit, $contentIds, $langIso, $debug) * * @return int * - * @throws \PrestaShopException - * @throws \PrestaShopDatabaseException + * @throws PrestaShopException + * @throws PrestaShopDatabaseException */ public function countFullSyncContentLeft($offset, $langIso, $debug) { diff --git a/src/Repository/NewRepository/OrderDetailRepository.php b/src/Repository/NewRepository/OrderDetailRepository.php index 9803b38c..ad7aa803 100644 --- a/src/Repository/NewRepository/OrderDetailRepository.php +++ b/src/Repository/NewRepository/OrderDetailRepository.php @@ -2,6 +2,11 @@ namespace PrestaShop\Module\PsEventbus\Repository\NewRepository; +use PrestaShopException; +use PrestaShopDatabaseException; +use Context; +use DbQuery; + class OrderDetailRepository extends AbstractRepository implements RepositoryInterface { const TABLE_NAME = 'order_detail'; @@ -11,21 +16,21 @@ class OrderDetailRepository extends AbstractRepository implements RepositoryInte * * @return mixed * - * @throws \PrestaShopException + * @throws PrestaShopException */ public function generateBaseQuery($langIso) { - $context = \Context::getContext(); + $context = Context::getContext(); if ($context === null) { - throw new \PrestaShopException('Context is null'); + throw new PrestaShopException('Context is null'); } if ($context->shop === null) { - throw new \PrestaShopException('No shop context'); + throw new PrestaShopException('No shop context'); } - $this->query = new \DbQuery(); + $this->query = new DbQuery(); $this->query ->from(self::TABLE_NAME, 'od') @@ -63,8 +68,8 @@ public function generateBaseQuery($langIso) * * @return array * - * @throws \PrestaShopException - * @throws \PrestaShopDatabaseException + * @throws PrestaShopException + * @throws PrestaShopDatabaseException */ public function getContentsForFull($offset, $limit, $langIso, $debug) { @@ -83,8 +88,8 @@ public function getContentsForFull($offset, $limit, $langIso, $debug) * * @return array * - * @throws \PrestaShopException - * @throws \PrestaShopDatabaseException + * @throws PrestaShopException + * @throws PrestaShopDatabaseException */ public function getContentsForIncremental($limit, $contentIds, $langIso, $debug) { @@ -105,8 +110,8 @@ public function getContentsForIncremental($limit, $contentIds, $langIso, $debug) * * @return int * - * @throws \PrestaShopException - * @throws \PrestaShopDatabaseException + * @throws PrestaShopException + * @throws PrestaShopDatabaseException */ public function countFullSyncContentLeft($offset, $langIso, $debug) { diff --git a/src/Repository/NewRepository/OrderHistoryRepository.php b/src/Repository/NewRepository/OrderHistoryRepository.php index dcb742d0..d1652088 100644 --- a/src/Repository/NewRepository/OrderHistoryRepository.php +++ b/src/Repository/NewRepository/OrderHistoryRepository.php @@ -2,6 +2,10 @@ namespace PrestaShop\Module\PsEventbus\Repository\NewRepository; +use PrestaShopException; +use PrestaShopDatabaseException; +use Language; +use DbQuery; class OrderHistoryRepository extends AbstractRepository implements RepositoryInterface { const TABLE_NAME = 'order_history'; @@ -11,13 +15,13 @@ class OrderHistoryRepository extends AbstractRepository implements RepositoryInt * * @return mixed * - * @throws \PrestaShopException + * @throws PrestaShopException */ public function generateBaseQuery($langIso) { - $langId = (int) \Language::getIdByIso($langIso); + $langId = (int) Language::getIdByIso($langIso); - $this->query = new \DbQuery(); + $this->query = new DbQuery(); $this->query ->from(self::TABLE_NAME, 'oh') @@ -48,8 +52,8 @@ public function generateBaseQuery($langIso) * * @return array * - * @throws \PrestaShopException - * @throws \PrestaShopDatabaseException + * @throws PrestaShopException + * @throws PrestaShopDatabaseException */ public function getContentsForFull($offset, $limit, $langIso, $debug) { @@ -68,8 +72,8 @@ public function getContentsForFull($offset, $limit, $langIso, $debug) * * @return array * - * @throws \PrestaShopException - * @throws \PrestaShopDatabaseException + * @throws PrestaShopException + * @throws PrestaShopDatabaseException */ public function getContentsForIncremental($limit, $contentIds, $langIso, $debug) { @@ -90,8 +94,8 @@ public function getContentsForIncremental($limit, $contentIds, $langIso, $debug) * * @return int * - * @throws \PrestaShopException - * @throws \PrestaShopDatabaseException + * @throws PrestaShopException + * @throws PrestaShopDatabaseException */ public function countFullSyncContentLeft($offset, $langIso, $debug) { @@ -111,7 +115,7 @@ public function countFullSyncContentLeft($offset, $langIso, $debug) * * @return array * - * @throws \PrestaShopDatabaseException + * @throws PrestaShopDatabaseException */ public function getOrderHistoryIdsByOrderIds($orderIds, $langIso, $debug) { diff --git a/src/Repository/NewRepository/OrderRepository.php b/src/Repository/NewRepository/OrderRepository.php index 29053013..6d8daef5 100644 --- a/src/Repository/NewRepository/OrderRepository.php +++ b/src/Repository/NewRepository/OrderRepository.php @@ -2,6 +2,10 @@ namespace PrestaShop\Module\PsEventbus\Repository\NewRepository; +use PrestaShopException; +use PrestaShopDatabaseException; +use DbQuery; + class OrderRepository extends AbstractRepository implements RepositoryInterface { const TABLE_NAME = 'orders'; @@ -11,11 +15,11 @@ class OrderRepository extends AbstractRepository implements RepositoryInterface * * @return mixed * - * @throws \PrestaShopException + * @throws PrestaShopException */ public function generateBaseQuery($langIso) { - $this->query = new \DbQuery(); + $this->query = new DbQuery(); $this->query ->from(self::TABLE_NAME, 'o') @@ -93,8 +97,8 @@ public function generateBaseQuery($langIso) * * @return array * - * @throws \PrestaShopException - * @throws \PrestaShopDatabaseException + * @throws PrestaShopException + * @throws PrestaShopDatabaseException */ public function getContentsForFull($offset, $limit, $langIso, $debug) { @@ -113,8 +117,8 @@ public function getContentsForFull($offset, $limit, $langIso, $debug) * * @return array * - * @throws \PrestaShopException - * @throws \PrestaShopDatabaseException + * @throws PrestaShopException + * @throws PrestaShopDatabaseException */ public function getContentsForIncremental($limit, $contentIds, $langIso, $debug) { @@ -135,8 +139,8 @@ public function getContentsForIncremental($limit, $contentIds, $langIso, $debug) * * @return int * - * @throws \PrestaShopException - * @throws \PrestaShopDatabaseException + * @throws PrestaShopException + * @throws PrestaShopDatabaseException */ public function countFullSyncContentLeft($offset, $langIso, $debug) { diff --git a/src/Repository/NewRepository/RepositoryInterface.php b/src/Repository/NewRepository/RepositoryInterface.php index d6ec5a21..9164716c 100644 --- a/src/Repository/NewRepository/RepositoryInterface.php +++ b/src/Repository/NewRepository/RepositoryInterface.php @@ -2,8 +2,10 @@ namespace PrestaShop\Module\PsEventbus\Repository\NewRepository; +use DbQuery; + /** - * @property \DbQuery $query + * @property DbQuery $query */ interface RepositoryInterface { diff --git a/src/Service/HealthCheckService.php b/src/Service/HealthCheckService.php index 19d0d8d9..3fd3c126 100644 --- a/src/Service/HealthCheckService.php +++ b/src/Service/HealthCheckService.php @@ -3,13 +3,14 @@ namespace PrestaShop\Module\PsEventbus\Service; use PrestaShop\Module\PsEventbus\Repository\ServerInformationRepository; +use Ps_eventbus; class HealthCheckService { - /** @var \Ps_eventbus */ + /** @var Ps_eventbus */ private $module; - public function __construct(\Ps_eventbus $module) + public function __construct(Ps_eventbus $module) { $this->module = $module; } @@ -19,7 +20,7 @@ public function __construct(\Ps_eventbus $module) * * @return void * - * @throws \PrestaShopException + * @throws PrestaShopException */ public function getHealthCheck($isAuthentified) { diff --git a/src/Service/SynchronizationService.php b/src/Service/SynchronizationService.php index 6024d5d9..b6a520cc 100644 --- a/src/Service/SynchronizationService.php +++ b/src/Service/SynchronizationService.php @@ -11,6 +11,9 @@ use PrestaShop\Module\PsEventbus\Repository\LiveSyncRepository; use PrestaShop\Module\PsEventbus\Service\ShopContent\ShopContentServiceInterface; use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; +use Module; +use DateTime; +use DateTimeZone; class SynchronizationService { @@ -72,7 +75,7 @@ public function __construct( * * @return array * - * @@throws \PrestaShopDatabaseException|EnvVarException|ApiException + * @@throws PrestaShopDatabaseException|EnvVarException|ApiException */ public function sendFullSync( string $shopContent, @@ -89,8 +92,8 @@ public function sendFullSync( $serviceName = str_replace('_', '', ucwords($shopContent, '_')); $serviceId = 'PrestaShop\Module\PsEventbus\Service\ShopContent\\' . $serviceName . 'Service'; // faire un mapping entre le service et le nom du shopcontent - /** @var \Ps_eventbus */ - $module = \Module::getInstanceByName('ps_eventbus'); + /** @var Ps_eventbus */ + $module = Module::getInstanceByName('ps_eventbus'); if (!$module->hasService($serviceId)) { throw new ServiceNotFoundException($serviceId); @@ -103,7 +106,7 @@ public function sendFullSync( $configurationRepository = $module->getService('PrestaShop\Module\PsEventbus\Repository\ConfigurationRepository'); $timezone = (string) $configurationRepository->get('PS_TIMEZONE'); - $dateNow = (new \DateTime('now', new \DateTimeZone($timezone)))->format(Config::MYSQL_DATE_FORMAT); + $dateNow = (new DateTime('now', new DateTimeZone($timezone)))->format(Config::MYSQL_DATE_FORMAT); $data = $shopContentApiService->getContentsForFull($offset, $limit, $langIso, $debug); @@ -139,7 +142,7 @@ public function sendFullSync( * * @return array * - * @@throws \PrestaShopDatabaseException|EnvVarException + * @@throws PrestaShopDatabaseException|EnvVarException */ public function sendIncrementalSync( string $shopContent, @@ -154,8 +157,8 @@ public function sendIncrementalSync( $serviceName = str_replace('_', '', ucwords($shopContent, '_')); $serviceId = 'PrestaShop\Module\PsEventbus\Service\ShopContent\\' . $serviceName . 'Service'; - /** @var \Ps_eventbus */ - $module = \Module::getInstanceByName('ps_eventbus'); + /** @var Ps_eventbus */ + $module = Module::getInstanceByName('ps_eventbus'); if (!$module->hasService($serviceId)) { throw new ServiceNotFoundException($serviceId); @@ -301,7 +304,7 @@ public function insertContentIntoIncremental($contentTypesWithIds, $actionType, * * @return bool * - * @@throws \PrestaShopDatabaseException + * @@throws PrestaShopDatabaseException */ private function debounceLiveSync($shopContentName) // @phpstan-ignore method.unused { From d6166b10ba66e9d0eb9b04db0b128474d1ecf4af Mon Sep 17 00:00:00 2001 From: "John.R" Date: Thu, 5 Sep 2024 11:09:00 +0200 Subject: [PATCH 2/5] feat: refacto carriers --- OLD/Provider/CarrierDataProvider.php | 137 ---------- config/common/builder.yml | 2 +- e2e/src/helpers/shop-contents.ts | 6 +- src/Builder/CarrierBuilder.php | 125 +++++++-- .../NewRepository/CarrierRepository.php | 240 ++---------------- src/Service/ShopContent/CarriersService.php | 123 +++++++++ 6 files changed, 256 insertions(+), 377 deletions(-) delete mode 100644 OLD/Provider/CarrierDataProvider.php create mode 100644 src/Service/ShopContent/CarriersService.php diff --git a/OLD/Provider/CarrierDataProvider.php b/OLD/Provider/CarrierDataProvider.php deleted file mode 100644 index 1a4a709f..00000000 --- a/OLD/Provider/CarrierDataProvider.php +++ /dev/null @@ -1,137 +0,0 @@ -configurationRepository = $configurationRepository; - $this->carrierBuilder = $carrierBuilder; - $this->carrierRepository = $carrierRepository; - $this->languageRepository = $languageRepository; - } - - /** - * @param int $offset - * @param int $limit - * @param string $langIso - * - * @return array - * - * @@throws \PrestaShopDatabaseException - */ - public function getFormattedData($offset, $limit, $langIso) - { - $currency = new \Currency((int) $this->configurationRepository->get('PS_CURRENCY_DEFAULT')); - - $langId = $this->languageRepository->getLanguageIdByIsoCode($langIso); - /** @var array $carriers */ - $carriers = $this->carrierRepository->getAllCarrierProperties($offset, $limit, $langId); - - /** @var string $configurationPsWeightUnit */ - $configurationPsWeightUnit = $this->configurationRepository->get('PS_WEIGHT_UNIT'); - /** @var EventBusCarrier[] $eventBusCarriers */ - $eventBusCarriers = $this->carrierBuilder->buildCarriers( - $carriers, - $langId, - $currency, - $configurationPsWeightUnit - ); - - return $eventBusCarriers; - } - - public function getFormattedDataIncremental($limit, $langIso, $objectIds) - { - /** @var array $shippingIncremental */ - $shippingIncremental = $this->carrierRepository->getShippingIncremental(Config::COLLECTION_CARRIERS, $langIso); - - if (!$shippingIncremental) { - return []; - } - - $currency = new \Currency((int) $this->configurationRepository->get('PS_CURRENCY_DEFAULT')); - - $langId = $this->languageRepository->getLanguageIdByIsoCode($langIso); - - $carrierIds = array_column($shippingIncremental, 'id_object'); - /** @var array $carriers */ - $carriers = $this->carrierRepository->getCarrierProperties($carrierIds, $langId); - - /** @var string $configurationPsWeightUnit */ - $configurationPsWeightUnit = $this->configurationRepository->get('PS_WEIGHT_UNIT'); - /** @var EventBusCarrier[] $eventBusCarriers */ - $eventBusCarriers = $this->carrierBuilder->buildCarriers( - $carriers, - $langId, - $currency, - $configurationPsWeightUnit - ); - - return $eventBusCarriers; - } - - /** - * @param int $offset - * @param string $langIso - * - * @return int - * - * @@throws \PrestaShopDatabaseException - */ - public function getRemainingObjectsCount($offset, $langIso) - { - $langId = $this->languageRepository->getLanguageIdByIsoCode($langIso); - - return (int) $this->carrierRepository->getRemainingCarriersCount($offset, $langId); - } - - /** - * @param int $offset - * @param int $limit - * @param string $langIso - * - * @return array - * - * @@throws \PrestaShopDatabaseException - */ - public function getQueryForDebug($offset, $limit, $langIso) - { - $langId = $this->languageRepository->getLanguageIdByIsoCode($langIso); - - return $this->carrierRepository->getQueryForDebug($offset, $limit, $langId); - } -} diff --git a/config/common/builder.yml b/config/common/builder.yml index 1caea5db..7e4e036c 100644 --- a/config/common/builder.yml +++ b/config/common/builder.yml @@ -3,8 +3,8 @@ services: class: PrestaShop\Module\PsEventbus\Builder\CarrierBuilder public: true arguments: - - '@PrestaShop\Module\PsEventbus\Repository\CarrierRepository' - '@PrestaShop\Module\PsEventbus\Repository\CountryRepository' - '@PrestaShop\Module\PsEventbus\Repository\StateRepository' - '@PrestaShop\Module\PsEventbus\Repository\TaxRepository' - '@PrestaShop\Module\PsEventbus\Repository\ConfigurationRepository' + - '@PrestaShop\Module\PsEventbus\Repository\LanguageRepository' diff --git a/e2e/src/helpers/shop-contents.ts b/e2e/src/helpers/shop-contents.ts index bf8a9bfe..7ed2ce5c 100644 --- a/e2e/src/helpers/shop-contents.ts +++ b/e2e/src/helpers/shop-contents.ts @@ -3,7 +3,6 @@ import R from "ramda"; // TEMPORARY DISABLED, WAIT ADD ALL SHOP CONTENT // AFTER UNCOMMENT THIS, CHANGE ALL "as ShopContent"CAST IN FULLSYNC TEST /* export const shopContentMapping = { - 'carriers': 'carriers', 'carrier_details': 'carrier-details', 'carts' : 'carts', 'cart_products': 'carts', @@ -35,10 +34,11 @@ import R from "ramda"; } as const; */ export const shopContentMapping = { + 'carriers': 'carriers', 'orders': 'orders', - 'order_histories': 'order-histories', 'order_cart_rules': 'order-cart-rules', - 'order_details': 'order-details' + 'order_details': 'order-details', + 'order_histories': 'order-histories' } as const; type ShopContentMapping = typeof shopContentMapping; diff --git a/src/Builder/CarrierBuilder.php b/src/Builder/CarrierBuilder.php index aeb65fed..dd8b662a 100644 --- a/src/Builder/CarrierBuilder.php +++ b/src/Builder/CarrierBuilder.php @@ -8,53 +8,44 @@ use PrestaShop\Module\PsEventbus\Repository\CarrierRepository; use PrestaShop\Module\PsEventbus\Repository\ConfigurationRepository; use PrestaShop\Module\PsEventbus\Repository\CountryRepository; +use PrestaShop\Module\PsEventbus\Repository\LanguageRepository; use PrestaShop\Module\PsEventbus\Repository\StateRepository; use PrestaShop\Module\PsEventbus\Repository\TaxRepository; class CarrierBuilder { - /** - * @var CarrierRepository - */ - private $carrierRepository; - - /** - * @var CountryRepository - */ + /** @var CountryRepository */ private $countryRepository; - /** - * @var StateRepository - */ + /** @var StateRepository */ private $stateRepository; - /** - * @var TaxRepository - */ + /** @var TaxRepository */ private $taxRepository; - /** - * @var ConfigurationRepository - */ + /** @var ConfigurationRepository */ private $configurationRepository; + /** @var LanguageRepository */ + private $languageRepository; + public function __construct( - CarrierRepository $carrierRepository, CountryRepository $countryRepository, StateRepository $stateRepository, TaxRepository $taxRepository, - ConfigurationRepository $configurationRepository + ConfigurationRepository $configurationRepository, + LanguageRepository $languageRepository ) { - $this->carrierRepository = $carrierRepository; $this->countryRepository = $countryRepository; $this->stateRepository = $stateRepository; $this->taxRepository = $taxRepository; $this->configurationRepository = $configurationRepository; + $this->languageRepository = $languageRepository; } /** * @param array $carriers - * @param int $langId + * @param int $langIso * @param \Currency $currency * @param string $weightUnit * @@ -63,8 +54,10 @@ public function __construct( * @@throws \PrestaShopDatabaseException * @@throws \PrestaShopException */ - public function buildCarriers($carriers, $langId, \Currency $currency, $weightUnit) + public function buildCarriers($carriers, $langIso, \Currency $currency, $weightUnit) { + $langId = $this->languageRepository->getLanguageIdByIsoCode($langIso); + $eventBusCarriers = []; foreach ($carriers as $carrier) { $eventBusCarriers[] = $this->buildCarrier( @@ -128,7 +121,7 @@ public function buildCarrier(\Carrier $carrier, $currencyIsoCode, $weightUnit) ->setCurrency($currencyIsoCode) ->setWeightUnit($weightUnit); - $deliveryPriceByRanges = $this->carrierRepository->getDeliveryPriceByRange($carrier); + $deliveryPriceByRanges = $this->getDeliveryPriceByRange($carrier); if (!$deliveryPriceByRanges) { return $eventBusCarrier; @@ -137,7 +130,7 @@ public function buildCarrier(\Carrier $carrier, $currencyIsoCode, $weightUnit) $carrierDetails = []; $carrierTaxes = []; foreach ($deliveryPriceByRanges as $deliveryPriceByRange) { - $range = $this->carrierRepository->getCarrierRange($deliveryPriceByRange); + $range = $this->getCarrierRange($deliveryPriceByRange); if (!$range) { continue; } @@ -162,6 +155,90 @@ public function buildCarrier(\Carrier $carrier, $currencyIsoCode, $weightUnit) return $eventBusCarrier; } + /** + * @param \Carrier $carrierObj + * + * @return array|false + */ + public function getDeliveryPriceByRange(\Carrier $carrierObj) + { + $rangeTable = $carrierObj->getRangeTable(); + switch ($rangeTable) { + case 'range_weight': + return $this->getCarrierByWeightRange($carrierObj, 'range_weight'); + case 'range_price': + return $this->getCarrierByPriceRange($carrierObj, 'range_price'); + default: + return false; + } + } + + /** + * @param \Carrier $carrierObj + * @param string $rangeTable + * + * @return array + */ + private function getCarrierByPriceRange( + \Carrier $carrierObj, + $rangeTable + ) { + $deliveryPriceByRange = \Carrier::getDeliveryPriceByRanges($rangeTable, (int) $carrierObj->id); + + $filteredRanges = []; + foreach ($deliveryPriceByRange as $range) { + $filteredRanges[$range['id_range_price']]['id_range_price'] = $range['id_range_price']; + $filteredRanges[$range['id_range_price']]['id_carrier'] = $range['id_carrier']; + $filteredRanges[$range['id_range_price']]['zones'][$range['id_zone']]['id_zone'] = $range['id_zone']; + $filteredRanges[$range['id_range_price']]['zones'][$range['id_zone']]['price'] = $range['price']; + } + + return $filteredRanges; + } + + /** + * @param \Carrier $carrierObj + * @param string $rangeTable + * + * @return array + */ + private function getCarrierByWeightRange( + \Carrier $carrierObj, + $rangeTable + ) { + $deliveryPriceByRange = \Carrier::getDeliveryPriceByRanges($rangeTable, (int) $carrierObj->id); + + $filteredRanges = []; + foreach ($deliveryPriceByRange as $range) { + $filteredRanges[$range['id_range_weight']]['id_range_weight'] = $range['id_range_weight']; + $filteredRanges[$range['id_range_weight']]['id_carrier'] = $range['id_carrier']; + $filteredRanges[$range['id_range_weight']]['zones'][$range['id_zone']]['id_zone'] = $range['id_zone']; + $filteredRanges[$range['id_range_weight']]['zones'][$range['id_zone']]['price'] = $range['price']; + } + + return $filteredRanges; + } + + /** + * @param array $deliveryPriceByRange + * + * @return false|\RangeWeight|\RangePrice + * + * @throws \PrestaShopDatabaseException + * @throws \PrestaShopException + */ + public function getCarrierRange($deliveryPriceByRange) + { + if (isset($deliveryPriceByRange['id_range_weight'])) { + return new \RangeWeight($deliveryPriceByRange['id_range_weight']); + } + if (isset($deliveryPriceByRange['id_range_price'])) { + return new \RangePrice($deliveryPriceByRange['id_range_price']); + } + + return false; + } + /** * @param \Carrier $carrier * @param \RangeWeight|\RangePrice $range diff --git a/src/Repository/NewRepository/CarrierRepository.php b/src/Repository/NewRepository/CarrierRepository.php index c0e4951f..4bc83709 100644 --- a/src/Repository/NewRepository/CarrierRepository.php +++ b/src/Repository/NewRepository/CarrierRepository.php @@ -33,12 +33,14 @@ public function generateBaseQuery($langIso) $this->query = new DbQuery(); - $this->query->from('carrier', 'c'); - $this->query->select('c.id_carrier'); - $this->query->leftJoin('carrier_lang', 'cl', 'cl.id_carrier = c.id_carrier AND cl.id_lang = ' . $langId); - $this->query->leftJoin('carrier_shop', 'cs', 'cs.id_carrier = c.id_carrier'); - $this->query->where('cs.id_shop = ' . $context->shop->id); - $this->query->where('deleted=0'); + $this->query->from('carrier', 'c') + ->leftJoin('carrier_lang', 'cl', 'cl.id_carrier = c.id_carrier AND cl.id_lang = ' . $langId) + ->leftJoin('carrier_shop', 'cs', 'cs.id_carrier = c.id_carrier') + ->where('cs.id_shop = ' . $context->shop->id) + ->where('deleted=0') + ; + + $this->query->select('c.*'); } /** @@ -49,12 +51,16 @@ public function generateBaseQuery($langIso) * * @return array * - * @throws \PrestaShopException - * @throws \PrestaShopDatabaseException + * @throws PrestaShopException + * @throws PrestaShopDatabaseException */ public function getContentsForFull($offset, $limit, $langIso, $debug) { + $this->generateBaseQuery($langIso); + + $this->query->limit((int) $limit, (int) $offset); + return $this->runQuery($debug); } /** @@ -65,228 +71,38 @@ public function getContentsForFull($offset, $limit, $langIso, $debug) * * @return array * - * @throws \PrestaShopException - * @throws \PrestaShopDatabaseException + * @throws PrestaShopException + * @throws PrestaShopDatabaseException */ public function getContentsForIncremental($limit, $contentIds, $langIso, $debug) { + $this->generateBaseQuery($langIso); - } - - /** - * @param int $offset - * @param string $langIso - * @param bool $debug - * - * @return int - * - * @throws \PrestaShopException - * @throws \PrestaShopDatabaseException - */ - public function countFullSyncContentLeft($offset, $langIso, $debug) - { - - } - - /** - * @param \Carrier $carrierObj - * - * @return array|false - */ - public function getDeliveryPriceByRange(\Carrier $carrierObj) - { - $rangeTable = $carrierObj->getRangeTable(); - switch ($rangeTable) { - case 'range_weight': - return $this->getCarrierByWeightRange($carrierObj, 'range_weight'); - case 'range_price': - return $this->getCarrierByPriceRange($carrierObj, 'range_price'); - default: - return false; - } - } - - /** - * @param \Carrier $carrierObj - * @param string $rangeTable - * - * @return array - */ - private function getCarrierByPriceRange( - \Carrier $carrierObj, - $rangeTable - ) { - $deliveryPriceByRange = \Carrier::getDeliveryPriceByRanges($rangeTable, (int) $carrierObj->id); + $this->query + ->where('c.id_carrier IN(' . implode(',', array_map('intval', $contentIds)) . ')') + ->limit($limit); - $filteredRanges = []; - foreach ($deliveryPriceByRange as $range) { - $filteredRanges[$range['id_range_price']]['id_range_price'] = $range['id_range_price']; - $filteredRanges[$range['id_range_price']]['id_carrier'] = $range['id_carrier']; - $filteredRanges[$range['id_range_price']]['zones'][$range['id_zone']]['id_zone'] = $range['id_zone']; - $filteredRanges[$range['id_range_price']]['zones'][$range['id_zone']]['price'] = $range['price']; - } - - return $filteredRanges; - } - - /** - * @param \Carrier $carrierObj - * @param string $rangeTable - * - * @return array - */ - private function getCarrierByWeightRange( - \Carrier $carrierObj, - $rangeTable - ) { - $deliveryPriceByRange = \Carrier::getDeliveryPriceByRanges($rangeTable, (int) $carrierObj->id); - - $filteredRanges = []; - foreach ($deliveryPriceByRange as $range) { - $filteredRanges[$range['id_range_weight']]['id_range_weight'] = $range['id_range_weight']; - $filteredRanges[$range['id_range_weight']]['id_carrier'] = $range['id_carrier']; - $filteredRanges[$range['id_range_weight']]['zones'][$range['id_zone']]['id_zone'] = $range['id_zone']; - $filteredRanges[$range['id_range_weight']]['zones'][$range['id_zone']]['price'] = $range['price']; - } - - return $filteredRanges; + return $this->runQuery($debug); } /** * @param int $offset - * @param int $limit - * @param int $langId - * - * @return \DbQuery - */ - private function getAllCarriersQuery($offset, $limit, $langId) - { - $query = new \DbQuery(); - $query->from('carrier', 'c'); - $query->select('c.id_carrier'); - $query->leftJoin('carrier_lang', 'cl', 'cl.id_carrier = c.id_carrier AND cl.id_lang = ' . (int) $langId); - $query->leftJoin('carrier_shop', 'cs', 'cs.id_carrier = c.id_carrier'); - $query->where('cs.id_shop = ' . $this->shopId); - $query->where('deleted=0'); - $query->limit($limit, $offset); - - return $query; - } - - /** - * @param string $type * @param string $langIso - * - * @return array|bool|\mysqli_result|\PDOStatement|resource|null - * - * @throws \PrestaShopDatabaseException - */ - public function getShippingIncremental($type, $langIso) - { - $query = new \DbQuery(); - $query->from(IncrementalSyncRepository::INCREMENTAL_SYNC_TABLE, 'aic'); - $query->leftJoin(EventbusSyncRepository::TYPE_SYNC_TABLE_NAME, 'ts', 'ts.type = aic.type'); - $query->where('aic.type = "' . pSQL($type) . '"'); - $query->where('ts.id_shop = ' . $this->shopId); - $query->where('ts.lang_iso = "' . pSQL($langIso) . '"'); - - return $this->db->executeS($query); - } - - /** - * @param array $deliveryPriceByRange - * - * @return false|\RangeWeight|\RangePrice - * - * @throws \PrestaShopDatabaseException - * @throws \PrestaShopException - */ - public function getCarrierRange($deliveryPriceByRange) - { - if (isset($deliveryPriceByRange['id_range_weight'])) { - return new \RangeWeight($deliveryPriceByRange['id_range_weight']); - } - if (isset($deliveryPriceByRange['id_range_price'])) { - return new \RangePrice($deliveryPriceByRange['id_range_price']); - } - - return false; - } - - /** - * @param int[] $carrierIds - * @param int $langId - * - * @return array|bool|\mysqli_result|\PDOStatement|resource|null - * - * @throws \PrestaShopDatabaseException - */ - public function getCarrierProperties($carrierIds, $langId) - { - if (!$carrierIds) { - return []; - } - $query = new \DbQuery(); - $query->from('carrier', 'c'); - $query->select('c.*, cl.delay'); - $query->leftJoin('carrier_lang', 'cl', 'cl.id_carrier = c.id_carrier AND cl.id_lang = ' . (int) $langId); - $query->leftJoin('carrier_shop', 'cs', 'cs.id_carrier = c.id_carrier'); - $query->where('c.id_carrier IN (' . implode(',', array_map('intval', $carrierIds)) . ')'); - $query->where('cs.id_shop = ' . $this->shopId); - - return $this->db->executeS($query); - } - - /** - * @param int $offset - * @param int $limit - * @param int $langId - * - * @return array|bool|\mysqli_result|\PDOStatement|resource|null - * - * @throws \PrestaShopDatabaseException - */ - public function getAllCarrierProperties($offset, $limit, $langId) - { - return $this->db->executeS($this->getAllCarriersQuery($offset, $limit, $langId)); - } - - /** - * @param int $offset - * @param int $langId + * @param bool $debug * * @return int * - * @throws \PrestaShopDatabaseException + * @throws PrestaShopException + * @throws PrestaShopDatabaseException */ - public function getRemainingCarriersCount($offset, $langId) + public function countFullSyncContentLeft($offset, $langIso, $debug) { - $carriers = $this->getAllCarrierProperties($offset, 1, $langId); + $result = $this->getContentsForFull($offset, 1, $langIso, $debug); - if (!is_array($carriers) || empty($carriers)) { + if (!is_array($result) || empty($result)) { return 0; } - return count($carriers); - } - - /** - * @param int $offset - * @param int $limit - * @param int $langId - * - * @return array - * - * @throws \PrestaShopDatabaseException - */ - public function getQueryForDebug($offset, $limit, $langId) - { - $query = $this->getAllCarriersQuery($offset, $limit, $langId); - $queryStringified = preg_replace('/\s+/', ' ', $query->build()); - - return array_merge( - (array) $query, - ['queryStringified' => $queryStringified] - ); + return count($result); } } diff --git a/src/Service/ShopContent/CarriersService.php b/src/Service/ShopContent/CarriersService.php new file mode 100644 index 00000000..42a9daca --- /dev/null +++ b/src/Service/ShopContent/CarriersService.php @@ -0,0 +1,123 @@ +carrierRepository = $carrierRepository; + $this->configurationRepository = $configurationRepository; + $this->carrierBuilder = $carrierBuilder; + $this->languageRepository = $languageRepository; + } + + /** + * @param int $offset + * @param int $limit + * @param string $langIso + * @param bool $debug + * + * @return array + */ + public function getContentsForFull($offset, $limit, $langIso, $debug) + { + $currency = new Currency((int) $this->configurationRepository->get('PS_CURRENCY_DEFAULT')); + + /** @var array $carriers */ + $carriers = $this->carrierRepository->getContentsForFull($offset, $limit, $langIso, $debug); + + /** @var string $psWeightUnit */ + $psWeightUnit = $this->configurationRepository->get('PS_WEIGHT_UNIT'); + + /** @var EventBusCarrier[] $eventBusCarriers */ + $eventBusCarriers = $this->carrierBuilder->buildCarriers( + $carriers, + $langIso, + $currency, + $psWeightUnit + ); + + return array_map(function ($item) { + return [ + 'id' => $item['id_carrier'], + 'collection' => Config::COLLECTION_CARRIERS, + 'properties' => $item, + ]; + }, $eventBusCarriers); + } + + /** + * @param int $limit + * @param array $contentIds + * @param string $langIso + * @param bool $debug + * + * @return array + */ + public function getContentsForIncremental($limit, $contentIds, $langIso, $debug) + { + $result = $this->carrierRepository->getContentsForIncremental($limit, $contentIds, $langIso, $debug); + + if (empty($result)) { + return []; + } + + $currency = new \Currency((int) $this->configurationRepository->get('PS_CURRENCY_DEFAULT')); + + /** @var string $psWeightUnit */ + $psWeightUnit = $this->configurationRepository->get('PS_WEIGHT_UNIT'); + + /** @var EventBusCarrier[] $eventBusCarriers */ + $eventBusCarriers = $this->carrierBuilder->buildCarriers( + $result, + $langIso, + $currency, + $psWeightUnit + ); + + return array_map(function ($item) { + return [ + 'id' => $item['id_carrier'], + 'collection' => Config::COLLECTION_CARRIERS, + 'properties' => $item, + ]; + }, $eventBusCarriers); + } + + /** + * @param int $offset + * @param string $langIso + * @param bool $debug + * + * @return int + */ + public function countFullSyncContentLeft($offset, $langIso, $debug) + { + return (int) $this->carrierRepository->countFullSyncContentLeft($offset, $langIso, $debug); + } +} From b161289e791daf084c92813656db77360de342a3 Mon Sep 17 00:00:00 2001 From: "John.R" Date: Fri, 6 Sep 2024 17:17:45 +0200 Subject: [PATCH 3/5] feat: add carriers --- config/common/new-repository.yml | 4 + config/common/repository.yml | 6 -- config/front/services.yml | 9 +++ e2e/src/full-sync.spec.ts | 5 +- e2e/src/reject-invalid-job-id.spec.ts | 5 +- src/Builder/CarrierBuilder.php | 10 +-- src/Config/Config.php | 2 + src/DTO/Carrier.php | 81 +++++++-------------- src/Service/ShopContent/CarriersService.php | 5 +- 9 files changed, 52 insertions(+), 75 deletions(-) diff --git a/config/common/new-repository.yml b/config/common/new-repository.yml index 8d64c837..fc336efc 100644 --- a/config/common/new-repository.yml +++ b/config/common/new-repository.yml @@ -14,3 +14,7 @@ services: PrestaShop\Module\PsEventbus\Repository\NewRepository\OrderDetailRepository: class: PrestaShop\Module\PsEventbus\Repository\NewRepository\OrderDetailRepository public: true + + PrestaShop\Module\PsEventbus\Repository\NewRepository\CarrierRepository: + class: PrestaShop\Module\PsEventbus\Repository\NewRepository\CarrierRepository + public: true diff --git a/config/common/repository.yml b/config/common/repository.yml index 59fe9882..471dd2c5 100644 --- a/config/common/repository.yml +++ b/config/common/repository.yml @@ -127,12 +127,6 @@ services: arguments: - '@=service("prestashop.adapter.legacy.context").getContext()' - PrestaShop\Module\PsEventbus\Repository\CarrierRepository: - class: PrestaShop\Module\PsEventbus\Repository\CarrierRepository - public: true - arguments: - - '@=service("prestashop.adapter.legacy.context").getContext()' - PrestaShop\Module\PsEventbus\Repository\CustomPriceRepository: class: PrestaShop\Module\PsEventbus\Repository\CustomPriceRepository public: true diff --git a/config/front/services.yml b/config/front/services.yml index 57c26aba..e1bcabe4 100644 --- a/config/front/services.yml +++ b/config/front/services.yml @@ -78,3 +78,12 @@ services: public: true arguments: - '@PrestaShop\Module\PsEventbus\Repository\NewRepository\OrderDetailRepository' + + PrestaShop\Module\PsEventbus\Service\ShopContent\CarriersService: + class: PrestaShop\Module\PsEventbus\Service\ShopContent\CarriersService + public: true + arguments: + - '@PrestaShop\Module\PsEventbus\Repository\NewRepository\CarrierRepository' + - '@PrestaShop\Module\PsEventbus\Repository\ConfigurationRepository' + - '@PrestaShop\Module\PsEventbus\Builder\CarrierBuilder' + - '@PrestaShop\Module\PsEventbus\Repository\LanguageRepository' diff --git a/e2e/src/full-sync.spec.ts b/e2e/src/full-sync.spec.ts index 4ec84c0b..6a3f4e23 100644 --- a/e2e/src/full-sync.spec.ts +++ b/e2e/src/full-sync.spec.ts @@ -50,7 +50,7 @@ const specialFieldAssert: { [index: string]: (val) => void } = { } describe('Full Sync', () => { - let testIndex = 0; + let testTimestamp = 0; // gérer les cas ou un shopContent n'existe pas (pas de fixture du coup) const shopContents: ShopContent[] = shopContentList.filter( @@ -60,7 +60,8 @@ describe('Full Sync', () => { let jobId: string; beforeEach(() => { - jobId = `valid-job-full-${testIndex++}`; + testTimestamp = Date.now(); + jobId = `valid-job-full-${testTimestamp}`; }); // TODO : some versions of prestashop include ps_facebook out of the box, this test can't reliably be run for all versions diff --git a/e2e/src/reject-invalid-job-id.spec.ts b/e2e/src/reject-invalid-job-id.spec.ts index 807e133f..a0aee8f4 100644 --- a/e2e/src/reject-invalid-job-id.spec.ts +++ b/e2e/src/reject-invalid-job-id.spec.ts @@ -6,14 +6,15 @@ import {probe} from "./helpers/mock-probe"; import { ShopContent, shopContentList } from "./helpers/shop-contents"; describe('Reject invalid job-id', () => { - let testIndex = 0; + let testTimestamp = 0; const shopContents: ShopContent[] = shopContentList let jobId: string; beforeEach(() => { - jobId = `invalid-job-id-${testIndex++}` + testTimestamp = Date.now(); + jobId = `invalid-job-id-${testTimestamp}` }); it.each(shopContents)(`%s should return 454 with an invalid job id (sync-api status 454)`, async (shopContent) => { diff --git a/src/Builder/CarrierBuilder.php b/src/Builder/CarrierBuilder.php index dd8b662a..a5d6a09d 100644 --- a/src/Builder/CarrierBuilder.php +++ b/src/Builder/CarrierBuilder.php @@ -67,15 +67,11 @@ public function buildCarriers($carriers, $langIso, \Currency $currency, $weightU ); } - $formattedCarriers = []; /** @var EventBusCarrier $eventBusCarrier */ - foreach ($eventBusCarriers as $eventBusCarrier) { + return array_map(function ($eventBusCarrier) { /** @var array $eventBusCarrierSerialized */ - $eventBusCarrierSerialized = $eventBusCarrier->jsonSerialize(); - $formattedCarriers = array_merge($formattedCarriers, $eventBusCarrierSerialized); - } - - return $formattedCarriers; + return $eventBusCarrier->jsonSerialize(); + }, $eventBusCarriers); } /** diff --git a/src/Config/Config.php b/src/Config/Config.php index 39ad3e95..788f15da 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -34,6 +34,7 @@ class Config const COLLECTION_CARRIERS = 'carriers'; const COLLECTION_CARRIER_DETAILS = 'carrier_details'; + CONST COLLECTION_CARRIER_TAXES = 'carrier_taxes'; const COLLECTION_CARTS = 'carts'; const COLLECTION_CART_PRODUCTS = 'cart_products'; const COLLECTION_CART_RULES = 'cart_rules'; @@ -73,6 +74,7 @@ class Config const SHOP_CONTENTS = [ self::COLLECTION_CARRIERS, self::COLLECTION_CARRIER_DETAILS, + self::COLLECTION_CARRIER_TAXES, self::COLLECTION_CARTS, self::COLLECTION_CART_PRODUCTS, self::COLLECTION_CART_RULES, diff --git a/src/DTO/Carrier.php b/src/DTO/Carrier.php index 7f8e5976..db6ec260 100644 --- a/src/DTO/Carrier.php +++ b/src/DTO/Carrier.php @@ -4,11 +4,6 @@ class Carrier implements \JsonSerializable { - /** - * @var string - */ - private $collection = 'carriers'; - /** * @var int */ @@ -139,14 +134,6 @@ class Carrier implements \JsonSerializable */ private $carrierTaxes = []; - /** - * @return string - */ - public function getCollection() - { - return $this->collection; - } - /** * @return int */ @@ -683,49 +670,31 @@ public function jsonSerialize() */ error_reporting(E_ALL ^ E_WARNING); - $return = []; - - $return[] = [ - 'collection' => $this->getCollection(), - 'id' => (string) $this->getIdReference(), - 'properties' => [ - 'id_carrier' => (string) $this->getIdCarrier(), - 'id_reference' => (string) $this->getIdReference(), - 'name' => (string) $this->getName(), - 'carrier_taxes_rates_group_id' => (string) $this->getTaxesRatesGroupId(), - 'url' => (string) $this->getUrl(), - 'active' => (bool) $this->isActive(), - 'deleted' => (bool) $this->isDeleted(), - 'shipping_handling' => (float) $this->getShippingHandling(), - 'free_shipping_starts_at_price' => (float) $this->getFreeShippingStartsAtPrice(), - 'free_shipping_starts_at_weight' => (float) $this->getFreeShippingStartsAtWeight(), - 'disable_carrier_when_out_of_range' => (bool) $this->isDisableCarrierWhenOutOfRange(), - 'is_module' => (bool) $this->isModule(), - 'is_free' => (bool) $this->isFree(), - 'shipping_external' => (bool) $this->isShippingExternal(), - 'need_range' => (bool) $this->isNeedRange(), - 'external_module_name' => (string) $this->getExternalModuleName(), - 'max_width' => (float) $this->getMaxWidth(), - 'max_height' => (float) $this->getMaxHeight(), - 'max_depth' => (float) $this->getMaxDepth(), - 'max_weight' => (float) $this->getMaxWeight(), - 'grade' => (int) $this->getGrade(), - 'delay' => (string) $this->getDelay(), - 'currency' => (string) $this->getCurrency(), - 'weight_unit' => (string) $this->getWeightUnit(), - ], + return [ + 'id_carrier' => (string) $this->getIdCarrier(), + 'id_reference' => (string) $this->getIdReference(), + 'name' => (string) $this->getName(), + 'carrier_taxes_rates_group_id' => (string) $this->getTaxesRatesGroupId(), + 'url' => (string) $this->getUrl(), + 'active' => (bool) $this->isActive(), + 'deleted' => (bool) $this->isDeleted(), + 'shipping_handling' => (float) $this->getShippingHandling(), + 'free_shipping_starts_at_price' => (float) $this->getFreeShippingStartsAtPrice(), + 'free_shipping_starts_at_weight' => (float) $this->getFreeShippingStartsAtWeight(), + 'disable_carrier_when_out_of_range' => (bool) $this->isDisableCarrierWhenOutOfRange(), + 'is_module' => (bool) $this->isModule(), + 'is_free' => (bool) $this->isFree(), + 'shipping_external' => (bool) $this->isShippingExternal(), + 'need_range' => (bool) $this->isNeedRange(), + 'external_module_name' => (string) $this->getExternalModuleName(), + 'max_width' => (float) $this->getMaxWidth(), + 'max_height' => (float) $this->getMaxHeight(), + 'max_depth' => (float) $this->getMaxDepth(), + 'max_weight' => (float) $this->getMaxWeight(), + 'grade' => (int) $this->getGrade(), + 'delay' => (string) $this->getDelay(), + 'currency' => (string) $this->getCurrency(), + 'weight_unit' => (string) $this->getWeightUnit() ]; - - $carrierDetails = []; - foreach ($this->getCarrierDetails() as $carrierDetail) { - $carrierDetails[] = $carrierDetail->jsonSerialize(); - } - - $carrierTaxRates = []; - foreach ($this->getCarrierTaxes() as $carrierTax) { - $carrierTaxRates[] = $carrierTax->jsonSerialize(); - } - - return array_merge($return, $carrierDetails, $carrierTaxRates); } } diff --git a/src/Service/ShopContent/CarriersService.php b/src/Service/ShopContent/CarriersService.php index 42a9daca..7a02a837 100644 --- a/src/Service/ShopContent/CarriersService.php +++ b/src/Service/ShopContent/CarriersService.php @@ -63,8 +63,9 @@ public function getContentsForFull($offset, $limit, $langIso, $debug) ); return array_map(function ($item) { + return [ - 'id' => $item['id_carrier'], + 'id' => $item['id_reference'], 'collection' => Config::COLLECTION_CARRIERS, 'properties' => $item, ]; @@ -102,7 +103,7 @@ public function getContentsForIncremental($limit, $contentIds, $langIso, $debug) return array_map(function ($item) { return [ - 'id' => $item['id_carrier'], + 'id' => $item['id_reference'], 'collection' => Config::COLLECTION_CARRIERS, 'properties' => $item, ]; From 001746db83c0eac059f489953e1f9a44180a74f6 Mon Sep 17 00:00:00 2001 From: "John.R" Date: Mon, 9 Sep 2024 09:34:10 +0200 Subject: [PATCH 4/5] chore: indent and add comment --- src/Service/ShopContent/CarriersService.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Service/ShopContent/CarriersService.php b/src/Service/ShopContent/CarriersService.php index 7a02a837..c015f02e 100644 --- a/src/Service/ShopContent/CarriersService.php +++ b/src/Service/ShopContent/CarriersService.php @@ -63,7 +63,6 @@ public function getContentsForFull($offset, $limit, $langIso, $debug) ); return array_map(function ($item) { - return [ 'id' => $item['id_reference'], 'collection' => Config::COLLECTION_CARRIERS, From ef0e4240d2c0906a03813df96814f63bbb001627 Mon Sep 17 00:00:00 2001 From: "John.R" Date: Mon, 9 Sep 2024 15:10:13 +0200 Subject: [PATCH 5/5] fix: phpcsfixer --- config/front/services.yml | 1 - src/Builder/CarrierBuilder.php | 21 ++++++----- src/Config/Config.php | 2 +- src/DTO/Carrier.php | 2 +- .../NewRepository/AbstractRepository.php | 27 ++++++-------- .../NewRepository/CarrierRepository.php | 35 ++++++++----------- .../NewRepository/OrderCartRuleRepository.php | 20 +++++------ .../NewRepository/OrderDetailRepository.php | 27 ++++++-------- .../NewRepository/OrderHistoryRepository.php | 24 ++++++------- .../NewRepository/OrderRepository.php | 20 +++++------ .../NewRepository/RepositoryInterface.php | 4 +-- src/Service/HealthCheckService.php | 7 ++-- src/Service/ShopContent/CarriersService.php | 14 ++------ src/Service/SynchronizationService.php | 13 +++---- src/Traits/UseHooks.php | 9 +++++ 15 files changed, 95 insertions(+), 131 deletions(-) diff --git a/config/front/services.yml b/config/front/services.yml index e1bcabe4..4f02827a 100644 --- a/config/front/services.yml +++ b/config/front/services.yml @@ -86,4 +86,3 @@ services: - '@PrestaShop\Module\PsEventbus\Repository\NewRepository\CarrierRepository' - '@PrestaShop\Module\PsEventbus\Repository\ConfigurationRepository' - '@PrestaShop\Module\PsEventbus\Builder\CarrierBuilder' - - '@PrestaShop\Module\PsEventbus\Repository\LanguageRepository' diff --git a/src/Builder/CarrierBuilder.php b/src/Builder/CarrierBuilder.php index a5d6a09d..63ba7a62 100644 --- a/src/Builder/CarrierBuilder.php +++ b/src/Builder/CarrierBuilder.php @@ -5,12 +5,13 @@ use PrestaShop\Module\PsEventbus\DTO\Carrier as EventBusCarrier; use PrestaShop\Module\PsEventbus\DTO\CarrierDetail; use PrestaShop\Module\PsEventbus\DTO\CarrierTax; -use PrestaShop\Module\PsEventbus\Repository\CarrierRepository; use PrestaShop\Module\PsEventbus\Repository\ConfigurationRepository; use PrestaShop\Module\PsEventbus\Repository\CountryRepository; use PrestaShop\Module\PsEventbus\Repository\LanguageRepository; use PrestaShop\Module\PsEventbus\Repository\StateRepository; use PrestaShop\Module\PsEventbus\Repository\TaxRepository; +use PrestaShopDatabaseException; +use PrestaShopException; class CarrierBuilder { @@ -45,14 +46,14 @@ public function __construct( /** * @param array $carriers - * @param int $langIso + * @param string $langIso * @param \Currency $currency * @param string $weightUnit * * @return array * - * @@throws \PrestaShopDatabaseException - * @@throws \PrestaShopException + * @@throws PrestaShopDatabaseException + * @@throws PrestaShopException */ public function buildCarriers($carriers, $langIso, \Currency $currency, $weightUnit) { @@ -67,9 +68,7 @@ public function buildCarriers($carriers, $langIso, \Currency $currency, $weightU ); } - /** @var EventBusCarrier $eventBusCarrier */ return array_map(function ($eventBusCarrier) { - /** @var array $eventBusCarrierSerialized */ return $eventBusCarrier->jsonSerialize(); }, $eventBusCarriers); } @@ -81,8 +80,8 @@ public function buildCarriers($carriers, $langIso, \Currency $currency, $weightU * * @return EventBusCarrier * - * @@throws \PrestaShopDatabaseException - * @@throws \PrestaShopException + * @@throws PrestaShopDatabaseException + * @@throws PrestaShopException */ public function buildCarrier(\Carrier $carrier, $currencyIsoCode, $weightUnit) { @@ -151,7 +150,7 @@ public function buildCarrier(\Carrier $carrier, $currencyIsoCode, $weightUnit) return $eventBusCarrier; } - /** + /** * @param \Carrier $carrierObj * * @return array|false @@ -242,7 +241,7 @@ public function getCarrierRange($deliveryPriceByRange) * * @return false|CarrierDetail * - * @@throws \PrestaShopDatabaseException + * @@throws PrestaShopDatabaseException */ private function buildCarrierDetails(\Carrier $carrier, $range, $zone) { @@ -279,7 +278,7 @@ private function buildCarrierDetails(\Carrier $carrier, $range, $zone) * * @return CarrierTax|null * - * @@throws \PrestaShopDatabaseException + * @@throws PrestaShopDatabaseException */ private function buildCarrierTaxes(\Carrier $carrier, $zoneId, $rangeId) { diff --git a/src/Config/Config.php b/src/Config/Config.php index 788f15da..8ddb35a8 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -34,7 +34,7 @@ class Config const COLLECTION_CARRIERS = 'carriers'; const COLLECTION_CARRIER_DETAILS = 'carrier_details'; - CONST COLLECTION_CARRIER_TAXES = 'carrier_taxes'; + const COLLECTION_CARRIER_TAXES = 'carrier_taxes'; const COLLECTION_CARTS = 'carts'; const COLLECTION_CART_PRODUCTS = 'cart_products'; const COLLECTION_CART_RULES = 'cart_rules'; diff --git a/src/DTO/Carrier.php b/src/DTO/Carrier.php index db6ec260..8d86b337 100644 --- a/src/DTO/Carrier.php +++ b/src/DTO/Carrier.php @@ -694,7 +694,7 @@ public function jsonSerialize() 'grade' => (int) $this->getGrade(), 'delay' => (string) $this->getDelay(), 'currency' => (string) $this->getCurrency(), - 'weight_unit' => (string) $this->getWeightUnit() + 'weight_unit' => (string) $this->getWeightUnit(), ]; } } diff --git a/src/Repository/NewRepository/AbstractRepository.php b/src/Repository/NewRepository/AbstractRepository.php index e941c0a2..a54de804 100644 --- a/src/Repository/NewRepository/AbstractRepository.php +++ b/src/Repository/NewRepository/AbstractRepository.php @@ -3,50 +3,45 @@ namespace PrestaShop\Module\PsEventbus\Repository\NewRepository; use PrestaShop\Module\PsEventbus\Service\CommonService; -use PrestaShopException; -use PrestaShopDatabaseException; -use Db; -use Context; -use DbQuery; abstract class AbstractRepository { /** - * @var Context + * @var \Context */ private $context; /** - * @var Db + * @var \Db */ private $db; /** - * @var DbQuery + * @var \DbQuery */ protected $query; public function __construct() { - $context = Context::getContext(); + $context = \Context::getContext(); if ($context == null) { - throw new PrestaShopException('Context not found'); + throw new \PrestaShopException('Context not found'); } $this->context = $context; - $this->db = Db::getInstance(); + $this->db = \Db::getInstance(); } /** * @return int * - * @throws PrestaShopException + * @throws \PrestaShopException */ public function getShopId() { if ($this->context->shop === null) { - throw new PrestaShopException('No shop context'); + throw new \PrestaShopException('No shop context'); } return (int) $this->context->shop->id; @@ -57,8 +52,8 @@ public function getShopId() * * @return array * - * @throws PrestaShopException - * @throws PrestaShopDatabaseException + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException */ protected function runQuery($debug) { @@ -74,7 +69,7 @@ protected function runQuery($debug) /** * @return void * - * @throws PrestaShopException + * @throws \PrestaShopException */ private function debugQuery() { diff --git a/src/Repository/NewRepository/CarrierRepository.php b/src/Repository/NewRepository/CarrierRepository.php index 4bc83709..27bd0d59 100644 --- a/src/Repository/NewRepository/CarrierRepository.php +++ b/src/Repository/NewRepository/CarrierRepository.php @@ -2,11 +2,6 @@ namespace PrestaShop\Module\PsEventbus\Repository\NewRepository; -use Context; -use DbQuery; -use Language; -use PrestaShopException; - class CarrierRepository extends AbstractRepository implements RepositoryInterface { const TABLE_NAME = 'carrier'; @@ -16,24 +11,24 @@ class CarrierRepository extends AbstractRepository implements RepositoryInterfac * * @return mixed * - * @throws PrestaShopException + * @throws \PrestaShopException */ public function generateBaseQuery($langIso) - { - $langId = (int) Language::getIdByIso($langIso); - $context = Context::getContext(); + { + $langId = (int) \Language::getIdByIso($langIso); + $context = \Context::getContext(); if ($context === null) { - throw new PrestaShopException('Context is null'); + throw new \PrestaShopException('Context is null'); } if ($context->shop === null) { - throw new PrestaShopException('No shop context'); + throw new \PrestaShopException('No shop context'); } - $this->query = new DbQuery(); + $this->query = new \DbQuery(); - $this->query->from('carrier', 'c') + $this->query->from('carrier', 'c') ->leftJoin('carrier_lang', 'cl', 'cl.id_carrier = c.id_carrier AND cl.id_lang = ' . $langId) ->leftJoin('carrier_shop', 'cs', 'cs.id_carrier = c.id_carrier') ->where('cs.id_shop = ' . $context->shop->id) @@ -42,7 +37,7 @@ public function generateBaseQuery($langIso) $this->query->select('c.*'); } - + /** * @param int $offset * @param int $limit @@ -51,8 +46,8 @@ public function generateBaseQuery($langIso) * * @return array * - * @throws PrestaShopException - * @throws PrestaShopDatabaseException + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException */ public function getContentsForFull($offset, $limit, $langIso, $debug) { @@ -71,8 +66,8 @@ public function getContentsForFull($offset, $limit, $langIso, $debug) * * @return array * - * @throws PrestaShopException - * @throws PrestaShopDatabaseException + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException */ public function getContentsForIncremental($limit, $contentIds, $langIso, $debug) { @@ -92,8 +87,8 @@ public function getContentsForIncremental($limit, $contentIds, $langIso, $debug) * * @return int * - * @throws PrestaShopException - * @throws PrestaShopDatabaseException + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException */ public function countFullSyncContentLeft($offset, $langIso, $debug) { diff --git a/src/Repository/NewRepository/OrderCartRuleRepository.php b/src/Repository/NewRepository/OrderCartRuleRepository.php index b5d0b84b..b7cfe543 100644 --- a/src/Repository/NewRepository/OrderCartRuleRepository.php +++ b/src/Repository/NewRepository/OrderCartRuleRepository.php @@ -2,10 +2,6 @@ namespace PrestaShop\Module\PsEventbus\Repository\NewRepository; -use PrestaShopException; -use PrestaShopDatabaseException; -use DbQuery; - class OrderCartRuleRepository extends AbstractRepository implements RepositoryInterface { const TABLE_NAME = 'order_cart_rule'; @@ -15,11 +11,11 @@ class OrderCartRuleRepository extends AbstractRepository implements RepositoryIn * * @return mixed * - * @throws PrestaShopException + * @throws \PrestaShopException */ public function generateBaseQuery($langIso) { - $this->query = new DbQuery(); + $this->query = new \DbQuery(); $this->query ->from(self::TABLE_NAME, 'ocr'); @@ -47,8 +43,8 @@ public function generateBaseQuery($langIso) * * @return array * - * @throws PrestaShopException - * @throws PrestaShopDatabaseException + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException */ public function getContentsForFull($offset, $limit, $langIso, $debug) { @@ -67,8 +63,8 @@ public function getContentsForFull($offset, $limit, $langIso, $debug) * * @return array * - * @throws PrestaShopException - * @throws PrestaShopDatabaseException + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException */ public function getContentsForIncremental($limit, $contentIds, $langIso, $debug) { @@ -88,8 +84,8 @@ public function getContentsForIncremental($limit, $contentIds, $langIso, $debug) * * @return int * - * @throws PrestaShopException - * @throws PrestaShopDatabaseException + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException */ public function countFullSyncContentLeft($offset, $langIso, $debug) { diff --git a/src/Repository/NewRepository/OrderDetailRepository.php b/src/Repository/NewRepository/OrderDetailRepository.php index ad7aa803..9803b38c 100644 --- a/src/Repository/NewRepository/OrderDetailRepository.php +++ b/src/Repository/NewRepository/OrderDetailRepository.php @@ -2,11 +2,6 @@ namespace PrestaShop\Module\PsEventbus\Repository\NewRepository; -use PrestaShopException; -use PrestaShopDatabaseException; -use Context; -use DbQuery; - class OrderDetailRepository extends AbstractRepository implements RepositoryInterface { const TABLE_NAME = 'order_detail'; @@ -16,21 +11,21 @@ class OrderDetailRepository extends AbstractRepository implements RepositoryInte * * @return mixed * - * @throws PrestaShopException + * @throws \PrestaShopException */ public function generateBaseQuery($langIso) { - $context = Context::getContext(); + $context = \Context::getContext(); if ($context === null) { - throw new PrestaShopException('Context is null'); + throw new \PrestaShopException('Context is null'); } if ($context->shop === null) { - throw new PrestaShopException('No shop context'); + throw new \PrestaShopException('No shop context'); } - $this->query = new DbQuery(); + $this->query = new \DbQuery(); $this->query ->from(self::TABLE_NAME, 'od') @@ -68,8 +63,8 @@ public function generateBaseQuery($langIso) * * @return array * - * @throws PrestaShopException - * @throws PrestaShopDatabaseException + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException */ public function getContentsForFull($offset, $limit, $langIso, $debug) { @@ -88,8 +83,8 @@ public function getContentsForFull($offset, $limit, $langIso, $debug) * * @return array * - * @throws PrestaShopException - * @throws PrestaShopDatabaseException + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException */ public function getContentsForIncremental($limit, $contentIds, $langIso, $debug) { @@ -110,8 +105,8 @@ public function getContentsForIncremental($limit, $contentIds, $langIso, $debug) * * @return int * - * @throws PrestaShopException - * @throws PrestaShopDatabaseException + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException */ public function countFullSyncContentLeft($offset, $langIso, $debug) { diff --git a/src/Repository/NewRepository/OrderHistoryRepository.php b/src/Repository/NewRepository/OrderHistoryRepository.php index d1652088..dcb742d0 100644 --- a/src/Repository/NewRepository/OrderHistoryRepository.php +++ b/src/Repository/NewRepository/OrderHistoryRepository.php @@ -2,10 +2,6 @@ namespace PrestaShop\Module\PsEventbus\Repository\NewRepository; -use PrestaShopException; -use PrestaShopDatabaseException; -use Language; -use DbQuery; class OrderHistoryRepository extends AbstractRepository implements RepositoryInterface { const TABLE_NAME = 'order_history'; @@ -15,13 +11,13 @@ class OrderHistoryRepository extends AbstractRepository implements RepositoryInt * * @return mixed * - * @throws PrestaShopException + * @throws \PrestaShopException */ public function generateBaseQuery($langIso) { - $langId = (int) Language::getIdByIso($langIso); + $langId = (int) \Language::getIdByIso($langIso); - $this->query = new DbQuery(); + $this->query = new \DbQuery(); $this->query ->from(self::TABLE_NAME, 'oh') @@ -52,8 +48,8 @@ public function generateBaseQuery($langIso) * * @return array * - * @throws PrestaShopException - * @throws PrestaShopDatabaseException + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException */ public function getContentsForFull($offset, $limit, $langIso, $debug) { @@ -72,8 +68,8 @@ public function getContentsForFull($offset, $limit, $langIso, $debug) * * @return array * - * @throws PrestaShopException - * @throws PrestaShopDatabaseException + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException */ public function getContentsForIncremental($limit, $contentIds, $langIso, $debug) { @@ -94,8 +90,8 @@ public function getContentsForIncremental($limit, $contentIds, $langIso, $debug) * * @return int * - * @throws PrestaShopException - * @throws PrestaShopDatabaseException + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException */ public function countFullSyncContentLeft($offset, $langIso, $debug) { @@ -115,7 +111,7 @@ public function countFullSyncContentLeft($offset, $langIso, $debug) * * @return array * - * @throws PrestaShopDatabaseException + * @throws \PrestaShopDatabaseException */ public function getOrderHistoryIdsByOrderIds($orderIds, $langIso, $debug) { diff --git a/src/Repository/NewRepository/OrderRepository.php b/src/Repository/NewRepository/OrderRepository.php index 6d8daef5..29053013 100644 --- a/src/Repository/NewRepository/OrderRepository.php +++ b/src/Repository/NewRepository/OrderRepository.php @@ -2,10 +2,6 @@ namespace PrestaShop\Module\PsEventbus\Repository\NewRepository; -use PrestaShopException; -use PrestaShopDatabaseException; -use DbQuery; - class OrderRepository extends AbstractRepository implements RepositoryInterface { const TABLE_NAME = 'orders'; @@ -15,11 +11,11 @@ class OrderRepository extends AbstractRepository implements RepositoryInterface * * @return mixed * - * @throws PrestaShopException + * @throws \PrestaShopException */ public function generateBaseQuery($langIso) { - $this->query = new DbQuery(); + $this->query = new \DbQuery(); $this->query ->from(self::TABLE_NAME, 'o') @@ -97,8 +93,8 @@ public function generateBaseQuery($langIso) * * @return array * - * @throws PrestaShopException - * @throws PrestaShopDatabaseException + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException */ public function getContentsForFull($offset, $limit, $langIso, $debug) { @@ -117,8 +113,8 @@ public function getContentsForFull($offset, $limit, $langIso, $debug) * * @return array * - * @throws PrestaShopException - * @throws PrestaShopDatabaseException + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException */ public function getContentsForIncremental($limit, $contentIds, $langIso, $debug) { @@ -139,8 +135,8 @@ public function getContentsForIncremental($limit, $contentIds, $langIso, $debug) * * @return int * - * @throws PrestaShopException - * @throws PrestaShopDatabaseException + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException */ public function countFullSyncContentLeft($offset, $langIso, $debug) { diff --git a/src/Repository/NewRepository/RepositoryInterface.php b/src/Repository/NewRepository/RepositoryInterface.php index 9164716c..d6ec5a21 100644 --- a/src/Repository/NewRepository/RepositoryInterface.php +++ b/src/Repository/NewRepository/RepositoryInterface.php @@ -2,10 +2,8 @@ namespace PrestaShop\Module\PsEventbus\Repository\NewRepository; -use DbQuery; - /** - * @property DbQuery $query + * @property \DbQuery $query */ interface RepositoryInterface { diff --git a/src/Service/HealthCheckService.php b/src/Service/HealthCheckService.php index 3fd3c126..19d0d8d9 100644 --- a/src/Service/HealthCheckService.php +++ b/src/Service/HealthCheckService.php @@ -3,14 +3,13 @@ namespace PrestaShop\Module\PsEventbus\Service; use PrestaShop\Module\PsEventbus\Repository\ServerInformationRepository; -use Ps_eventbus; class HealthCheckService { - /** @var Ps_eventbus */ + /** @var \Ps_eventbus */ private $module; - public function __construct(Ps_eventbus $module) + public function __construct(\Ps_eventbus $module) { $this->module = $module; } @@ -20,7 +19,7 @@ public function __construct(Ps_eventbus $module) * * @return void * - * @throws PrestaShopException + * @throws \PrestaShopException */ public function getHealthCheck($isAuthentified) { diff --git a/src/Service/ShopContent/CarriersService.php b/src/Service/ShopContent/CarriersService.php index c015f02e..da6a8225 100644 --- a/src/Service/ShopContent/CarriersService.php +++ b/src/Service/ShopContent/CarriersService.php @@ -2,13 +2,10 @@ namespace PrestaShop\Module\PsEventbus\Service\ShopContent; -use Currency; use PrestaShop\Module\PsEventbus\Builder\CarrierBuilder; use PrestaShop\Module\PsEventbus\Config\Config; use PrestaShop\Module\PsEventbus\Repository\ConfigurationRepository; -use PrestaShop\Module\PsEventbus\Repository\LanguageRepository; use PrestaShop\Module\PsEventbus\Repository\NewRepository\CarrierRepository; -use PrestaShop\Module\PsEventbus\DTO\Carrier as EventBusCarrier; class CarriersService implements ShopContentServiceInterface { @@ -21,19 +18,14 @@ class CarriersService implements ShopContentServiceInterface /** @var CarrierBuilder */ private $carrierBuilder; - /** @var LanguageRepository */ - private $languageRepository; - public function __construct( CarrierRepository $carrierRepository, ConfigurationRepository $configurationRepository, CarrierBuilder $carrierBuilder, - LanguageRepository $languageRepository ) { $this->carrierRepository = $carrierRepository; $this->configurationRepository = $configurationRepository; $this->carrierBuilder = $carrierBuilder; - $this->languageRepository = $languageRepository; } /** @@ -46,15 +38,14 @@ public function __construct( */ public function getContentsForFull($offset, $limit, $langIso, $debug) { - $currency = new Currency((int) $this->configurationRepository->get('PS_CURRENCY_DEFAULT')); - + $currency = new \Currency((int) $this->configurationRepository->get('PS_CURRENCY_DEFAULT')); + /** @var array $carriers */ $carriers = $this->carrierRepository->getContentsForFull($offset, $limit, $langIso, $debug); /** @var string $psWeightUnit */ $psWeightUnit = $this->configurationRepository->get('PS_WEIGHT_UNIT'); - /** @var EventBusCarrier[] $eventBusCarriers */ $eventBusCarriers = $this->carrierBuilder->buildCarriers( $carriers, $langIso, @@ -92,7 +83,6 @@ public function getContentsForIncremental($limit, $contentIds, $langIso, $debug) /** @var string $psWeightUnit */ $psWeightUnit = $this->configurationRepository->get('PS_WEIGHT_UNIT'); - /** @var EventBusCarrier[] $eventBusCarriers */ $eventBusCarriers = $this->carrierBuilder->buildCarriers( $result, $langIso, diff --git a/src/Service/SynchronizationService.php b/src/Service/SynchronizationService.php index b6a520cc..a7daf7af 100644 --- a/src/Service/SynchronizationService.php +++ b/src/Service/SynchronizationService.php @@ -11,9 +11,6 @@ use PrestaShop\Module\PsEventbus\Repository\LiveSyncRepository; use PrestaShop\Module\PsEventbus\Service\ShopContent\ShopContentServiceInterface; use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; -use Module; -use DateTime; -use DateTimeZone; class SynchronizationService { @@ -92,8 +89,8 @@ public function sendFullSync( $serviceName = str_replace('_', '', ucwords($shopContent, '_')); $serviceId = 'PrestaShop\Module\PsEventbus\Service\ShopContent\\' . $serviceName . 'Service'; // faire un mapping entre le service et le nom du shopcontent - /** @var Ps_eventbus */ - $module = Module::getInstanceByName('ps_eventbus'); + /** @var \Ps_eventbus */ + $module = \Module::getInstanceByName('ps_eventbus'); if (!$module->hasService($serviceId)) { throw new ServiceNotFoundException($serviceId); @@ -106,7 +103,7 @@ public function sendFullSync( $configurationRepository = $module->getService('PrestaShop\Module\PsEventbus\Repository\ConfigurationRepository'); $timezone = (string) $configurationRepository->get('PS_TIMEZONE'); - $dateNow = (new DateTime('now', new DateTimeZone($timezone)))->format(Config::MYSQL_DATE_FORMAT); + $dateNow = (new \DateTime('now', new \DateTimeZone($timezone)))->format(Config::MYSQL_DATE_FORMAT); $data = $shopContentApiService->getContentsForFull($offset, $limit, $langIso, $debug); @@ -157,8 +154,8 @@ public function sendIncrementalSync( $serviceName = str_replace('_', '', ucwords($shopContent, '_')); $serviceId = 'PrestaShop\Module\PsEventbus\Service\ShopContent\\' . $serviceName . 'Service'; - /** @var Ps_eventbus */ - $module = Module::getInstanceByName('ps_eventbus'); + /** @var \Ps_eventbus */ + $module = \Module::getInstanceByName('ps_eventbus'); if (!$module->hasService($serviceId)) { throw new ServiceNotFoundException($serviceId); diff --git a/src/Traits/UseHooks.php b/src/Traits/UseHooks.php index a465a352..db0d0572 100644 --- a/src/Traits/UseHooks.php +++ b/src/Traits/UseHooks.php @@ -1128,6 +1128,9 @@ public function hookActionObjectCarrierAddAfter($parameters) $this->shopId, false ); + + // TODO INSERT INCREMENTAL SYNC AND LIVE SYNC OF CARRIER DETAILS + // TODO INSERT INCREMENTAL SYNC AND LIVE SYNC OF CARRIER TAXES } } @@ -1153,6 +1156,9 @@ public function hookActionObjectCarrierUpdateAfter($parameters) $this->shopId, false ); + + // TODO INSERT INCREMENTAL SYNC AND LIVE SYNC OF CARRIER DETAILS + // TODO INSERT INCREMENTAL SYNC AND LIVE SYNC OF CARRIER TAXES } } @@ -1177,6 +1183,9 @@ public function hookActionObjectCarrierDeleteAfter($parameters) $this->shopId, false ); + + // TODO INSERT INCREMENTAL SYNC AND LIVE SYNC OF CARRIER DETAILS + // TODO INSERT INCREMENTAL SYNC AND LIVE SYNC OF CARRIER TAXES } }