From 0d37c5538c514be40ee8b480e258773ad285d2eb Mon Sep 17 00:00:00 2001 From: "John.R" Date: Thu, 31 Oct 2024 16:21:40 +0100 Subject: [PATCH 01/14] fix: change carrier details --- config/front/services.yml | 4 +- src/Repository/DeliveryRepository.php | 125 ++++++++++++++++ .../ShopContent/CarrierDetailsService.php | 140 ++++++++---------- src/Service/ShopContent/CarriersService.php | 77 ++-------- 4 files changed, 198 insertions(+), 148 deletions(-) create mode 100644 src/Repository/DeliveryRepository.php diff --git a/config/front/services.yml b/config/front/services.yml index 93eb94f4..9f666d0e 100644 --- a/config/front/services.yml +++ b/config/front/services.yml @@ -70,7 +70,9 @@ services: class: PrestaShop\Module\PsEventbus\Service\ShopContent\CarrierDetailsService public: true arguments: - - '@PrestaShop\Module\PsEventbus\Repository\CarrierRepository' + - '@PrestaShop\Module\PsEventbus\Repository\DeliveryRepository' + - '@PrestaShop\Module\PsEventbus\Repository\CountryRepository' + - '@PrestaShop\Module\PsEventbus\Repository\StateRepository' PrestaShop\Module\PsEventbus\Service\ShopContent\CarrierTaxesService: class: PrestaShop\Module\PsEventbus\Service\ShopContent\CarrierTaxesService diff --git a/src/Repository/DeliveryRepository.php b/src/Repository/DeliveryRepository.php new file mode 100644 index 00000000..26569adc --- /dev/null +++ b/src/Repository/DeliveryRepository.php @@ -0,0 +1,125 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) + */ + +namespace PrestaShop\Module\PsEventbus\Repository; + +if (!defined('_PS_VERSION_')) { + exit; +} + +class DeliveryRepository extends AbstractRepository implements RepositoryInterface +{ + const TABLE_NAME = 'delivery'; + + /** + * @param string $langIso + * @param bool $withSelecParameters + * + * @return mixed + * + * @throws \PrestaShopException + */ + public function generateFullQuery($langIso, $withSelecParameters) + { + $this->generateMinimalQuery(self::TABLE_NAME, 'd'); + + if ($withSelecParameters) { + $this->query + ->select('d.id_delivery') + ->select('d.id_carrier') + ->select('d.id_range_price') + ->select('d.id_range_weight') + ->select('d.id_zone') + ->select('d.price') + ; + } + } + + /** + * @param int $offset + * @param int $limit + * @param string $langIso + * + * @return array + * + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException + */ + public function retrieveContentsForFull($offset, $limit, $langIso) + { + $this->generateFullQuery($langIso, true); + + $this->query->limit((int) $limit, (int) $offset); + + return $this->runQuery(); + } + + /** + * @param int $limit + * @param array $contentIds + * @param string $langIso + * + * @return array + * + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException + */ + public function retrieveContentsForIncremental($limit, $contentIds, $langIso) + { + if ($contentIds == []) { + return []; + } + + $this->generateFullQuery($langIso, true); + + $this->query + ->where('d.id_carrier IN(' . implode(',', array_map('intval', $contentIds)) . ')') + ->limit($limit); + + return $this->runQuery(); + } + + /** + * @param int $offset + * @param int $limit + * @param string $langIso + * + * @return int + * + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException + */ + public function countFullSyncContentLeft($offset, $limit, $langIso) + { + $this->generateFullQuery($langIso, false); + + $this->query->select('(COUNT(*) - ' . (int) $offset . ') as count'); + + $result = $this->runQuery(true); + + return $result[0]['count']; + } +} diff --git a/src/Service/ShopContent/CarrierDetailsService.php b/src/Service/ShopContent/CarrierDetailsService.php index 8cdbb1ae..9a8e06c4 100644 --- a/src/Service/ShopContent/CarrierDetailsService.php +++ b/src/Service/ShopContent/CarrierDetailsService.php @@ -27,7 +27,7 @@ namespace PrestaShop\Module\PsEventbus\Service\ShopContent; use PrestaShop\Module\PsEventbus\Config\Config; -use PrestaShop\Module\PsEventbus\Repository\CarrierRepository; +use PrestaShop\Module\PsEventbus\Repository\DeliveryRepository; use PrestaShop\Module\PsEventbus\Repository\CountryRepository; use PrestaShop\Module\PsEventbus\Repository\StateRepository; @@ -37,12 +37,23 @@ class CarrierDetailsService extends ShopContentAbstractService implements ShopContentServiceInterface { - /** @var CarrierRepository */ - private $carrierRepository; - - public function __construct(CarrierRepository $carrierRepository) - { - $this->carrierRepository = $carrierRepository; + /** @var DeliveryRepository */ + private $deliveryRepository; + + /** @var CountryRepository */ + private $countryRepository; + + /** @var StateRepository */ + private $stateRepository; + + public function __construct( + DeliveryRepository $deliveryRepository, + CountryRepository $countryRepository, + StateRepository $stateRepository + ) { + $this->deliveryRepository = $deliveryRepository; + $this->countryRepository = $countryRepository; + $this->stateRepository = $stateRepository; } /** @@ -54,16 +65,16 @@ public function __construct(CarrierRepository $carrierRepository) */ public function getContentsForFull($offset, $limit, $langIso) { - $result = $this->carrierRepository->retrieveContentsForFull($offset, $limit, $langIso); + $result = $this->deliveryRepository->retrieveContentsForFull($offset, $limit, $langIso); - if (empty($result)) { + if (!empty($result)) { return []; } $carrierDetails = []; - foreach ($result as $carrierData) { - $carrierDetails = array_merge($carrierDetails, $this->buildCarrierDetails($carrierData)); + foreach ($result as $delivery) { + $carrierDetails[] = $this->buildCarrierDetail($delivery); } $this->castCarrierDetails($carrierDetails); @@ -87,13 +98,13 @@ public function getContentsForFull($offset, $limit, $langIso) */ public function getContentsForIncremental($limit, $upsertedContents, $deletedContents, $langIso) { - $result = $this->carrierRepository->retrieveContentsForIncremental($limit, array_column($upsertedContents, 'id'), $langIso); + $result = $this->deliveryRepository->retrieveContentsForIncremental($limit, array_column($upsertedContents, 'id'), $langIso); if (!empty($result)) { $carrierDetails = []; - foreach ($result as $carrierData) { - $carrierDetails = array_merge($carrierDetails, $this->buildCarrierDetails($carrierData)); + foreach ($result as $delivery) { + $carrierDetails[] = $this->buildCarrierDetail($delivery); } $this->castCarrierDetails($carrierDetails); @@ -111,7 +122,42 @@ public function getContentsForIncremental($limit, $upsertedContents, $deletedCon */ public function getFullSyncContentLeft($offset, $limit, $langIso) { - return $this->carrierRepository->countFullSyncContentLeft($offset, $limit, $langIso); + return $this->deliveryRepository->countFullSyncContentLeft($offset, $limit, $langIso); + } + + /** + * Build a CarrierDetail from delvery data + * + * @param array $delivery + * + * @return array + * + * @throws \PrestaShopDatabaseException + * @throws \PrestaShopException + */ + private function buildCarrierDetail($delivery) + { + $carrier = new \Carrier($delivery['id_carrier']); + $range = CarriersService::generateRange($carrier, $delivery); + + /** @var array $countryIsoCodes */ + $countryIsoCodes = $this->countryRepository->getCountryIsoCodesByZoneId($delivery['id_zone'], true); + + /** @var array $stateIsoCodes */ + $stateIsoCodes = $this->stateRepository->getStateIsoCodesByZoneId($delivery['id_zone'], true); + + return [ + 'id_reference' => $carrier->id_reference, + 'id_zone' => $delivery['id_zone'], + 'id_range' => $delivery['id_range'], + 'id_carrier_detail' => $delivery['id_delivery'], + 'shipping_method' => $carrier->getRangeTable(), + 'delimiter1' => $range->delimiter1, + 'delimiter2' => $range->delimiter2, + 'country_ids' => implode(',', $countryIsoCodes), + 'state_ids' => implode(',', $stateIsoCodes), + 'price' => $delivery['price'], + ]; } /** @@ -134,68 +180,4 @@ private function castCarrierDetails(&$carrierDetails) $carrierDetail['price'] = (float) $carrierDetail['price']; } } - - /** - * Build a CarrierDetail from Carrier data - * - * @param array $carrierData - * - * @return array - * - * @throws \PrestaShopDatabaseException - * @throws \PrestaShopException - */ - private function buildCarrierDetails($carrierData) - { - /** @var \Ps_eventbus $module */ - $module = \Module::getInstanceByName('ps_eventbus'); - - /** @var CountryRepository $countryRepository */ - $countryRepository = $module->getService('PrestaShop\Module\PsEventbus\Repository\CountryRepository'); - - /** @var StateRepository $stateRepository */ - $stateRepository = $module->getService('PrestaShop\Module\PsEventbus\Repository\StateRepository'); - - $carrier = new \Carrier($carrierData['id_reference']); - - $deliveryPriceByRanges = CarriersService::getDeliveryPriceByRange($carrier); - - if (!$deliveryPriceByRanges) { - return []; - } - - $carrierDetails = []; - - foreach ($deliveryPriceByRanges as $deliveryPriceByRange) { - $range = CarriersService::getCarrierRange($deliveryPriceByRange); - - if (!$range) { - continue; - } - - foreach ($deliveryPriceByRange['zones'] as $zone) { - /** @var array $countryIsoCodes */ - $countryIsoCodes = $countryRepository->getCountryIsoCodesByZoneId($zone['id_zone'], true); - - /** @var array $stateIsoCodes */ - $stateIsoCodes = $stateRepository->getStateIsoCodesByZoneId($zone['id_zone'], true); - - $carrierDetail = []; - $carrierDetail['id_reference'] = $carrier->id_reference; - $carrierDetail['id_zone'] = $zone['id_zone']; - $carrierDetail['id_range'] = $range->id; - $carrierDetail['id_carrier_detail'] = $range->id; - $carrierDetail['shipping_method'] = $carrier->getRangeTable(); - $carrierDetail['delimiter1'] = $range->delimiter1; - $carrierDetail['delimiter2'] = $range->delimiter2; - $carrierDetail['country_ids'] = implode(',', $countryIsoCodes); - $carrierDetail['state_ids'] = implode(',', $stateIsoCodes); - $carrierDetail['price'] = $zone['price']; - - array_push($carrierDetails, $carrierDetail); - } - } - - return $carrierDetails; - } } diff --git a/src/Service/ShopContent/CarriersService.php b/src/Service/ShopContent/CarriersService.php index 129363a8..f59b7065 100644 --- a/src/Service/ShopContent/CarriersService.php +++ b/src/Service/ShopContent/CarriersService.php @@ -101,86 +101,27 @@ public function getFullSyncContentLeft($offset, $limit, $langIso) } /** - * @param array $deliveryPriceByRange + * @param \Carrier $carrier + * @param array $delivery * * @return false|\RangeWeight|\RangePrice * * @throws \PrestaShopDatabaseException * @throws \PrestaShopException */ - public static function getCarrierRange($deliveryPriceByRange) + public static function generateRange($carrier, $delivery) { - 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; - } + $rangeTable = $carrier->getRangeTable(); - /** - * @param \Carrier $carrierObj - * - * @return array|false - */ - public static function getDeliveryPriceByRange(\Carrier $carrierObj) - { - $rangeTable = $carrierObj->getRangeTable(); - - switch ($rangeTable) { - case 'range_weight': - return CarriersService::getCarrierByWeightRange($carrierObj, 'range_weight'); - case 'range_price': - return CarriersService::getCarrierByPriceRange($carrierObj, 'range_price'); - default: - return false; + if ($rangeTable === 'range_weight') { + return new \RangeWeight($delivery['id_range_weight']); } - } - /** - * @param \Carrier $carrierObj - * @param string $rangeTable - * - * @return array - */ - public static 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 \Carrier $carrierObj - * @param string $rangeTable - * - * @return array - */ - public static 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']; + if ($rangeTable === 'range_price') { + return new \RangePrice($delivery['id_range_price']); } - return $filteredRanges; + return false; } /** From 2310523caa4832f3542926258850a93d782f8c51 Mon Sep 17 00:00:00 2001 From: "John.R" Date: Thu, 31 Oct 2024 17:00:50 +0100 Subject: [PATCH 02/14] fix: carrier details tests --- config/common/repository.yml | 4 +++ e2e/src/fixtures/8/carrier_details.json | 32 +++++++++++++++++++ .../ShopContent/CarrierDetailsService.php | 6 ++-- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/config/common/repository.yml b/config/common/repository.yml index 0188df65..3fe43d56 100644 --- a/config/common/repository.yml +++ b/config/common/repository.yml @@ -75,6 +75,10 @@ services: class: PrestaShop\Module\PsEventbus\Repository\CurrencyRepository public: true + PrestaShop\Module\PsEventbus\Repository\DeliveryRepository: + class: PrestaShop\Module\PsEventbus\Repository\DeliveryRepository + public: true + PrestaShop\Module\PsEventbus\Repository\EmployeeRepository: class: PrestaShop\Module\PsEventbus\Repository\EmployeeRepository public: true diff --git a/e2e/src/fixtures/8/carrier_details.json b/e2e/src/fixtures/8/carrier_details.json index 68f95f5e..996e6aac 100644 --- a/e2e/src/fixtures/8/carrier_details.json +++ b/e2e/src/fixtures/8/carrier_details.json @@ -31,6 +31,38 @@ "price": 5 } }, + { + "action": "upsert", + "collection": "carrier_details", + "properties": { + "id_reference": "2", + "id_zone": "1", + "id_range": "", + "id_carrier_detail": "", + "shipping_method": "range_weight", + "delimiter1": 0, + "delimiter2": 0, + "country_ids": "FR", + "state_ids": "", + "price": 5 + } + }, + { + "action": "upsert", + "collection": "carrier_details", + "properties": { + "id_reference": "2", + "id_zone": "2", + "id_range": "", + "id_carrier_detail": "", + "shipping_method": "range_weight", + "delimiter1": 0, + "delimiter2": 0, + "country_ids": "US", + "state_ids": "AA,AE,AP,AL,AK,AZ,AR,CA,CO,CT,DE,FL,GA,HI,ID,IL,IN,IA,KS,KY,LA,ME,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VT,VA,WA,WV,WI,WY,PR,VI,DC", + "price": 5 + } + }, { "action": "upsert", "collection": "carrier_details", diff --git a/src/Service/ShopContent/CarrierDetailsService.php b/src/Service/ShopContent/CarrierDetailsService.php index 9a8e06c4..c3d9d3ae 100644 --- a/src/Service/ShopContent/CarrierDetailsService.php +++ b/src/Service/ShopContent/CarrierDetailsService.php @@ -67,7 +67,7 @@ public function getContentsForFull($offset, $limit, $langIso) { $result = $this->deliveryRepository->retrieveContentsForFull($offset, $limit, $langIso); - if (!empty($result)) { + if (empty($result)) { return []; } @@ -149,8 +149,8 @@ private function buildCarrierDetail($delivery) return [ 'id_reference' => $carrier->id_reference, 'id_zone' => $delivery['id_zone'], - 'id_range' => $delivery['id_range'], - 'id_carrier_detail' => $delivery['id_delivery'], + 'id_range' => $range->id, + 'id_carrier_detail' => $range->id, 'shipping_method' => $carrier->getRangeTable(), 'delimiter1' => $range->delimiter1, 'delimiter2' => $range->delimiter2, From 48b38ffc7099397905f02d81bf7429b6c443ae24 Mon Sep 17 00:00:00 2001 From: "John.R" Date: Mon, 4 Nov 2024 10:24:50 +0100 Subject: [PATCH 03/14] fix: carrier details declarations --- config/common/repository.yml | 18 ++- config/front/services.yml | 4 +- ...sitory.php => CarrierDetailRepository.php} | 2 +- ...pository.php => CarrierTaxeRepository.php} | 94 ++++++++++++- .../ShopContent/CarrierDetailsService.php | 16 +-- .../ShopContent/CarrierTaxesService.php | 129 +++++++----------- 6 files changed, 160 insertions(+), 103 deletions(-) rename src/Repository/{DeliveryRepository.php => CarrierDetailRepository.php} (97%) rename src/Repository/{TaxeRepository.php => CarrierTaxeRepository.php} (53%) diff --git a/config/common/repository.yml b/config/common/repository.yml index 3fe43d56..690d1869 100644 --- a/config/common/repository.yml +++ b/config/common/repository.yml @@ -25,12 +25,6 @@ services: class: PrestaShop\Module\PsEventbus\Repository\StateRepository public: true - PrestaShop\Module\PsEventbus\Repository\TaxeRepository: - class: PrestaShop\Module\PsEventbus\Repository\TaxeRepository - public: true - arguments: - - '@=service("ps_eventbus").getContext()' - PrestaShop\Module\PsEventbus\Repository\LiveSyncRepository: class: PrestaShop\Module\PsEventbus\Repository\LiveSyncRepository public: true @@ -47,6 +41,14 @@ services: class: PrestaShop\Module\PsEventbus\Repository\CarrierRepository public: true + PrestaShop\Module\PsEventbus\Repository\CarrierDetailRepository: + class: PrestaShop\Module\PsEventbus\Repository\CarrierDetailRepository + public: true + + PrestaShop\Module\PsEventbus\Repository\CarrierTaxeRepository: + class: PrestaShop\Module\PsEventbus\Repository\CarrierTaxeRepository + public: true + PrestaShop\Module\PsEventbus\Repository\CartRepository: class: PrestaShop\Module\PsEventbus\Repository\CartRepository public: true @@ -75,10 +77,6 @@ services: class: PrestaShop\Module\PsEventbus\Repository\CurrencyRepository public: true - PrestaShop\Module\PsEventbus\Repository\DeliveryRepository: - class: PrestaShop\Module\PsEventbus\Repository\DeliveryRepository - public: true - PrestaShop\Module\PsEventbus\Repository\EmployeeRepository: class: PrestaShop\Module\PsEventbus\Repository\EmployeeRepository public: true diff --git a/config/front/services.yml b/config/front/services.yml index 9f666d0e..48a81550 100644 --- a/config/front/services.yml +++ b/config/front/services.yml @@ -70,7 +70,7 @@ services: class: PrestaShop\Module\PsEventbus\Service\ShopContent\CarrierDetailsService public: true arguments: - - '@PrestaShop\Module\PsEventbus\Repository\DeliveryRepository' + - '@PrestaShop\Module\PsEventbus\Repository\CarrierDetailRepository' - '@PrestaShop\Module\PsEventbus\Repository\CountryRepository' - '@PrestaShop\Module\PsEventbus\Repository\StateRepository' @@ -78,7 +78,7 @@ services: class: PrestaShop\Module\PsEventbus\Service\ShopContent\CarrierTaxesService public: true arguments: - - '@PrestaShop\Module\PsEventbus\Repository\CarrierRepository' + - '@PrestaShop\Module\PsEventbus\Repository\CarrierTaxeRepository' PrestaShop\Module\PsEventbus\Service\ShopContent\CartsService: class: PrestaShop\Module\PsEventbus\Service\ShopContent\CartsService diff --git a/src/Repository/DeliveryRepository.php b/src/Repository/CarrierDetailRepository.php similarity index 97% rename from src/Repository/DeliveryRepository.php rename to src/Repository/CarrierDetailRepository.php index 26569adc..be9cd1c3 100644 --- a/src/Repository/DeliveryRepository.php +++ b/src/Repository/CarrierDetailRepository.php @@ -30,7 +30,7 @@ exit; } -class DeliveryRepository extends AbstractRepository implements RepositoryInterface +class CarrierDetailRepository extends AbstractRepository implements RepositoryInterface { const TABLE_NAME = 'delivery'; diff --git a/src/Repository/TaxeRepository.php b/src/Repository/CarrierTaxeRepository.php similarity index 53% rename from src/Repository/TaxeRepository.php rename to src/Repository/CarrierTaxeRepository.php index 3d1064d0..931e48ed 100644 --- a/src/Repository/TaxeRepository.php +++ b/src/Repository/CarrierTaxeRepository.php @@ -30,9 +30,98 @@ exit; } -class TaxeRepository extends AbstractRepository +class CarrierTaxeRepository extends AbstractRepository implements RepositoryInterface { - const TABLE_NAME = 'tax'; + const TABLE_NAME = 'delivery'; + + /** + * @param string $langIso + * @param bool $withSelecParameters + * + * @return mixed + * + * @throws \PrestaShopException + */ + public function generateFullQuery($langIso, $withSelecParameters) + { + $this->generateMinimalQuery(self::TABLE_NAME, 'd'); + + if ($withSelecParameters) { + $this->query + ->select('d.id_delivery') + ->select('d.id_carrier') + ->select('d.id_range_price') + ->select('d.id_range_weight') + ->select('d.id_zone') + ->select('d.price') + ; + } + } + + /** + * @param int $offset + * @param int $limit + * @param string $langIso + * + * @return array + * + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException + */ + public function retrieveContentsForFull($offset, $limit, $langIso) + { + $this->generateFullQuery($langIso, true); + + $this->query->limit((int) $limit, (int) $offset); + + return $this->runQuery(); + } + + /** + * @param int $limit + * @param array $contentIds + * @param string $langIso + * + * @return array + * + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException + */ + public function retrieveContentsForIncremental($limit, $contentIds, $langIso) + { + if ($contentIds == []) { + return []; + } + + $this->generateFullQuery($langIso, true); + + $this->query + ->where('d.id_carrier IN(' . implode(',', array_map('intval', $contentIds)) . ')') + ->limit($limit); + + return $this->runQuery(); + } + + /** + * @param int $offset + * @param int $limit + * @param string $langIso + * + * @return int + * + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException + */ + public function countFullSyncContentLeft($offset, $limit, $langIso) + { + $this->generateFullQuery($langIso, false); + + $this->query->select('(COUNT(*) - ' . (int) $offset . ') as count'); + + $result = $this->runQuery(true); + + return $result[0]['count']; + } /** * @param int $zoneId @@ -48,6 +137,7 @@ public function getCarrierTaxesByZone($zoneId, $taxRulesGroupId, $active) $this->generateMinimalQuery(self::TABLE_NAME, 't'); $this->query + ->innerJoin('tax', 't', 't.id_tax = tr.id_tax') ->innerJoin('tax_rule', 'tr', 'tr.id_tax = t.id_tax') ->innerJoin('tax_rules_group', 'trg', 'trg.id_tax_rules_group = tr.id_tax_rules_group') ->innerJoin('tax_rules_group_shop', 'trgs', 'trgs.id_tax_rules_group = tr.id_tax_rules_group') diff --git a/src/Service/ShopContent/CarrierDetailsService.php b/src/Service/ShopContent/CarrierDetailsService.php index c3d9d3ae..673abb43 100644 --- a/src/Service/ShopContent/CarrierDetailsService.php +++ b/src/Service/ShopContent/CarrierDetailsService.php @@ -27,7 +27,7 @@ namespace PrestaShop\Module\PsEventbus\Service\ShopContent; use PrestaShop\Module\PsEventbus\Config\Config; -use PrestaShop\Module\PsEventbus\Repository\DeliveryRepository; +use PrestaShop\Module\PsEventbus\Repository\CarrierDetailRepository; use PrestaShop\Module\PsEventbus\Repository\CountryRepository; use PrestaShop\Module\PsEventbus\Repository\StateRepository; @@ -37,8 +37,8 @@ class CarrierDetailsService extends ShopContentAbstractService implements ShopContentServiceInterface { - /** @var DeliveryRepository */ - private $deliveryRepository; + /** @var CarrierDetailRepository */ + private $carrierDetailRepository; /** @var CountryRepository */ private $countryRepository; @@ -47,11 +47,11 @@ class CarrierDetailsService extends ShopContentAbstractService implements ShopCo private $stateRepository; public function __construct( - DeliveryRepository $deliveryRepository, + CarrierDetailRepository $carrierDetailRepository, CountryRepository $countryRepository, StateRepository $stateRepository ) { - $this->deliveryRepository = $deliveryRepository; + $this->carrierDetailRepository = $carrierDetailRepository; $this->countryRepository = $countryRepository; $this->stateRepository = $stateRepository; } @@ -65,7 +65,7 @@ public function __construct( */ public function getContentsForFull($offset, $limit, $langIso) { - $result = $this->deliveryRepository->retrieveContentsForFull($offset, $limit, $langIso); + $result = $this->carrierDetailRepository->retrieveContentsForFull($offset, $limit, $langIso); if (empty($result)) { return []; @@ -98,7 +98,7 @@ public function getContentsForFull($offset, $limit, $langIso) */ public function getContentsForIncremental($limit, $upsertedContents, $deletedContents, $langIso) { - $result = $this->deliveryRepository->retrieveContentsForIncremental($limit, array_column($upsertedContents, 'id'), $langIso); + $result = $this->carrierDetailRepository->retrieveContentsForIncremental($limit, array_column($upsertedContents, 'id'), $langIso); if (!empty($result)) { $carrierDetails = []; @@ -122,7 +122,7 @@ public function getContentsForIncremental($limit, $upsertedContents, $deletedCon */ public function getFullSyncContentLeft($offset, $limit, $langIso) { - return $this->deliveryRepository->countFullSyncContentLeft($offset, $limit, $langIso); + return $this->carrierDetailRepository->countFullSyncContentLeft($offset, $limit, $langIso); } /** diff --git a/src/Service/ShopContent/CarrierTaxesService.php b/src/Service/ShopContent/CarrierTaxesService.php index 6dcf534a..36940291 100644 --- a/src/Service/ShopContent/CarrierTaxesService.php +++ b/src/Service/ShopContent/CarrierTaxesService.php @@ -27,8 +27,7 @@ namespace PrestaShop\Module\PsEventbus\Service\ShopContent; use PrestaShop\Module\PsEventbus\Config\Config; -use PrestaShop\Module\PsEventbus\Repository\CarrierRepository; -use PrestaShop\Module\PsEventbus\Repository\TaxeRepository; +use PrestaShop\Module\PsEventbus\Repository\CarrierTaxeRepository; if (!defined('_PS_VERSION_')) { exit; @@ -36,12 +35,11 @@ class CarrierTaxesService extends ShopContentAbstractService implements ShopContentServiceInterface { - /** @var CarrierRepository */ - private $carrierRepository; + /** @var CarrierTaxeRepository */ + private $carrierTaxeRepository; - public function __construct(CarrierRepository $carrierRepository) - { - $this->carrierRepository = $carrierRepository; + public function __construct(CarrierTaxeRepository $carrierTaxeRepository) { + $this->carrierTaxeRepository = $carrierTaxeRepository; } /** @@ -53,7 +51,7 @@ public function __construct(CarrierRepository $carrierRepository) */ public function getContentsForFull($offset, $limit, $langIso) { - $result = $this->carrierRepository->retrieveContentsForFull($offset, $limit, $langIso); + $result = $this->carrierTaxeRepository->retrieveContentsForFull($offset, $limit, $langIso); if (empty($result)) { return []; @@ -61,8 +59,8 @@ public function getContentsForFull($offset, $limit, $langIso) $carrierTaxes = []; - foreach ($result as $carrierData) { - $carrierTaxes = array_merge($carrierTaxes, $this->buildCarrierTaxes($carrierData)); + foreach ($result as $delivery) { + $carrierTaxes[] = $this->buildCarrierTaxe($delivery); } $this->castCarrierTaxes($carrierTaxes); @@ -86,13 +84,13 @@ public function getContentsForFull($offset, $limit, $langIso) */ public function getContentsForIncremental($limit, $upsertedContents, $deletedContents, $langIso) { - $result = $this->carrierRepository->retrieveContentsForIncremental($limit, array_column($upsertedContents, 'id'), $langIso); + $result = $this->carrierTaxeRepository->retrieveContentsForIncremental($limit, array_column($upsertedContents, 'id'), $langIso); if (!empty($result)) { $carrierTaxes = []; - foreach ($result as $carrierData) { - $carrierTaxes = array_merge($carrierTaxes, $this->buildCarrierTaxes($carrierData)); + foreach ($result as $delivery) { + $carrierTaxes[] = $this->buildCarrierTaxe($delivery); } $this->castCarrierTaxes($carrierTaxes); @@ -110,90 +108,61 @@ public function getContentsForIncremental($limit, $upsertedContents, $deletedCon */ public function getFullSyncContentLeft($offset, $limit, $langIso) { - $data = $this->getContentsForFull($offset, 50, $langIso); - - return count($data); + return $this->carrierTaxeRepository->countFullSyncContentLeft($offset, $limit, $langIso); } /** - * @param array $carrierTaxes + * Build a CarrierDetail from delvery data * - * @return void - */ - private function castCarrierTaxes(&$carrierTaxes) - { - foreach ($carrierTaxes as &$carrierTaxe) { - $carrierTaxe['id_reference'] = (string) $carrierTaxe['id_reference']; - $carrierTaxe['id_zone'] = (string) $carrierTaxe['id_zone']; - $carrierTaxe['id_range'] = (string) $carrierTaxe['id_range']; - $carrierTaxe['id_carrier_tax'] = (string) $carrierTaxe['id_carrier_tax']; - $carrierTaxe['country_ids'] = (string) $carrierTaxe['country_ids']; - $carrierTaxe['state_ids'] = (string) $carrierTaxe['state_ids']; - $carrierTaxe['tax_rate'] = (float) $carrierTaxe['tax_rate']; - } - } - - /** - * Build a CarrierTaxes from Carrier - * - * @param array $carrierData + * @param array $delivery * * @return array * * @throws \PrestaShopDatabaseException * @throws \PrestaShopException */ - private function buildCarrierTaxes($carrierData) + private function buildCarrierTaxe($delivery) { - /** @var \Ps_eventbus $module */ - $module = \Module::getInstanceByName('ps_eventbus'); - - /** @var TaxeRepository $taxeRepository */ - $taxeRepository = $module->getService('PrestaShop\Module\PsEventbus\Repository\TaxeRepository'); - - $carrier = new \Carrier($carrierData['id_reference']); - - $deliveryPriceByRanges = CarriersService::getDeliveryPriceByRange($carrier); - - if (!$deliveryPriceByRanges) { - return []; - } - - $carrierTaxes = []; + $carrier = new \Carrier($delivery['id_carrier']); + $range = CarriersService::generateRange($carrier, $delivery); + $taxRulesGroupId = (int) $carrier->getIdTaxRulesGroup(); + + $this->carrierTaxeRepository->getCarrierTaxesByZone($delivery['id_zone'], $taxRulesGroupId, true); + + return [ + 'id_reference' => $carrier->id_reference, + 'id_zone' => $delivery['id_zone'], + 'id_range' => $range->id, + 'id_carrier_tax' => $range->id, + 'country_ids' => $delivery['country_iso_code'], + 'state_ids' => $delivery['state_iso_code'], + 'tax_rate' => $delivery['rate'], + ]; + } - foreach ($deliveryPriceByRanges as $deliveryPriceByRange) { - $range = CarriersService::getCarrierRange($deliveryPriceByRange); + /** + * @param array $carrierTaxes + * + * @return void + */ + private function castCarrierTaxes($carrierTaxes) + { + $result = []; - if (!$range) { + foreach ($carrierTaxes as $key => $carrierTaxe) { + if ($carrierTaxes[$key] === null) { continue; } - foreach ($deliveryPriceByRange['zones'] as $zone) { - $taxRulesGroupId = (int) $carrier->getIdTaxRulesGroup(); - - /** @var array $carrierTaxesByZone */ - $carrierTaxesByZone = $taxeRepository->getCarrierTaxesByZone($zone['id_zone'], $taxRulesGroupId, true); - - if (!$carrierTaxesByZone[0]['country_iso_code']) { - continue; - } - - $carrierTaxesByZone = $carrierTaxesByZone[0]; - - $carrierTaxe = []; - - $carrierTaxe['id_reference'] = $carrier->id_reference; - $carrierTaxe['id_zone'] = $zone['id_zone']; - $carrierTaxe['id_range'] = $range->id; - $carrierTaxe['id_carrier_tax'] = $taxRulesGroupId; - $carrierTaxe['country_id'] = $carrierTaxesByZone['country_iso_code']; - $carrierTaxe['state_ids'] = $carrierTaxesByZone['state_iso_code']; - $carrierTaxe['tax_rate'] = $carrierTaxesByZone['rate']; - - array_push($carrierTaxes, $carrierTaxe); - } + $result['id_reference'] = (string) $carrierTaxe['id_reference']; + $result['id_zone'] = (string) $carrierTaxe['id_zone']; + $result['id_range'] = (string) $carrierTaxe['id_range']; + $result['id_carrier_tax'] = (string) $carrierTaxe['id_carrier_tax']; + $result['country_ids'] = (string) $carrierTaxe['country_ids']; + $result['state_ids'] = (string) $carrierTaxe['state_ids']; + $result['tax_rate'] = (float) $carrierTaxe['tax_rate']; } - return $carrierTaxes; + return $result; } } From f67ba7b4cc6f9eb277a4f654164f7928c7cedb57 Mon Sep 17 00:00:00 2001 From: "John.R" Date: Wed, 6 Nov 2024 16:28:36 +0100 Subject: [PATCH 04/14] fix: problems --- src/Repository/CarrierTaxeRepository.php | 82 +++++++------------ .../ShopContent/CarrierDetailsService.php | 2 +- .../ShopContent/CarrierTaxesService.php | 35 ++++---- 3 files changed, 45 insertions(+), 74 deletions(-) diff --git a/src/Repository/CarrierTaxeRepository.php b/src/Repository/CarrierTaxeRepository.php index 931e48ed..0ab0e300 100644 --- a/src/Repository/CarrierTaxeRepository.php +++ b/src/Repository/CarrierTaxeRepository.php @@ -32,7 +32,7 @@ class CarrierTaxeRepository extends AbstractRepository implements RepositoryInterface { - const TABLE_NAME = 'delivery'; + const TABLE_NAME = 'carrier'; /** * @param string $langIso @@ -44,18 +44,34 @@ class CarrierTaxeRepository extends AbstractRepository implements RepositoryInte */ public function generateFullQuery($langIso, $withSelecParameters) { - $this->generateMinimalQuery(self::TABLE_NAME, 'd'); - - if ($withSelecParameters) { - $this->query - ->select('d.id_delivery') - ->select('d.id_carrier') - ->select('d.id_range_price') - ->select('d.id_range_weight') - ->select('d.id_zone') - ->select('d.price') - ; - } + $this->generateMinimalQuery(SELF::TABLE_NAME, 'ca'); + + $this->query + ->leftJoin('ps_carrier_tax_rules_group_shop', 'ctrgs', 'ca.id_carrier = ctrgs.id_carrier') + ->leftJoin('ps_tax_rule', 'tr', 'tr.id_tax_rules_group = ctrgs.id_tax_rules_group') + ->leftJoin('ps_tax', 't', 't.id_tax = tr.id_tax') + ->leftJoin('ps_tax_lang', 'tl', 'tl.id_tax = t.id_tax') + ->leftJoin('ps_country', 'co', 'co.id_country = tr.id_country') + ->leftJoin('ps_delivery', 'd', 'd.id_carrier = ca.id_carrier') + ->leftJoin('ps_state', 's', 's.id_state = tr.id_state') + ; + + $this->query + ->where('co.iso_code IS NOT NULL') + ->where('d.id_delivery IS NOT NULL') + ->where('co.active = 1') + ->where('tl.id_lang = ' . (int) parent::getLanguageContext()->id) + ; + + $this->query->groupBy('co.iso_code'); + + $this->query + ->select('ca.id_reference') + ->select('d.id_zone') + ->select('co.iso_code AS country_id') + ->select('GROUP_CONCAT(s.iso_code SEPARATOR ",") as state_iso_code') + ->select('t.rate AS tax_rate') + ; } /** @@ -122,44 +138,4 @@ public function countFullSyncContentLeft($offset, $limit, $langIso) return $result[0]['count']; } - - /** - * @param int $zoneId - * @param int $taxRulesGroupId - * @param bool $active - * - * @return array - * - * @throws \PrestaShopDatabaseException - */ - public function getCarrierTaxesByZone($zoneId, $taxRulesGroupId, $active) - { - $this->generateMinimalQuery(self::TABLE_NAME, 't'); - - $this->query - ->innerJoin('tax', 't', 't.id_tax = tr.id_tax') - ->innerJoin('tax_rule', 'tr', 'tr.id_tax = t.id_tax') - ->innerJoin('tax_rules_group', 'trg', 'trg.id_tax_rules_group = tr.id_tax_rules_group') - ->innerJoin('tax_rules_group_shop', 'trgs', 'trgs.id_tax_rules_group = tr.id_tax_rules_group') - ->innerJoin('tax_lang', 'tl', 'tl.id_tax = t.id_tax') - ->leftJoin('country', 'c', 'c.id_country = tr.id_country') - ->leftJoin('state', 's', 's.id_state = tr.id_state') - ->where('tr.id_tax_rules_group = ' . (int) $taxRulesGroupId) - ->where('c.active = ' . (bool) $active) - ->where('s.active = ' . (bool) $active . ' OR s.active IS NULL') - ->where('t.active = ' . (bool) $active) - ->where('c.id_zone = ' . (int) $zoneId . ' OR s.id_zone = ' . (int) $zoneId) - ->where('c.iso_code IS NOT NULL') - ->where('trgs.id_shop = ' . parent::getShopContext()->id) - ->where('tl.id_lang = ' . (int) parent::getLanguageContext()->id) - ; - - $this->query - ->select('t.rate') - ->select('c.iso_code as country_iso_code') - ->select('GROUP_CONCAT(s.iso_code SEPARATOR ",") as state_iso_code') - ; - - return $this->runQuery(true); - } } diff --git a/src/Service/ShopContent/CarrierDetailsService.php b/src/Service/ShopContent/CarrierDetailsService.php index 673abb43..9cc2f8d4 100644 --- a/src/Service/ShopContent/CarrierDetailsService.php +++ b/src/Service/ShopContent/CarrierDetailsService.php @@ -126,7 +126,7 @@ public function getFullSyncContentLeft($offset, $limit, $langIso) } /** - * Build a CarrierDetail from delvery data + * Build a CarrierDetail from delivery data * * @param array $delivery * diff --git a/src/Service/ShopContent/CarrierTaxesService.php b/src/Service/ShopContent/CarrierTaxesService.php index 36940291..bb4b11f9 100644 --- a/src/Service/ShopContent/CarrierTaxesService.php +++ b/src/Service/ShopContent/CarrierTaxesService.php @@ -59,11 +59,11 @@ public function getContentsForFull($offset, $limit, $langIso) $carrierTaxes = []; - foreach ($result as $delivery) { - $carrierTaxes[] = $this->buildCarrierTaxe($delivery); + foreach ($result as $taxe) { + $carrierTaxes[] = $this->buildCarrierTaxe($taxe); } - $this->castCarrierTaxes($carrierTaxes); + $this->castCarrierTaxes($result); return array_map(function ($item) { return [ @@ -87,13 +87,11 @@ public function getContentsForIncremental($limit, $upsertedContents, $deletedCon $result = $this->carrierTaxeRepository->retrieveContentsForIncremental($limit, array_column($upsertedContents, 'id'), $langIso); if (!empty($result)) { - $carrierTaxes = []; - - foreach ($result as $delivery) { - $carrierTaxes[] = $this->buildCarrierTaxe($delivery); + foreach ($result as $taxe) { + $carrierTaxes[] = $this->buildCarrierTaxe($taxe); } - $this->castCarrierTaxes($carrierTaxes); + $this->castCarrierTaxes($result); } return parent::formatIncrementalSyncResponse(Config::COLLECTION_CARRIER_TAXES, $result, $deletedContents); @@ -112,31 +110,28 @@ public function getFullSyncContentLeft($offset, $limit, $langIso) } /** - * Build a CarrierDetail from delvery data + * Build a CarrierTaxes from tax data * - * @param array $delivery + * @param array $taxe * * @return array * * @throws \PrestaShopDatabaseException * @throws \PrestaShopException */ - private function buildCarrierTaxe($delivery) + private function buildCarrierTaxe($taxe) { - $carrier = new \Carrier($delivery['id_carrier']); - $range = CarriersService::generateRange($carrier, $delivery); - $taxRulesGroupId = (int) $carrier->getIdTaxRulesGroup(); - - $this->carrierTaxeRepository->getCarrierTaxesByZone($delivery['id_zone'], $taxRulesGroupId, true); + $carrier = new \Carrier($taxe['id_carrier']); + $range = CarriersService::generateRange($carrier, $taxe); return [ 'id_reference' => $carrier->id_reference, - 'id_zone' => $delivery['id_zone'], + 'id_zone' => $taxe['id_zone'], 'id_range' => $range->id, 'id_carrier_tax' => $range->id, - 'country_ids' => $delivery['country_iso_code'], - 'state_ids' => $delivery['state_iso_code'], - 'tax_rate' => $delivery['rate'], + 'country_id' => $taxe['country_iso_code'], + 'state_ids' => $taxe['state_iso_code'], + 'tax_rate' => $taxe['rate'], ]; } From 216b76dc5bc54a976601d86913bc7511ce523906 Mon Sep 17 00:00:00 2001 From: "John.R" Date: Wed, 13 Nov 2024 14:00:00 +0100 Subject: [PATCH 05/14] feat: add carrier taxes --- src/Repository/AbstractRepository.php | 4 +- src/Repository/CarrierTaxeRepository.php | 64 ++++++++++++------- .../ShopContent/CarrierTaxesService.php | 52 ++------------- 3 files changed, 46 insertions(+), 74 deletions(-) diff --git a/src/Repository/AbstractRepository.php b/src/Repository/AbstractRepository.php index 8e5e066c..c9b07098 100644 --- a/src/Repository/AbstractRepository.php +++ b/src/Repository/AbstractRepository.php @@ -63,11 +63,11 @@ public function __construct() /** * @param string $tableName - * @param string $alias + * @param string|null $alias * * @return void */ - protected function generateMinimalQuery($tableName, $alias) + protected function generateMinimalQuery($tableName, $alias = null) { $this->query = new \DbQuery(); diff --git a/src/Repository/CarrierTaxeRepository.php b/src/Repository/CarrierTaxeRepository.php index 0ab0e300..37a6880a 100644 --- a/src/Repository/CarrierTaxeRepository.php +++ b/src/Repository/CarrierTaxeRepository.php @@ -45,33 +45,48 @@ class CarrierTaxeRepository extends AbstractRepository implements RepositoryInte public function generateFullQuery($langIso, $withSelecParameters) { $this->generateMinimalQuery(SELF::TABLE_NAME, 'ca'); - + $this->query - ->leftJoin('ps_carrier_tax_rules_group_shop', 'ctrgs', 'ca.id_carrier = ctrgs.id_carrier') - ->leftJoin('ps_tax_rule', 'tr', 'tr.id_tax_rules_group = ctrgs.id_tax_rules_group') - ->leftJoin('ps_tax', 't', 't.id_tax = tr.id_tax') - ->leftJoin('ps_tax_lang', 'tl', 'tl.id_tax = t.id_tax') - ->leftJoin('ps_country', 'co', 'co.id_country = tr.id_country') - ->leftJoin('ps_delivery', 'd', 'd.id_carrier = ca.id_carrier') - ->leftJoin('ps_state', 's', 's.id_state = tr.id_state') + ->innerJoin('carrier_tax_rules_group_shop', 'ctrgs', 'ca.id_carrier = ctrgs.id_carrier') + ->innerJoin('tax_rule', 'tr', 'ctrgs.id_tax_rules_group = tr.id_tax_rules_group') + ->innerJoin('country', 'co', 'tr.id_country = co.id_country AND co.iso_code IS NOT NULL AND co.active = 1') + ->innerJoin('delivery', 'd', 'ca.id_carrier = d.id_carrier AND d.id_zone IS NOT NULL') + ->innerJoin('tax', 't', 'tr.id_tax = t.id_tax AND t.active = 1') + ->leftJoin('state', 's', 'tr.id_state = s.id_state AND s.active = 1') ; $this->query - ->where('co.iso_code IS NOT NULL') - ->where('d.id_delivery IS NOT NULL') - ->where('co.active = 1') - ->where('tl.id_lang = ' . (int) parent::getLanguageContext()->id) + ->where('(co.id_zone = d.id_zone OR s.id_zone = d.id_zone)') ; - $this->query->groupBy('co.iso_code'); + if ($withSelecParameters) { + $this->query + ->select('ca.id_reference') + ->select('co.id_zone') + ->select(' + CASE + WHEN d.id_range_weight IS NOT NULL AND d.id_range_weight != 0 THEN d.id_range_weight + WHEN d.id_range_price IS NOT NULL AND d.id_range_price != 0 THEN d.id_range_price + END AS id_range + ') + ->select('ctrgs.id_tax_rules_group AS id_carrier_tax') + ->select('co.iso_code as country_id') + ->select(' + GROUP_CONCAT( + DISTINCT IF( + s.iso_code IS NOT NULL, + s.iso_code, + NULL + ) + ORDER BY s.iso_code ASC + SEPARATOR \',\' + ) AS state_ids + ') + ->select('t.rate AS tax_rate') + ; + } - $this->query - ->select('ca.id_reference') - ->select('d.id_zone') - ->select('co.iso_code AS country_id') - ->select('GROUP_CONCAT(s.iso_code SEPARATOR ",") as state_iso_code') - ->select('t.rate AS tax_rate') - ; + $this->query->groupBy('ca.id_reference, co.id_zone, id_range, country_id'); } /** @@ -130,11 +145,12 @@ public function retrieveContentsForIncremental($limit, $contentIds, $langIso) */ public function countFullSyncContentLeft($offset, $limit, $langIso) { - $this->generateFullQuery($langIso, false); - - $this->query->select('(COUNT(*) - ' . (int) $offset . ') as count'); + $this->generateFullQuery($langIso, true); - $result = $this->runQuery(true); + $result = $this->db->executeS(' + SELECT (COUNT(*) - ' . (int) $offset . ') AS count + FROM (' . $this->query->build() . ') as subquery; + '); return $result[0]['count']; } diff --git a/src/Service/ShopContent/CarrierTaxesService.php b/src/Service/ShopContent/CarrierTaxesService.php index bb4b11f9..5b851ad2 100644 --- a/src/Service/ShopContent/CarrierTaxesService.php +++ b/src/Service/ShopContent/CarrierTaxesService.php @@ -57,12 +57,6 @@ public function getContentsForFull($offset, $limit, $langIso) return []; } - $carrierTaxes = []; - - foreach ($result as $taxe) { - $carrierTaxes[] = $this->buildCarrierTaxe($taxe); - } - $this->castCarrierTaxes($result); return array_map(function ($item) { @@ -71,7 +65,7 @@ public function getContentsForFull($offset, $limit, $langIso) 'collection' => Config::COLLECTION_CARRIER_TAXES, 'properties' => $item, ]; - }, $carrierTaxes); + }, $result); } /** @@ -87,10 +81,6 @@ public function getContentsForIncremental($limit, $upsertedContents, $deletedCon $result = $this->carrierTaxeRepository->retrieveContentsForIncremental($limit, array_column($upsertedContents, 'id'), $langIso); if (!empty($result)) { - foreach ($result as $taxe) { - $carrierTaxes[] = $this->buildCarrierTaxe($taxe); - } - $this->castCarrierTaxes($result); } @@ -109,55 +99,21 @@ public function getFullSyncContentLeft($offset, $limit, $langIso) return $this->carrierTaxeRepository->countFullSyncContentLeft($offset, $limit, $langIso); } - /** - * Build a CarrierTaxes from tax data - * - * @param array $taxe - * - * @return array - * - * @throws \PrestaShopDatabaseException - * @throws \PrestaShopException - */ - private function buildCarrierTaxe($taxe) - { - $carrier = new \Carrier($taxe['id_carrier']); - $range = CarriersService::generateRange($carrier, $taxe); - - return [ - 'id_reference' => $carrier->id_reference, - 'id_zone' => $taxe['id_zone'], - 'id_range' => $range->id, - 'id_carrier_tax' => $range->id, - 'country_id' => $taxe['country_iso_code'], - 'state_ids' => $taxe['state_iso_code'], - 'tax_rate' => $taxe['rate'], - ]; - } - /** * @param array $carrierTaxes * * @return void */ - private function castCarrierTaxes($carrierTaxes) + private function castCarrierTaxes(&$carrierTaxes) { - $result = []; - - foreach ($carrierTaxes as $key => $carrierTaxe) { - if ($carrierTaxes[$key] === null) { - continue; - } - + foreach ($carrierTaxes as &$carrierTaxe) { $result['id_reference'] = (string) $carrierTaxe['id_reference']; $result['id_zone'] = (string) $carrierTaxe['id_zone']; $result['id_range'] = (string) $carrierTaxe['id_range']; $result['id_carrier_tax'] = (string) $carrierTaxe['id_carrier_tax']; - $result['country_ids'] = (string) $carrierTaxe['country_ids']; + $result['country_id'] = (string) $carrierTaxe['country_id']; $result['state_ids'] = (string) $carrierTaxe['state_ids']; $result['tax_rate'] = (float) $carrierTaxe['tax_rate']; } - - return $result; } } From 6dcf849ccfbe65b976ae361b3b59a2d6f993bf0c Mon Sep 17 00:00:00 2001 From: "John.R" Date: Wed, 13 Nov 2024 17:07:53 +0100 Subject: [PATCH 06/14] fix: bug with cast --- src/Repository/CarrierTaxeRepository.php | 7 ++----- src/Service/ShopContent/CarrierTaxesService.php | 14 +++++++------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/Repository/CarrierTaxeRepository.php b/src/Repository/CarrierTaxeRepository.php index 37a6880a..2e1fb049 100644 --- a/src/Repository/CarrierTaxeRepository.php +++ b/src/Repository/CarrierTaxeRepository.php @@ -73,11 +73,8 @@ public function generateFullQuery($langIso, $withSelecParameters) ->select('co.iso_code as country_id') ->select(' GROUP_CONCAT( - DISTINCT IF( - s.iso_code IS NOT NULL, - s.iso_code, - NULL - ) + DISTINCT + s.iso_code ORDER BY s.iso_code ASC SEPARATOR \',\' ) AS state_ids diff --git a/src/Service/ShopContent/CarrierTaxesService.php b/src/Service/ShopContent/CarrierTaxesService.php index 5b851ad2..05001c5a 100644 --- a/src/Service/ShopContent/CarrierTaxesService.php +++ b/src/Service/ShopContent/CarrierTaxesService.php @@ -107,13 +107,13 @@ public function getFullSyncContentLeft($offset, $limit, $langIso) private function castCarrierTaxes(&$carrierTaxes) { foreach ($carrierTaxes as &$carrierTaxe) { - $result['id_reference'] = (string) $carrierTaxe['id_reference']; - $result['id_zone'] = (string) $carrierTaxe['id_zone']; - $result['id_range'] = (string) $carrierTaxe['id_range']; - $result['id_carrier_tax'] = (string) $carrierTaxe['id_carrier_tax']; - $result['country_id'] = (string) $carrierTaxe['country_id']; - $result['state_ids'] = (string) $carrierTaxe['state_ids']; - $result['tax_rate'] = (float) $carrierTaxe['tax_rate']; + $carrierTaxe['id_reference'] = (string) $carrierTaxe['id_reference']; + $carrierTaxe['id_zone'] = (string) $carrierTaxe['id_zone']; + $carrierTaxe['id_range'] = (string) $carrierTaxe['id_range']; + $carrierTaxe['id_carrier_tax'] = (string) $carrierTaxe['id_carrier_tax']; + $carrierTaxe['country_id'] = (string) $carrierTaxe['country_id']; + $carrierTaxe['state_ids'] = (string) $carrierTaxe['state_ids']; + $carrierTaxe['tax_rate'] = (float) $carrierTaxe['tax_rate']; } } } From b58f9c6de547398ecc0d55b0dccb29abfe9863f9 Mon Sep 17 00:00:00 2001 From: "John.R" Date: Thu, 14 Nov 2024 10:07:58 +0100 Subject: [PATCH 07/14] fix: missing reefacto --- src/Repository/CarrierTaxeRepository.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Repository/CarrierTaxeRepository.php b/src/Repository/CarrierTaxeRepository.php index 2e1fb049..dd7053a6 100644 --- a/src/Repository/CarrierTaxeRepository.php +++ b/src/Repository/CarrierTaxeRepository.php @@ -81,9 +81,9 @@ public function generateFullQuery($langIso, $withSelecParameters) ') ->select('t.rate AS tax_rate') ; - } - $this->query->groupBy('ca.id_reference, co.id_zone, id_range, country_id'); + $this->query->groupBy('ca.id_reference, co.id_zone, id_range, country_id'); + } } /** From 7665505beb9afa5b9b3948136c3d77483af39fcf Mon Sep 17 00:00:00 2001 From: "John.R" Date: Thu, 14 Nov 2024 10:57:17 +0100 Subject: [PATCH 08/14] fix: php-cs-fixer and phpstan --- src/Repository/CarrierTaxeRepository.php | 6 +++--- src/Service/ShopContent/CarrierDetailsService.php | 8 ++++---- src/Service/ShopContent/CarrierTaxesService.php | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Repository/CarrierTaxeRepository.php b/src/Repository/CarrierTaxeRepository.php index dd7053a6..6cb61304 100644 --- a/src/Repository/CarrierTaxeRepository.php +++ b/src/Repository/CarrierTaxeRepository.php @@ -44,8 +44,8 @@ class CarrierTaxeRepository extends AbstractRepository implements RepositoryInte */ public function generateFullQuery($langIso, $withSelecParameters) { - $this->generateMinimalQuery(SELF::TABLE_NAME, 'ca'); - + $this->generateMinimalQuery(self::TABLE_NAME, 'ca'); + $this->query ->innerJoin('carrier_tax_rules_group_shop', 'ctrgs', 'ca.id_carrier = ctrgs.id_carrier') ->innerJoin('tax_rule', 'tr', 'ctrgs.id_tax_rules_group = tr.id_tax_rules_group') @@ -149,6 +149,6 @@ public function countFullSyncContentLeft($offset, $limit, $langIso) FROM (' . $this->query->build() . ') as subquery; '); - return $result[0]['count']; + return is_array($result) ? $result[0]['count'] : []; } } diff --git a/src/Service/ShopContent/CarrierDetailsService.php b/src/Service/ShopContent/CarrierDetailsService.php index 9cc2f8d4..9a1a7f50 100644 --- a/src/Service/ShopContent/CarrierDetailsService.php +++ b/src/Service/ShopContent/CarrierDetailsService.php @@ -149,11 +149,11 @@ private function buildCarrierDetail($delivery) return [ 'id_reference' => $carrier->id_reference, 'id_zone' => $delivery['id_zone'], - 'id_range' => $range->id, - 'id_carrier_detail' => $range->id, + 'id_range' => $range ? $range->id : null, + 'id_carrier_detail' => $range ? $range->id : null, 'shipping_method' => $carrier->getRangeTable(), - 'delimiter1' => $range->delimiter1, - 'delimiter2' => $range->delimiter2, + 'delimiter1' => $range ? $range->delimiter1 : null, + 'delimiter2' => $range ? $range->delimiter2 : null, 'country_ids' => implode(',', $countryIsoCodes), 'state_ids' => implode(',', $stateIsoCodes), 'price' => $delivery['price'], diff --git a/src/Service/ShopContent/CarrierTaxesService.php b/src/Service/ShopContent/CarrierTaxesService.php index 05001c5a..97eecc20 100644 --- a/src/Service/ShopContent/CarrierTaxesService.php +++ b/src/Service/ShopContent/CarrierTaxesService.php @@ -38,7 +38,8 @@ class CarrierTaxesService extends ShopContentAbstractService implements ShopCont /** @var CarrierTaxeRepository */ private $carrierTaxeRepository; - public function __construct(CarrierTaxeRepository $carrierTaxeRepository) { + public function __construct(CarrierTaxeRepository $carrierTaxeRepository) + { $this->carrierTaxeRepository = $carrierTaxeRepository; } From f1ac80fb6991e74cbc68244cb1ffb749fe6ffc62 Mon Sep 17 00:00:00 2001 From: "John.R" Date: Fri, 15 Nov 2024 15:35:22 +0100 Subject: [PATCH 09/14] refactor: update carrier details --- e2e/src/fixtures/1.7/carrier_details.json | 162 ++++++++-------- e2e/src/fixtures/8/carrier_details.json | 166 +++++++--------- e2e/src/fixtures/9/carrier_details.json | 181 ++++++++---------- src/Repository/CarrierDetailRepository.php | 69 +++++-- .../ShopContent/CarrierDetailsService.php | 55 +----- 5 files changed, 293 insertions(+), 340 deletions(-) diff --git a/e2e/src/fixtures/1.7/carrier_details.json b/e2e/src/fixtures/1.7/carrier_details.json index 502f304c..309a9a16 100644 --- a/e2e/src/fixtures/1.7/carrier_details.json +++ b/e2e/src/fixtures/1.7/carrier_details.json @@ -6,13 +6,13 @@ "id_reference": "2", "id_zone": "1", "id_range": "1", - "id_carrier_detail": "1", "shipping_method": "range_weight", "delimiter1": 0, "delimiter2": 10000, - "country_ids": "", + "country_ids": "FR", "state_ids": "", - "price": 5 + "price": 5, + "id_carrier_detail": "1" } }, { @@ -22,13 +22,13 @@ "id_reference": "2", "id_zone": "2", "id_range": "1", - "id_carrier_detail": "1", "shipping_method": "range_weight", "delimiter1": 0, "delimiter2": 10000, - "country_ids": "", - "state_ids": "", - "price": 5 + "country_ids": "US", + "state_ids": "AA,AE,AK,AL,AP,AR,AZ,CA,CO,CT,DC,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,PR,RI,SC,SD,TN,TX,UT,VA,VI,VT,WA,WI,WV,WY", + "price": 5, + "id_carrier_detail": "1" } }, { @@ -36,15 +36,15 @@ "collection": "carrier_details", "properties": { "id_reference": "3", - "id_zone": "2", + "id_zone": "1", "id_range": "2", - "id_carrier_detail": "2", "shipping_method": "range_price", "delimiter1": 0, "delimiter2": 50, - "country_ids": "", + "country_ids": "FR", "state_ids": "", - "price": 4 + "price": 3, + "id_carrier_detail": "2" } }, { @@ -53,14 +53,14 @@ "properties": { "id_reference": "3", "id_zone": "1", - "id_range": "2", - "id_carrier_detail": "2", + "id_range": "3", "shipping_method": "range_price", - "delimiter1": 0, - "delimiter2": 50, - "country_ids": "", + "delimiter1": 50, + "delimiter2": 100, + "country_ids": "FR", "state_ids": "", - "price": 3 + "price": 1, + "id_carrier_detail": "3" } }, { @@ -68,15 +68,15 @@ "collection": "carrier_details", "properties": { "id_reference": "3", - "id_zone": "2", - "id_range": "3", - "id_carrier_detail": "3", + "id_zone": "1", + "id_range": "4", "shipping_method": "range_price", - "delimiter1": 50, - "delimiter2": 100, - "country_ids": "", + "delimiter1": 100, + "delimiter2": 200, + "country_ids": "FR", "state_ids": "", - "price": 2 + "price": 0, + "id_carrier_detail": "4" } }, { @@ -84,15 +84,15 @@ "collection": "carrier_details", "properties": { "id_reference": "3", - "id_zone": "1", - "id_range": "3", - "id_carrier_detail": "3", + "id_zone": "2", + "id_range": "2", "shipping_method": "range_price", - "delimiter1": 50, - "delimiter2": 100, - "country_ids": "", - "state_ids": "", - "price": 1 + "delimiter1": 0, + "delimiter2": 50, + "country_ids": "US", + "state_ids": "AA,AE,AK,AL,AP,AR,AZ,CA,CO,CT,DC,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,PR,RI,SC,SD,TN,TX,UT,VA,VI,VT,WA,WI,WV,WY", + "price": 4, + "id_carrier_detail": "2" } }, { @@ -101,14 +101,14 @@ "properties": { "id_reference": "3", "id_zone": "2", - "id_range": "4", - "id_carrier_detail": "4", + "id_range": "3", "shipping_method": "range_price", - "delimiter1": 100, - "delimiter2": 200, - "country_ids": "", - "state_ids": "", - "price": 0 + "delimiter1": 50, + "delimiter2": 100, + "country_ids": "US", + "state_ids": "AA,AE,AK,AL,AP,AR,AZ,CA,CO,CT,DC,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,PR,RI,SC,SD,TN,TX,UT,VA,VI,VT,WA,WI,WV,WY", + "price": 2, + "id_carrier_detail": "3" } }, { @@ -116,15 +116,15 @@ "collection": "carrier_details", "properties": { "id_reference": "3", - "id_zone": "1", + "id_zone": "2", "id_range": "4", - "id_carrier_detail": "4", "shipping_method": "range_price", "delimiter1": 100, "delimiter2": 200, - "country_ids": "", - "state_ids": "", - "price": 0 + "country_ids": "US", + "state_ids": "AA,AE,AK,AL,AP,AR,AZ,CA,CO,CT,DC,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,PR,RI,SC,SD,TN,TX,UT,VA,VI,VT,WA,WI,WV,WY", + "price": 0, + "id_carrier_detail": "4" } }, { @@ -132,15 +132,15 @@ "collection": "carrier_details", "properties": { "id_reference": "4", - "id_zone": "2", + "id_zone": "1", "id_range": "2", - "id_carrier_detail": "2", "shipping_method": "range_weight", "delimiter1": 0, "delimiter2": 1, - "country_ids": "", + "country_ids": "FR", "state_ids": "", - "price": 0 + "price": 0, + "id_carrier_detail": "2" } }, { @@ -149,14 +149,14 @@ "properties": { "id_reference": "4", "id_zone": "1", - "id_range": "2", - "id_carrier_detail": "2", + "id_range": "3", "shipping_method": "range_weight", - "delimiter1": 0, - "delimiter2": 1, - "country_ids": "", + "delimiter1": 1, + "delimiter2": 3, + "country_ids": "FR", "state_ids": "", - "price": 0 + "price": 2, + "id_carrier_detail": "3" } }, { @@ -164,15 +164,15 @@ "collection": "carrier_details", "properties": { "id_reference": "4", - "id_zone": "2", - "id_range": "3", - "id_carrier_detail": "3", + "id_zone": "1", + "id_range": "4", "shipping_method": "range_weight", - "delimiter1": 1, - "delimiter2": 3, - "country_ids": "", + "delimiter1": 3, + "delimiter2": 10000, + "country_ids": "FR", "state_ids": "", - "price": 3 + "price": 5, + "id_carrier_detail": "4" } }, { @@ -180,15 +180,15 @@ "collection": "carrier_details", "properties": { "id_reference": "4", - "id_zone": "1", - "id_range": "3", - "id_carrier_detail": "3", + "id_zone": "2", + "id_range": "2", "shipping_method": "range_weight", - "delimiter1": 1, - "delimiter2": 3, - "country_ids": "", - "state_ids": "", - "price": 2 + "delimiter1": 0, + "delimiter2": 1, + "country_ids": "US", + "state_ids": "AA,AE,AK,AL,AP,AR,AZ,CA,CO,CT,DC,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,PR,RI,SC,SD,TN,TX,UT,VA,VI,VT,WA,WI,WV,WY", + "price": 0, + "id_carrier_detail": "2" } }, { @@ -197,14 +197,14 @@ "properties": { "id_reference": "4", "id_zone": "2", - "id_range": "4", - "id_carrier_detail": "4", + "id_range": "3", "shipping_method": "range_weight", - "delimiter1": 3, - "delimiter2": 10000, - "country_ids": "", - "state_ids": "", - "price": 6 + "delimiter1": 1, + "delimiter2": 3, + "country_ids": "US", + "state_ids": "AA,AE,AK,AL,AP,AR,AZ,CA,CO,CT,DC,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,PR,RI,SC,SD,TN,TX,UT,VA,VI,VT,WA,WI,WV,WY", + "price": 3, + "id_carrier_detail": "3" } }, { @@ -212,15 +212,15 @@ "collection": "carrier_details", "properties": { "id_reference": "4", - "id_zone": "1", + "id_zone": "2", "id_range": "4", - "id_carrier_detail": "4", "shipping_method": "range_weight", "delimiter1": 3, "delimiter2": 10000, - "country_ids": "", - "state_ids": "", - "price": 5 + "country_ids": "US", + "state_ids": "AA,AE,AK,AL,AP,AR,AZ,CA,CO,CT,DC,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,PR,RI,SC,SD,TN,TX,UT,VA,VI,VT,WA,WI,WV,WY", + "price": 6, + "id_carrier_detail": "4" } } ] diff --git a/e2e/src/fixtures/8/carrier_details.json b/e2e/src/fixtures/8/carrier_details.json index 996e6aac..309a9a16 100644 --- a/e2e/src/fixtures/8/carrier_details.json +++ b/e2e/src/fixtures/8/carrier_details.json @@ -6,13 +6,13 @@ "id_reference": "2", "id_zone": "1", "id_range": "1", - "id_carrier_detail": "1", "shipping_method": "range_weight", "delimiter1": 0, "delimiter2": 10000, "country_ids": "FR", "state_ids": "", - "price": 5 + "price": 5, + "id_carrier_detail": "1" } }, { @@ -22,45 +22,45 @@ "id_reference": "2", "id_zone": "2", "id_range": "1", - "id_carrier_detail": "1", "shipping_method": "range_weight", "delimiter1": 0, "delimiter2": 10000, "country_ids": "US", - "state_ids": "AA,AE,AP,AL,AK,AZ,AR,CA,CO,CT,DE,FL,GA,HI,ID,IL,IN,IA,KS,KY,LA,ME,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VT,VA,WA,WV,WI,WY,PR,VI,DC", - "price": 5 + "state_ids": "AA,AE,AK,AL,AP,AR,AZ,CA,CO,CT,DC,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,PR,RI,SC,SD,TN,TX,UT,VA,VI,VT,WA,WI,WV,WY", + "price": 5, + "id_carrier_detail": "1" } }, { "action": "upsert", "collection": "carrier_details", "properties": { - "id_reference": "2", + "id_reference": "3", "id_zone": "1", - "id_range": "", - "id_carrier_detail": "", - "shipping_method": "range_weight", + "id_range": "2", + "shipping_method": "range_price", "delimiter1": 0, - "delimiter2": 0, + "delimiter2": 50, "country_ids": "FR", "state_ids": "", - "price": 5 + "price": 3, + "id_carrier_detail": "2" } }, { "action": "upsert", "collection": "carrier_details", "properties": { - "id_reference": "2", - "id_zone": "2", - "id_range": "", - "id_carrier_detail": "", - "shipping_method": "range_weight", - "delimiter1": 0, - "delimiter2": 0, - "country_ids": "US", - "state_ids": "AA,AE,AP,AL,AK,AZ,AR,CA,CO,CT,DE,FL,GA,HI,ID,IL,IN,IA,KS,KY,LA,ME,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VT,VA,WA,WV,WI,WY,PR,VI,DC", - "price": 5 + "id_reference": "3", + "id_zone": "1", + "id_range": "3", + "shipping_method": "range_price", + "delimiter1": 50, + "delimiter2": 100, + "country_ids": "FR", + "state_ids": "", + "price": 1, + "id_carrier_detail": "3" } }, { @@ -69,14 +69,14 @@ "properties": { "id_reference": "3", "id_zone": "1", - "id_range": "2", - "id_carrier_detail": "2", + "id_range": "4", "shipping_method": "range_price", - "delimiter1": 0, - "delimiter2": 50, + "delimiter1": 100, + "delimiter2": 200, "country_ids": "FR", "state_ids": "", - "price": 3 + "price": 0, + "id_carrier_detail": "4" } }, { @@ -86,29 +86,13 @@ "id_reference": "3", "id_zone": "2", "id_range": "2", - "id_carrier_detail": "2", "shipping_method": "range_price", "delimiter1": 0, "delimiter2": 50, "country_ids": "US", - "state_ids": "AA,AE,AP,AL,AK,AZ,AR,CA,CO,CT,DE,FL,GA,HI,ID,IL,IN,IA,KS,KY,LA,ME,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VT,VA,WA,WV,WI,WY,PR,VI,DC", - "price": 4 - } - }, - { - "action": "upsert", - "collection": "carrier_details", - "properties": { - "id_reference": "3", - "id_zone": "1", - "id_range": "3", - "id_carrier_detail": "3", - "shipping_method": "range_price", - "delimiter1": 50, - "delimiter2": 100, - "country_ids": "FR", - "state_ids": "", - "price": 1 + "state_ids": "AA,AE,AK,AL,AP,AR,AZ,CA,CO,CT,DC,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,PR,RI,SC,SD,TN,TX,UT,VA,VI,VT,WA,WI,WV,WY", + "price": 4, + "id_carrier_detail": "2" } }, { @@ -118,29 +102,13 @@ "id_reference": "3", "id_zone": "2", "id_range": "3", - "id_carrier_detail": "3", "shipping_method": "range_price", "delimiter1": 50, "delimiter2": 100, "country_ids": "US", - "state_ids": "AA,AE,AP,AL,AK,AZ,AR,CA,CO,CT,DE,FL,GA,HI,ID,IL,IN,IA,KS,KY,LA,ME,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VT,VA,WA,WV,WI,WY,PR,VI,DC", - "price": 2 - } - }, - { - "action": "upsert", - "collection": "carrier_details", - "properties": { - "id_reference": "3", - "id_zone": "1", - "id_range": "4", - "id_carrier_detail": "4", - "shipping_method": "range_price", - "delimiter1": 100, - "delimiter2": 200, - "country_ids": "FR", - "state_ids": "", - "price": 0 + "state_ids": "AA,AE,AK,AL,AP,AR,AZ,CA,CO,CT,DC,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,PR,RI,SC,SD,TN,TX,UT,VA,VI,VT,WA,WI,WV,WY", + "price": 2, + "id_carrier_detail": "3" } }, { @@ -150,13 +118,13 @@ "id_reference": "3", "id_zone": "2", "id_range": "4", - "id_carrier_detail": "4", "shipping_method": "range_price", "delimiter1": 100, "delimiter2": 200, "country_ids": "US", - "state_ids": "AA,AE,AP,AL,AK,AZ,AR,CA,CO,CT,DE,FL,GA,HI,ID,IL,IN,IA,KS,KY,LA,ME,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VT,VA,WA,WV,WI,WY,PR,VI,DC", - "price": 0 + "state_ids": "AA,AE,AK,AL,AP,AR,AZ,CA,CO,CT,DC,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,PR,RI,SC,SD,TN,TX,UT,VA,VI,VT,WA,WI,WV,WY", + "price": 0, + "id_carrier_detail": "4" } }, { @@ -166,13 +134,13 @@ "id_reference": "4", "id_zone": "1", "id_range": "2", - "id_carrier_detail": "2", "shipping_method": "range_weight", "delimiter1": 0, "delimiter2": 1, "country_ids": "FR", "state_ids": "", - "price": 0 + "price": 0, + "id_carrier_detail": "2" } }, { @@ -180,15 +148,15 @@ "collection": "carrier_details", "properties": { "id_reference": "4", - "id_zone": "2", - "id_range": "2", - "id_carrier_detail": "2", + "id_zone": "1", + "id_range": "3", "shipping_method": "range_weight", - "delimiter1": 0, - "delimiter2": 1, - "country_ids": "US", - "state_ids": "AA,AE,AP,AL,AK,AZ,AR,CA,CO,CT,DE,FL,GA,HI,ID,IL,IN,IA,KS,KY,LA,ME,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VT,VA,WA,WV,WI,WY,PR,VI,DC", - "price": 0 + "delimiter1": 1, + "delimiter2": 3, + "country_ids": "FR", + "state_ids": "", + "price": 2, + "id_carrier_detail": "3" } }, { @@ -197,14 +165,14 @@ "properties": { "id_reference": "4", "id_zone": "1", - "id_range": "3", - "id_carrier_detail": "3", + "id_range": "4", "shipping_method": "range_weight", - "delimiter1": 1, - "delimiter2": 3, + "delimiter1": 3, + "delimiter2": 10000, "country_ids": "FR", "state_ids": "", - "price": 2 + "price": 5, + "id_carrier_detail": "4" } }, { @@ -213,14 +181,14 @@ "properties": { "id_reference": "4", "id_zone": "2", - "id_range": "3", - "id_carrier_detail": "3", + "id_range": "2", "shipping_method": "range_weight", - "delimiter1": 1, - "delimiter2": 3, + "delimiter1": 0, + "delimiter2": 1, "country_ids": "US", - "state_ids": "AA,AE,AP,AL,AK,AZ,AR,CA,CO,CT,DE,FL,GA,HI,ID,IL,IN,IA,KS,KY,LA,ME,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VT,VA,WA,WV,WI,WY,PR,VI,DC", - "price": 3 + "state_ids": "AA,AE,AK,AL,AP,AR,AZ,CA,CO,CT,DC,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,PR,RI,SC,SD,TN,TX,UT,VA,VI,VT,WA,WI,WV,WY", + "price": 0, + "id_carrier_detail": "2" } }, { @@ -228,15 +196,15 @@ "collection": "carrier_details", "properties": { "id_reference": "4", - "id_zone": "1", - "id_range": "4", - "id_carrier_detail": "4", + "id_zone": "2", + "id_range": "3", "shipping_method": "range_weight", - "delimiter1": 3, - "delimiter2": 10000, - "country_ids": "FR", - "state_ids": "", - "price": 5 + "delimiter1": 1, + "delimiter2": 3, + "country_ids": "US", + "state_ids": "AA,AE,AK,AL,AP,AR,AZ,CA,CO,CT,DC,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,PR,RI,SC,SD,TN,TX,UT,VA,VI,VT,WA,WI,WV,WY", + "price": 3, + "id_carrier_detail": "3" } }, { @@ -246,13 +214,13 @@ "id_reference": "4", "id_zone": "2", "id_range": "4", - "id_carrier_detail": "4", "shipping_method": "range_weight", "delimiter1": 3, "delimiter2": 10000, "country_ids": "US", - "state_ids": "AA,AE,AP,AL,AK,AZ,AR,CA,CO,CT,DE,FL,GA,HI,ID,IL,IN,IA,KS,KY,LA,ME,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VT,VA,WA,WV,WI,WY,PR,VI,DC", - "price": 6 + "state_ids": "AA,AE,AK,AL,AP,AR,AZ,CA,CO,CT,DC,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,PR,RI,SC,SD,TN,TX,UT,VA,VI,VT,WA,WI,WV,WY", + "price": 6, + "id_carrier_detail": "4" } } ] diff --git a/e2e/src/fixtures/9/carrier_details.json b/e2e/src/fixtures/9/carrier_details.json index 2c206edd..309a9a16 100644 --- a/e2e/src/fixtures/9/carrier_details.json +++ b/e2e/src/fixtures/9/carrier_details.json @@ -2,188 +2,177 @@ { "action": "upsert", "collection": "carrier_details", - "properties": { - "id_reference": "3", + "id_reference": "2", + "id_zone": "1", + "id_range": "1", + "shipping_method": "range_weight", + "delimiter1": 0, + "delimiter2": 10000, + "country_ids": "FR", + "state_ids": "", + "price": 5, + "id_carrier_detail": "1" + } + }, + { + "action": "upsert", + "collection": "carrier_details", + "properties": { + "id_reference": "2", "id_zone": "2", - "id_range": "2", - "id_carrier_detail": "2", - "shipping_method": "range_price", + "id_range": "1", + "shipping_method": "range_weight", "delimiter1": 0, - "delimiter2": 50, + "delimiter2": 10000, "country_ids": "US", - "state_ids": "AA,AE,AP,AL,AK,AZ,AR,CA,CO,CT,DE,FL,GA,HI,ID,IL,IN,IA,KS,KY,LA,ME,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VT,VA,WA,WV,WI,WY,PR,VI,DC", - "price": 4 + "state_ids": "AA,AE,AK,AL,AP,AR,AZ,CA,CO,CT,DC,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,PR,RI,SC,SD,TN,TX,UT,VA,VI,VT,WA,WI,WV,WY", + "price": 5, + "id_carrier_detail": "1" } }, { "action": "upsert", "collection": "carrier_details", - "properties": { "id_reference": "3", "id_zone": "1", "id_range": "2", - "id_carrier_detail": "2", "shipping_method": "range_price", "delimiter1": 0, "delimiter2": 50, "country_ids": "FR", "state_ids": "", - "price": 3 + "price": 3, + "id_carrier_detail": "2" } }, { "action": "upsert", "collection": "carrier_details", - "properties": { "id_reference": "3", - "id_zone": "2", + "id_zone": "1", "id_range": "3", - "id_carrier_detail": "3", "shipping_method": "range_price", "delimiter1": 50, "delimiter2": 100, - "country_ids": "US", - "state_ids": "AA,AE,AP,AL,AK,AZ,AR,CA,CO,CT,DE,FL,GA,HI,ID,IL,IN,IA,KS,KY,LA,ME,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VT,VA,WA,WV,WI,WY,PR,VI,DC", - "price": 2 + "country_ids": "FR", + "state_ids": "", + "price": 1, + "id_carrier_detail": "3" } }, { "action": "upsert", "collection": "carrier_details", - "properties": { "id_reference": "3", "id_zone": "1", - "id_range": "3", - "id_carrier_detail": "3", + "id_range": "4", "shipping_method": "range_price", - "delimiter1": 50, - "delimiter2": 100, + "delimiter1": 100, + "delimiter2": 200, "country_ids": "FR", "state_ids": "", - "price": 1 + "price": 0, + "id_carrier_detail": "4" } }, { "action": "upsert", "collection": "carrier_details", - "properties": { "id_reference": "3", - "id_zone": "1", - "id_range": "4", - "id_carrier_detail": "4", + "id_zone": "2", + "id_range": "2", "shipping_method": "range_price", - "delimiter1": 100, - "delimiter2": 200, - "country_ids": "FR", - "state_ids": "", - "price": 0 + "delimiter1": 0, + "delimiter2": 50, + "country_ids": "US", + "state_ids": "AA,AE,AK,AL,AP,AR,AZ,CA,CO,CT,DC,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,PR,RI,SC,SD,TN,TX,UT,VA,VI,VT,WA,WI,WV,WY", + "price": 4, + "id_carrier_detail": "2" } }, { "action": "upsert", "collection": "carrier_details", - "properties": { "id_reference": "3", "id_zone": "2", - "id_range": "4", - "id_carrier_detail": "4", + "id_range": "3", "shipping_method": "range_price", - "delimiter1": 100, - "delimiter2": 200, + "delimiter1": 50, + "delimiter2": 100, "country_ids": "US", - "state_ids": "AA,AE,AP,AL,AK,AZ,AR,CA,CO,CT,DE,FL,GA,HI,ID,IL,IN,IA,KS,KY,LA,ME,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VT,VA,WA,WV,WI,WY,PR,VI,DC", - "price": 0 + "state_ids": "AA,AE,AK,AL,AP,AR,AZ,CA,CO,CT,DC,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,PR,RI,SC,SD,TN,TX,UT,VA,VI,VT,WA,WI,WV,WY", + "price": 2, + "id_carrier_detail": "3" } }, { "action": "upsert", "collection": "carrier_details", - "properties": { - "id_reference": "4", + "id_reference": "3", "id_zone": "2", - "id_range": "2", - "id_carrier_detail": "2", - "shipping_method": "range_weight", - "delimiter1": 0, - "delimiter2": 1, + "id_range": "4", + "shipping_method": "range_price", + "delimiter1": 100, + "delimiter2": 200, "country_ids": "US", - "state_ids": "AA,AE,AP,AL,AK,AZ,AR,CA,CO,CT,DE,FL,GA,HI,ID,IL,IN,IA,KS,KY,LA,ME,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VT,VA,WA,WV,WI,WY,PR,VI,DC", - "price": 0 + "state_ids": "AA,AE,AK,AL,AP,AR,AZ,CA,CO,CT,DC,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,PR,RI,SC,SD,TN,TX,UT,VA,VI,VT,WA,WI,WV,WY", + "price": 0, + "id_carrier_detail": "4" } }, { "action": "upsert", "collection": "carrier_details", - "properties": { "id_reference": "4", "id_zone": "1", "id_range": "2", - "id_carrier_detail": "2", "shipping_method": "range_weight", "delimiter1": 0, "delimiter2": 1, "country_ids": "FR", "state_ids": "", - "price": 0 + "price": 0, + "id_carrier_detail": "2" } }, { "action": "upsert", "collection": "carrier_details", - - "properties": { - "id_reference": "4", - "id_zone": "2", - "id_range": "3", - "id_carrier_detail": "3", - "shipping_method": "range_weight", - "delimiter1": 1, - "delimiter2": 3, - "country_ids": "US", - "state_ids": "AA,AE,AP,AL,AK,AZ,AR,CA,CO,CT,DE,FL,GA,HI,ID,IL,IN,IA,KS,KY,LA,ME,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VT,VA,WA,WV,WI,WY,PR,VI,DC", - "price": 3 - } - }, - { - "action": "upsert", - "collection": "carrier_details", - "properties": { "id_reference": "4", "id_zone": "1", "id_range": "3", - "id_carrier_detail": "3", "shipping_method": "range_weight", "delimiter1": 1, "delimiter2": 3, "country_ids": "FR", "state_ids": "", - "price": 2 + "price": 2, + "id_carrier_detail": "3" } }, { "action": "upsert", "collection": "carrier_details", - "properties": { "id_reference": "4", "id_zone": "1", "id_range": "4", - "id_carrier_detail": "4", "shipping_method": "range_weight", "delimiter1": 3, "delimiter2": 10000, "country_ids": "FR", "state_ids": "", - "price": 5 + "price": 5, + "id_carrier_detail": "4" } }, { @@ -192,48 +181,46 @@ "properties": { "id_reference": "4", "id_zone": "2", - "id_range": "4", - "id_carrier_detail": "4", + "id_range": "2", "shipping_method": "range_weight", - "delimiter1": 3, - "delimiter2": 10000, + "delimiter1": 0, + "delimiter2": 1, "country_ids": "US", - "state_ids": "AA,AE,AP,AL,AK,AZ,AR,CA,CO,CT,DE,FL,GA,HI,ID,IL,IN,IA,KS,KY,LA,ME,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VT,VA,WA,WV,WI,WY,PR,VI,DC", - "price": 6 + "state_ids": "AA,AE,AK,AL,AP,AR,AZ,CA,CO,CT,DC,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,PR,RI,SC,SD,TN,TX,UT,VA,VI,VT,WA,WI,WV,WY", + "price": 0, + "id_carrier_detail": "2" } }, { "action": "upsert", "collection": "carrier_details", - "properties": { - "id_reference": "2", - "id_zone": "1", - "id_range": "1", - "id_carrier_detail": "1", + "id_reference": "4", + "id_zone": "2", + "id_range": "3", "shipping_method": "range_weight", - "delimiter1": 0, - "delimiter2": 10000, - "country_ids": "FR", - "state_ids": "", - "price": 5 + "delimiter1": 1, + "delimiter2": 3, + "country_ids": "US", + "state_ids": "AA,AE,AK,AL,AP,AR,AZ,CA,CO,CT,DC,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,PR,RI,SC,SD,TN,TX,UT,VA,VI,VT,WA,WI,WV,WY", + "price": 3, + "id_carrier_detail": "3" } }, { "action": "upsert", "collection": "carrier_details", - "properties": { - "id_reference": "2", + "id_reference": "4", "id_zone": "2", - "id_range": "1", - "id_carrier_detail": "1", + "id_range": "4", "shipping_method": "range_weight", - "delimiter1": 0, + "delimiter1": 3, "delimiter2": 10000, "country_ids": "US", - "state_ids": "AA,AE,AP,AL,AK,AZ,AR,CA,CO,CT,DE,FL,GA,HI,ID,IL,IN,IA,KS,KY,LA,ME,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VT,VA,WA,WV,WI,WY,PR,VI,DC", - "price": 5 + "state_ids": "AA,AE,AK,AL,AP,AR,AZ,CA,CO,CT,DC,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,PR,RI,SC,SD,TN,TX,UT,VA,VI,VT,WA,WI,WV,WY", + "price": 6, + "id_carrier_detail": "4" } } ] diff --git a/src/Repository/CarrierDetailRepository.php b/src/Repository/CarrierDetailRepository.php index be9cd1c3..e34e3549 100644 --- a/src/Repository/CarrierDetailRepository.php +++ b/src/Repository/CarrierDetailRepository.php @@ -32,7 +32,7 @@ class CarrierDetailRepository extends AbstractRepository implements RepositoryInterface { - const TABLE_NAME = 'delivery'; + const TABLE_NAME = 'carrier'; /** * @param string $langIso @@ -44,17 +44,61 @@ class CarrierDetailRepository extends AbstractRepository implements RepositoryIn */ public function generateFullQuery($langIso, $withSelecParameters) { - $this->generateMinimalQuery(self::TABLE_NAME, 'd'); + $this->generateMinimalQuery(self::TABLE_NAME, 'ca'); + + $this->query + ->innerJoin('delivery', 'd', 'ca.id_carrier = d.id_carrier AND d.id_zone IS NOT NULL') + ->leftJoin('range_weight', 'rw', 'ca.id_carrier = rw.id_carrier AND d.id_range_weight = rw.id_range_weight') + ->leftJoin('range_price', 'rp', 'ca.id_carrier = rp.id_carrier AND d.id_range_price = rp.id_range_price') + ->leftJoin('country', 'co', 'd.id_zone = co.id_zone AND co.iso_code IS NOT NULL AND co.active = 1') + ->leftJoin('state', 's', 'co.id_zone = s.id_zone AND co.id_country = s.id_country AND s.active = 1') + ->leftJoin('configuration', 'conf', 'conf.name = "PS_SHIPPING_METHOD"') + ; if ($withSelecParameters) { $this->query - ->select('d.id_delivery') - ->select('d.id_carrier') - ->select('d.id_range_price') - ->select('d.id_range_weight') + ->select('ca.id_reference') ->select('d.id_zone') + ->select(' + CASE + WHEN d.id_range_weight IS NOT NULL AND d.id_range_weight != 0 THEN d.id_range_weight + WHEN d.id_range_price IS NOT NULL AND d.id_range_price != 0 THEN d.id_range_price + END AS id_range + ') + ->select(' + CASE + WHEN ca.is_free = 1 THEN "free_shipping" + WHEN ca.shipping_method = 0 AND conf.value IS NULL THEN "range_price" + WHEN ca.shipping_method = 0 AND conf.value IS NOT NULL THEN "range_weight" + WHEN ca.shipping_method = 1 THEN "range_weight" + WHEN ca.shipping_method = 2 THEN "range_price" + END AS shipping_method + ') + ->select(' + CASE + WHEN rw.delimiter1 IS NOT NULL THEN rw.delimiter1 + WHEN rp.delimiter1 IS NOT NULL THEN rp.delimiter1 + END AS delimiter1 + ') + ->select(' + CASE + WHEN rw.delimiter2 IS NOT NULL THEN rw.delimiter2 + WHEN rp.delimiter2 IS NOT NULL THEN rp.delimiter2 + END AS delimiter2 + ') + ->select('co.iso_code AS country_ids') + ->select(' + GROUP_CONCAT( + DISTINCT + s.iso_code + ORDER BY s.iso_code ASC + SEPARATOR \',\' + ) AS state_ids + ') ->select('d.price') ; + + $this->query->groupBy('ca.id_reference, co.id_zone, id_range, country_ids'); } } @@ -96,7 +140,7 @@ public function retrieveContentsForIncremental($limit, $contentIds, $langIso) $this->generateFullQuery($langIso, true); $this->query - ->where('d.id_carrier IN(' . implode(',', array_map('intval', $contentIds)) . ')') + ->where('ca.id_carrier IN(' . implode(',', array_map('intval', $contentIds)) . ')') ->limit($limit); return $this->runQuery(); @@ -114,12 +158,13 @@ public function retrieveContentsForIncremental($limit, $contentIds, $langIso) */ public function countFullSyncContentLeft($offset, $limit, $langIso) { - $this->generateFullQuery($langIso, false); - - $this->query->select('(COUNT(*) - ' . (int) $offset . ') as count'); + $this->generateFullQuery($langIso, true); - $result = $this->runQuery(true); + $result = $this->db->executeS(' + SELECT (COUNT(*) - ' . (int) $offset . ') AS count + FROM (' . $this->query->build() . ') as subquery; + '); - return $result[0]['count']; + return is_array($result) ? $result[0]['count'] : []; } } diff --git a/src/Service/ShopContent/CarrierDetailsService.php b/src/Service/ShopContent/CarrierDetailsService.php index 9a1a7f50..849928a4 100644 --- a/src/Service/ShopContent/CarrierDetailsService.php +++ b/src/Service/ShopContent/CarrierDetailsService.php @@ -71,13 +71,7 @@ public function getContentsForFull($offset, $limit, $langIso) return []; } - $carrierDetails = []; - - foreach ($result as $delivery) { - $carrierDetails[] = $this->buildCarrierDetail($delivery); - } - - $this->castCarrierDetails($carrierDetails); + $this->castCarrierDetails($result); return array_map(function ($item) { return [ @@ -85,7 +79,7 @@ public function getContentsForFull($offset, $limit, $langIso) 'collection' => Config::COLLECTION_CARRIER_DETAILS, 'properties' => $item, ]; - }, $carrierDetails); + }, $result); } /** @@ -101,13 +95,7 @@ public function getContentsForIncremental($limit, $upsertedContents, $deletedCon $result = $this->carrierDetailRepository->retrieveContentsForIncremental($limit, array_column($upsertedContents, 'id'), $langIso); if (!empty($result)) { - $carrierDetails = []; - - foreach ($result as $delivery) { - $carrierDetails[] = $this->buildCarrierDetail($delivery); - } - - $this->castCarrierDetails($carrierDetails); + $this->castCarrierDetails($result); } return parent::formatIncrementalSyncResponse(Config::COLLECTION_CARRIER_DETAILS, $result, $deletedContents); @@ -125,41 +113,6 @@ public function getFullSyncContentLeft($offset, $limit, $langIso) return $this->carrierDetailRepository->countFullSyncContentLeft($offset, $limit, $langIso); } - /** - * Build a CarrierDetail from delivery data - * - * @param array $delivery - * - * @return array - * - * @throws \PrestaShopDatabaseException - * @throws \PrestaShopException - */ - private function buildCarrierDetail($delivery) - { - $carrier = new \Carrier($delivery['id_carrier']); - $range = CarriersService::generateRange($carrier, $delivery); - - /** @var array $countryIsoCodes */ - $countryIsoCodes = $this->countryRepository->getCountryIsoCodesByZoneId($delivery['id_zone'], true); - - /** @var array $stateIsoCodes */ - $stateIsoCodes = $this->stateRepository->getStateIsoCodesByZoneId($delivery['id_zone'], true); - - return [ - 'id_reference' => $carrier->id_reference, - 'id_zone' => $delivery['id_zone'], - 'id_range' => $range ? $range->id : null, - 'id_carrier_detail' => $range ? $range->id : null, - 'shipping_method' => $carrier->getRangeTable(), - 'delimiter1' => $range ? $range->delimiter1 : null, - 'delimiter2' => $range ? $range->delimiter2 : null, - 'country_ids' => implode(',', $countryIsoCodes), - 'state_ids' => implode(',', $stateIsoCodes), - 'price' => $delivery['price'], - ]; - } - /** * @param array $carrierDetails * @@ -171,7 +124,7 @@ private function castCarrierDetails(&$carrierDetails) $carrierDetail['id_reference'] = (string) $carrierDetail['id_reference']; $carrierDetail['id_zone'] = (string) $carrierDetail['id_zone']; $carrierDetail['id_range'] = (string) $carrierDetail['id_range']; - $carrierDetail['id_carrier_detail'] = (string) $carrierDetail['id_carrier_detail']; + $carrierDetail['id_carrier_detail'] = (string) $carrierDetail['id_range']; // same value as id_range $carrierDetail['shipping_method'] = (string) $carrierDetail['shipping_method']; $carrierDetail['delimiter1'] = (float) $carrierDetail['delimiter1']; $carrierDetail['delimiter2'] = (float) $carrierDetail['delimiter2']; From 2e4119671aedb5eec2d7e2d8dc4c97253f42163f Mon Sep 17 00:00:00 2001 From: "John.R" Date: Fri, 15 Nov 2024 15:39:47 +0100 Subject: [PATCH 10/14] refactor: remove useless code --- config/common/repository.yml | 10 --- config/front/services.yml | 2 - src/Repository/CountryRepository.php | 70 ------------------- src/Repository/StateRepository.php | 67 ------------------ .../ShopContent/CarrierDetailsService.php | 16 +---- 5 files changed, 1 insertion(+), 164 deletions(-) delete mode 100644 src/Repository/CountryRepository.php delete mode 100644 src/Repository/StateRepository.php diff --git a/config/common/repository.yml b/config/common/repository.yml index 690d1869..d35e343b 100644 --- a/config/common/repository.yml +++ b/config/common/repository.yml @@ -15,16 +15,6 @@ services: class: PrestaShop\Module\PsEventbus\Repository\ShopRepository public: true - PrestaShop\Module\PsEventbus\Repository\CountryRepository: - class: PrestaShop\Module\PsEventbus\Repository\CountryRepository - public: true - arguments: - - '@=service("ps_eventbus").getContext()' - - PrestaShop\Module\PsEventbus\Repository\StateRepository: - class: PrestaShop\Module\PsEventbus\Repository\StateRepository - public: true - PrestaShop\Module\PsEventbus\Repository\LiveSyncRepository: class: PrestaShop\Module\PsEventbus\Repository\LiveSyncRepository public: true diff --git a/config/front/services.yml b/config/front/services.yml index 48a81550..a8c0a251 100644 --- a/config/front/services.yml +++ b/config/front/services.yml @@ -71,8 +71,6 @@ services: public: true arguments: - '@PrestaShop\Module\PsEventbus\Repository\CarrierDetailRepository' - - '@PrestaShop\Module\PsEventbus\Repository\CountryRepository' - - '@PrestaShop\Module\PsEventbus\Repository\StateRepository' PrestaShop\Module\PsEventbus\Service\ShopContent\CarrierTaxesService: class: PrestaShop\Module\PsEventbus\Service\ShopContent\CarrierTaxesService diff --git a/src/Repository/CountryRepository.php b/src/Repository/CountryRepository.php deleted file mode 100644 index e2bdd7b3..00000000 --- a/src/Repository/CountryRepository.php +++ /dev/null @@ -1,70 +0,0 @@ - - * @copyright Since 2007 PrestaShop SA and Contributors - * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) - */ - -namespace PrestaShop\Module\PsEventbus\Repository; - -if (!defined('_PS_VERSION_')) { - exit; -} - -class CountryRepository extends AbstractRepository -{ - const TABLE_NAME = 'country'; - - /** - * @param int $zoneId - * @param bool $active - * - * @return array - * - * @throws \PrestaShopDatabaseException - */ - public function getCountryIsoCodesByZoneId($zoneId, $active) - { - $isoCodes = []; - - $this->generateMinimalQuery(self::TABLE_NAME, 'c'); - - $this->query - ->innerJoin('country_shop', 'cs', 'cs.id_country = c.id_country') - ->innerJoin('country_lang', 'cl', 'cl.id_country = c.id_country') - ->where('cs.id_shop = ' . (int) parent::getShopContext()->id) - ->where('cl.id_lang = ' . (int) parent::getLanguageContext()->id) - ->where('id_zone = ' . (int) $zoneId) - ->where('active = ' . (bool) $active) - ; - - $this->query->select('iso_code'); - - $result = $this->runQuery(true); - - foreach ($result as $country) { - $isoCodes[] = $country['iso_code']; - } - - return $isoCodes; - } -} diff --git a/src/Repository/StateRepository.php b/src/Repository/StateRepository.php deleted file mode 100644 index e8663274..00000000 --- a/src/Repository/StateRepository.php +++ /dev/null @@ -1,67 +0,0 @@ - - * @copyright Since 2007 PrestaShop SA and Contributors - * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) - */ - -namespace PrestaShop\Module\PsEventbus\Repository; - -if (!defined('_PS_VERSION_')) { - exit; -} - -class StateRepository extends AbstractRepository -{ - const TABLE_NAME = 'state'; - - /** - * @param int $zoneId - * @param bool $active - * - * @return array - * - * @throws \PrestaShopDatabaseException - */ - public function getStateIsoCodesByZoneId($zoneId, $active) - { - $isoCodes = []; - - $this->generateMinimalQuery(self::TABLE_NAME, 's'); - - $this->query->innerJoin('country', 'c', 'c.id_country = s.id_country') - ->where('s.id_zone = ' . (int) $zoneId) - ->where('s.active = ' . (bool) $active) - ->where('c.active = ' . (bool) $active) - ; - - $this->query->select('s.iso_code'); - - $result = $this->runQuery(true); - - foreach ($result as $state) { - $isoCodes[] = $state['iso_code']; - } - - return $isoCodes; - } -} diff --git a/src/Service/ShopContent/CarrierDetailsService.php b/src/Service/ShopContent/CarrierDetailsService.php index 849928a4..01a219ad 100644 --- a/src/Service/ShopContent/CarrierDetailsService.php +++ b/src/Service/ShopContent/CarrierDetailsService.php @@ -28,8 +28,6 @@ use PrestaShop\Module\PsEventbus\Config\Config; use PrestaShop\Module\PsEventbus\Repository\CarrierDetailRepository; -use PrestaShop\Module\PsEventbus\Repository\CountryRepository; -use PrestaShop\Module\PsEventbus\Repository\StateRepository; if (!defined('_PS_VERSION_')) { exit; @@ -40,20 +38,8 @@ class CarrierDetailsService extends ShopContentAbstractService implements ShopCo /** @var CarrierDetailRepository */ private $carrierDetailRepository; - /** @var CountryRepository */ - private $countryRepository; - - /** @var StateRepository */ - private $stateRepository; - - public function __construct( - CarrierDetailRepository $carrierDetailRepository, - CountryRepository $countryRepository, - StateRepository $stateRepository - ) { + public function __construct(CarrierDetailRepository $carrierDetailRepository) { $this->carrierDetailRepository = $carrierDetailRepository; - $this->countryRepository = $countryRepository; - $this->stateRepository = $stateRepository; } /** From f4e3f287667abf9ba65b407a97464c29e48533af Mon Sep 17 00:00:00 2001 From: "John.R" Date: Fri, 15 Nov 2024 16:05:52 +0100 Subject: [PATCH 11/14] refactor: update naming of SyncRepository --- config/common/repository.yml | 12 ++++++------ config/front/services.yml | 6 +++--- src/Repository/EventbusSyncRepository.php | 2 +- src/Service/ApiAuthorizationService.php | 14 +++++++------- src/Service/ApiShopContentService.php | 14 +++++++------- .../ShopContent/CarrierDetailsService.php | 3 ++- src/Service/SynchronizationService.php | 16 ++++++++-------- 7 files changed, 34 insertions(+), 33 deletions(-) diff --git a/config/common/repository.yml b/config/common/repository.yml index d35e343b..3b475815 100644 --- a/config/common/repository.yml +++ b/config/common/repository.yml @@ -1,6 +1,6 @@ services: - PrestaShop\Module\PsEventbus\Repository\EventbusSyncRepository: - class: PrestaShop\Module\PsEventbus\Repository\EventbusSyncRepository + PrestaShop\Module\PsEventbus\Repository\SyncRepository: + class: PrestaShop\Module\PsEventbus\Repository\SyncRepository public: true arguments: - '@=service("ps_eventbus").getContext()' @@ -11,10 +11,6 @@ services: arguments: - '@PrestaShop\Module\PsEventbus\Handler\ErrorHandler\ErrorHandler' - PrestaShop\Module\PsEventbus\Repository\ShopRepository: - class: PrestaShop\Module\PsEventbus\Repository\ShopRepository - public: true - PrestaShop\Module\PsEventbus\Repository\LiveSyncRepository: class: PrestaShop\Module\PsEventbus\Repository\LiveSyncRepository public: true @@ -115,6 +111,10 @@ services: class: PrestaShop\Module\PsEventbus\Repository\ProductSupplierRepository public: true + PrestaShop\Module\PsEventbus\Repository\ShopRepository: + class: PrestaShop\Module\PsEventbus\Repository\ShopRepository + public: true + PrestaShop\Module\PsEventbus\Repository\StockRepository: class: PrestaShop\Module\PsEventbus\Repository\StockRepository public: true diff --git a/config/front/services.yml b/config/front/services.yml index a8c0a251..4efb7643 100644 --- a/config/front/services.yml +++ b/config/front/services.yml @@ -8,7 +8,7 @@ services: class: PrestaShop\Module\PsEventbus\Service\ApiAuthorizationService public: true arguments: - - '@PrestaShop\Module\PsEventbus\Repository\EventbusSyncRepository' + - '@PrestaShop\Module\PsEventbus\Repository\SyncRepository' - '@PrestaShop\Module\PsEventbus\Api\SyncApiClient' - '@PrestaShop\Module\PsEventbus\Service\PsAccountsAdapterService' - '@PrestaShop\Module\PsEventbus\Handler\ErrorHandler\ErrorHandler' @@ -18,7 +18,7 @@ services: public: true arguments: - '@PrestaShop\Module\PsEventbus\Api\LiveSyncApiClient' - - '@PrestaShop\Module\PsEventbus\Repository\EventbusSyncRepository' + - '@PrestaShop\Module\PsEventbus\Repository\SyncRepository' - '@PrestaShop\Module\PsEventbus\Repository\IncrementalSyncRepository' - '@PrestaShop\Module\PsEventbus\Repository\LiveSyncRepository' - '@PrestaShop\Module\PsEventbus\Service\ShopContent\LanguagesService' @@ -37,7 +37,7 @@ services: - '@PrestaShop\Module\PsEventbus\Handler\ErrorHandler\ErrorHandler' - '@PrestaShop\Module\PsEventbus\Service\ApiAuthorizationService' - '@PrestaShop\Module\PsEventbus\Service\SynchronizationService' - - '@PrestaShop\Module\PsEventbus\Repository\EventbusSyncRepository' + - '@PrestaShop\Module\PsEventbus\Repository\SyncRepository' - '@PrestaShop\Module\PsEventbus\Handler\ErrorHandler\ErrorHandler' PrestaShop\Module\PsEventbus\Service\ApiHealthCheckService: diff --git a/src/Repository/EventbusSyncRepository.php b/src/Repository/EventbusSyncRepository.php index 7217ff87..d92491ee 100644 --- a/src/Repository/EventbusSyncRepository.php +++ b/src/Repository/EventbusSyncRepository.php @@ -30,7 +30,7 @@ exit; } -class EventbusSyncRepository extends AbstractRepository +class SyncRepository extends AbstractRepository { const TYPE_SYNC_TABLE_NAME = 'eventbus_type_sync'; const JOB_TABLE_NAME = 'eventbus_job'; diff --git a/src/Service/ApiAuthorizationService.php b/src/Service/ApiAuthorizationService.php index dcf5ed5d..923975a6 100644 --- a/src/Service/ApiAuthorizationService.php +++ b/src/Service/ApiAuthorizationService.php @@ -30,7 +30,7 @@ use PrestaShop\Module\PsEventbus\Exception\EnvVarException; use PrestaShop\Module\PsEventbus\Exception\FirebaseException; use PrestaShop\Module\PsEventbus\Handler\ErrorHandler\ErrorHandler; -use PrestaShop\Module\PsEventbus\Repository\EventbusSyncRepository; +use PrestaShop\Module\PsEventbus\Repository\SyncRepository; if (!defined('_PS_VERSION_')) { exit; @@ -38,8 +38,8 @@ class ApiAuthorizationService { - /** @var EventbusSyncRepository */ - private $eventbusSyncRepository; + /** @var SyncRepository */ + private $syncRepository; /** @var SyncApiClient */ private $syncApiClient; @@ -51,12 +51,12 @@ class ApiAuthorizationService private $errorHandler; public function __construct( - EventbusSyncRepository $eventbusSyncRepository, + SyncRepository $syncRepository, SyncApiClient $syncApiClient, PsAccountsAdapterService $psAccountsAdapterService, ErrorHandler $errorHandler ) { - $this->eventbusSyncRepository = $eventbusSyncRepository; + $this->syncRepository = $syncRepository; $this->syncApiClient = $syncApiClient; $this->psAccountsAdapterService = $psAccountsAdapterService; $this->errorHandler = $errorHandler; @@ -118,7 +118,7 @@ public function authorize($jobId, $isHealthCheck) private function authorizeCall($jobId) { // Check if the job already exists - $job = $this->eventbusSyncRepository->findJobById($jobId); + $job = $this->syncRepository->findJobById($jobId); if ($job) { return true; @@ -132,6 +132,6 @@ private function authorizeCall($jobId) } // Cache the valid jobId - return $this->eventbusSyncRepository->insertJob($jobId, date(DATE_ATOM)); + return $this->syncRepository->insertJob($jobId, date(DATE_ATOM)); } } diff --git a/src/Service/ApiShopContentService.php b/src/Service/ApiShopContentService.php index 3cd78882..f4041e83 100644 --- a/src/Service/ApiShopContentService.php +++ b/src/Service/ApiShopContentService.php @@ -31,8 +31,8 @@ use PrestaShop\Module\PsEventbus\Exception\FirebaseException; use PrestaShop\Module\PsEventbus\Exception\QueryParamsException; use PrestaShop\Module\PsEventbus\Handler\ErrorHandler\ErrorHandler; -use PrestaShop\Module\PsEventbus\Repository\EventbusSyncRepository; use PrestaShop\Module\PsEventbus\Repository\IncrementalSyncRepository; +use PrestaShop\Module\PsEventbus\Repository\SyncRepository; use PrestaShop\Module\PsEventbus\Service\ShopContent\LanguagesService; use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; @@ -48,8 +48,8 @@ class ApiShopContentService /** @var ApiAuthorizationService */ private $apiAuthorizationService; - /** @var EventbusSyncRepository */ - private $eventbusSyncRepository; + /** @var SyncRepository */ + private $syncRepository; /** @var SynchronizationService */ private $synchronizationService; @@ -65,7 +65,7 @@ public function __construct( ErrorHandler $errorHandler, ApiAuthorizationService $apiAuthorizationService, SynchronizationService $synchronizationService, - EventbusSyncRepository $eventbusSyncRepository + SyncRepository $syncRepository ) { $this->startTime = time(); @@ -73,7 +73,7 @@ public function __construct( $this->errorHandler = $errorHandler; $this->apiAuthorizationService = $apiAuthorizationService; $this->synchronizationService = $synchronizationService; - $this->eventbusSyncRepository = $eventbusSyncRepository; + $this->syncRepository = $syncRepository; } /** @@ -107,7 +107,7 @@ public function handleDataSync($shopContent, $jobId, $langIso, $limit, $fullSync $dateNow = (new \DateTime('now', new \DateTimeZone($timezone)))->format(Config::MYSQL_DATE_FORMAT); $langIso = $langIso ? $langIso : $languagesService->getDefaultLanguageIsoCode(); - $typeSync = $this->eventbusSyncRepository->findTypeSync($shopContent, $langIso); + $typeSync = $this->syncRepository->findTypeSync($shopContent, $langIso); // If no typesync exist, or if fullsync is requested by user if (!is_array($typeSync) || $fullSyncRequested) { @@ -121,7 +121,7 @@ public function handleDataSync($shopContent, $jobId, $langIso, $limit, $fullSync $incrementalSyncRepository->removeIncrementaSyncObjectByType($shopContent); } - $this->eventbusSyncRepository->upsertTypeSync( + $this->syncRepository->upsertTypeSync( $shopContent, $offset, $dateNow, diff --git a/src/Service/ShopContent/CarrierDetailsService.php b/src/Service/ShopContent/CarrierDetailsService.php index 01a219ad..b5b477f6 100644 --- a/src/Service/ShopContent/CarrierDetailsService.php +++ b/src/Service/ShopContent/CarrierDetailsService.php @@ -38,7 +38,8 @@ class CarrierDetailsService extends ShopContentAbstractService implements ShopCo /** @var CarrierDetailRepository */ private $carrierDetailRepository; - public function __construct(CarrierDetailRepository $carrierDetailRepository) { + public function __construct(CarrierDetailRepository $carrierDetailRepository) + { $this->carrierDetailRepository = $carrierDetailRepository; } diff --git a/src/Service/SynchronizationService.php b/src/Service/SynchronizationService.php index 239efce6..5a275ba9 100644 --- a/src/Service/SynchronizationService.php +++ b/src/Service/SynchronizationService.php @@ -29,9 +29,9 @@ use PrestaShop\Module\PsEventbus\Api\LiveSyncApiClient; use PrestaShop\Module\PsEventbus\Config\Config; use PrestaShop\Module\PsEventbus\Handler\ErrorHandler\ErrorHandler; -use PrestaShop\Module\PsEventbus\Repository\EventbusSyncRepository; use PrestaShop\Module\PsEventbus\Repository\IncrementalSyncRepository; use PrestaShop\Module\PsEventbus\Repository\LiveSyncRepository; +use PrestaShop\Module\PsEventbus\Repository\SyncRepository; use PrestaShop\Module\PsEventbus\Service\ShopContent\LanguagesService; use PrestaShop\Module\PsEventbus\Service\ShopContent\ShopContentServiceInterface; use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; @@ -48,9 +48,9 @@ class SynchronizationService private $liveSyncApiClient; /** - * @var EventbusSyncRepository + * @var SyncRepository */ - private $eventbusSyncRepository; + private $syncRepository; /** * @var IncrementalSyncRepository @@ -79,7 +79,7 @@ class SynchronizationService public function __construct( LiveSyncApiClient $liveSyncApiClient, - EventbusSyncRepository $eventbusSyncRepository, + SyncRepository $syncRepository, IncrementalSyncRepository $incrementalSyncRepository, LiveSyncRepository $liveSyncRepository, LanguagesService $languagesService, @@ -87,7 +87,7 @@ public function __construct( ErrorHandler $errorHandler ) { $this->liveSyncApiClient = $liveSyncApiClient; - $this->eventbusSyncRepository = $eventbusSyncRepository; + $this->syncRepository = $syncRepository; $this->incrementalSyncRepository = $incrementalSyncRepository; $this->liveSyncRepository = $liveSyncRepository; $this->languagesService = $languagesService; @@ -151,7 +151,7 @@ public function sendFullSync( $offset = 0; } - $this->eventbusSyncRepository->upsertTypeSync($shopContent, $offset, $dateNow, $remainingObjects === 0, $langIso); + $this->syncRepository->upsertTypeSync($shopContent, $offset, $dateNow, $remainingObjects === 0, $langIso); return $this->returnSyncResponse($data, $response, $remainingObjects); } @@ -281,7 +281,7 @@ public function insertContentIntoIncremental($contentTypesWithIds, $actionType, $hasDeleted = $this->incrementalSyncRepository->removeIncrementaSyncObjectByType($contentType); if ($hasDeleted) { - $this->eventbusSyncRepository->upsertTypeSync( + $this->syncRepository->upsertTypeSync( $contentType, 0, $createdAt, @@ -386,7 +386,7 @@ private function debounceLiveSync($shopContentName) // @phpstan-ignore method.un */ private function isFullSyncDone($shopContent, $langIso) { - return $this->eventbusSyncRepository->isFullSyncDoneForThisTypeSync($shopContent, $langIso); + return $this->syncRepository->isFullSyncDoneForThisTypeSync($shopContent, $langIso); } /** From d59da3e6af37b09399f5deb18c542e05de4d26be Mon Sep 17 00:00:00 2001 From: "John.R" Date: Fri, 15 Nov 2024 16:30:23 +0100 Subject: [PATCH 12/14] fix: rename missing file --- src/Repository/{EventbusSyncRepository.php => SyncRepository.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/Repository/{EventbusSyncRepository.php => SyncRepository.php} (100%) diff --git a/src/Repository/EventbusSyncRepository.php b/src/Repository/SyncRepository.php similarity index 100% rename from src/Repository/EventbusSyncRepository.php rename to src/Repository/SyncRepository.php From 5b0a0eb29752fae6b2808a83fbb3be3a822af56a Mon Sep 17 00:00:00 2001 From: "John.R" Date: Tue, 19 Nov 2024 11:04:06 +0100 Subject: [PATCH 13/14] fix: country_iso_code type for carrier details --- src/Repository/CarrierDetailRepository.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Repository/CarrierDetailRepository.php b/src/Repository/CarrierDetailRepository.php index e34e3549..a44577e1 100644 --- a/src/Repository/CarrierDetailRepository.php +++ b/src/Repository/CarrierDetailRepository.php @@ -86,7 +86,13 @@ public function generateFullQuery($langIso, $withSelecParameters) WHEN rp.delimiter2 IS NOT NULL THEN rp.delimiter2 END AS delimiter2 ') - ->select('co.iso_code AS country_ids') + ->select(' + GROUP_CONCAT( + DISTINCT co.iso_code + ORDER BY co.iso_code ASC + SEPARATOR \',\' + ) AS country_ids + ') ->select(' GROUP_CONCAT( DISTINCT @@ -98,7 +104,7 @@ public function generateFullQuery($langIso, $withSelecParameters) ->select('d.price') ; - $this->query->groupBy('ca.id_reference, co.id_zone, id_range, country_ids'); + $this->query->groupBy('ca.id_reference, co.id_zone, id_range'); } } From 7e6e4b5bbe8aca656101f42badb7e00073e08b51 Mon Sep 17 00:00:00 2001 From: "John.R" Date: Tue, 19 Nov 2024 15:58:06 +0100 Subject: [PATCH 14/14] fix: missing --- src/Repository/CarrierTaxeRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Repository/CarrierTaxeRepository.php b/src/Repository/CarrierTaxeRepository.php index 6cb61304..485e58d4 100644 --- a/src/Repository/CarrierTaxeRepository.php +++ b/src/Repository/CarrierTaxeRepository.php @@ -124,7 +124,7 @@ public function retrieveContentsForIncremental($limit, $contentIds, $langIso) $this->generateFullQuery($langIso, true); $this->query - ->where('d.id_carrier IN(' . implode(',', array_map('intval', $contentIds)) . ')') + ->where('ca.id_carrier IN(' . implode(',', array_map('intval', $contentIds)) . ')') ->limit($limit); return $this->runQuery();