diff --git a/config/common/repository.yml b/config/common/repository.yml index 0188df65..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,26 +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\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\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 +27,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 @@ -123,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 93eb94f4..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: @@ -70,13 +70,13 @@ services: class: PrestaShop\Module\PsEventbus\Service\ShopContent\CarrierDetailsService public: true arguments: - - '@PrestaShop\Module\PsEventbus\Repository\CarrierRepository' + - '@PrestaShop\Module\PsEventbus\Repository\CarrierDetailRepository' PrestaShop\Module\PsEventbus\Service\ShopContent\CarrierTaxesService: 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/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 68f95f5e..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,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": "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" } }, { @@ -38,13 +38,13 @@ "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" } }, { @@ -52,15 +52,15 @@ "collection": "carrier_details", "properties": { "id_reference": "3", - "id_zone": "2", - "id_range": "2", - "id_carrier_detail": "2", + "id_zone": "1", + "id_range": "3", "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 + "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": "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" } }, { @@ -85,14 +85,14 @@ "properties": { "id_reference": "3", "id_zone": "2", - "id_range": "3", - "id_carrier_detail": "3", + "id_range": "2", "shipping_method": "range_price", - "delimiter1": 50, - "delimiter2": 100, + "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": 2 + "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" } }, { @@ -100,15 +100,15 @@ "collection": "carrier_details", "properties": { "id_reference": "3", - "id_zone": "1", - "id_range": "4", - "id_carrier_detail": "4", + "id_zone": "2", + "id_range": "3", "shipping_method": "range_price", - "delimiter1": 100, - "delimiter2": 200, - "country_ids": "FR", - "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" } }, { @@ -118,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" } }, { @@ -134,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" } }, { @@ -148,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" } }, { @@ -165,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" } }, { @@ -181,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" } }, { @@ -196,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" } }, { @@ -214,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/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/CarrierDetailRepository.php b/src/Repository/CarrierDetailRepository.php new file mode 100644 index 00000000..a44577e1 --- /dev/null +++ b/src/Repository/CarrierDetailRepository.php @@ -0,0 +1,176 @@ + + * @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 CarrierDetailRepository extends AbstractRepository implements RepositoryInterface +{ + const TABLE_NAME = 'carrier'; + + /** + * @param string $langIso + * @param bool $withSelecParameters + * + * @return mixed + * + * @throws \PrestaShopException + */ + public function generateFullQuery($langIso, $withSelecParameters) + { + $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('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(' + GROUP_CONCAT( + DISTINCT co.iso_code + ORDER BY co.iso_code ASC + SEPARATOR \',\' + ) 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'); + } + } + + /** + * @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('ca.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, true); + + $result = $this->db->executeS(' + SELECT (COUNT(*) - ' . (int) $offset . ') AS count + FROM (' . $this->query->build() . ') as subquery; + '); + + return is_array($result) ? $result[0]['count'] : []; + } +} diff --git a/src/Repository/CarrierTaxeRepository.php b/src/Repository/CarrierTaxeRepository.php new file mode 100644 index 00000000..485e58d4 --- /dev/null +++ b/src/Repository/CarrierTaxeRepository.php @@ -0,0 +1,154 @@ + + * @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 CarrierTaxeRepository extends AbstractRepository implements RepositoryInterface +{ + const TABLE_NAME = 'carrier'; + + /** + * @param string $langIso + * @param bool $withSelecParameters + * + * @return mixed + * + * @throws \PrestaShopException + */ + public function generateFullQuery($langIso, $withSelecParameters) + { + $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') + ->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.id_zone = d.id_zone OR s.id_zone = d.id_zone)') + ; + + 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 + s.iso_code + ORDER BY s.iso_code ASC + SEPARATOR \',\' + ) AS state_ids + ') + ->select('t.rate AS tax_rate') + ; + + $this->query->groupBy('ca.id_reference, co.id_zone, id_range, country_id'); + } + } + + /** + * @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('ca.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, true); + + $result = $this->db->executeS(' + SELECT (COUNT(*) - ' . (int) $offset . ') AS count + FROM (' . $this->query->build() . ') as subquery; + '); + + return is_array($result) ? $result[0]['count'] : []; + } +} 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/Repository/EventbusSyncRepository.php b/src/Repository/SyncRepository.php similarity index 98% rename from src/Repository/EventbusSyncRepository.php rename to src/Repository/SyncRepository.php index 7217ff87..d92491ee 100644 --- a/src/Repository/EventbusSyncRepository.php +++ b/src/Repository/SyncRepository.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/Repository/TaxeRepository.php b/src/Repository/TaxeRepository.php deleted file mode 100644 index 3d1064d0..00000000 --- a/src/Repository/TaxeRepository.php +++ /dev/null @@ -1,75 +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 TaxeRepository extends AbstractRepository -{ - const TABLE_NAME = 'tax'; - - /** - * @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_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/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 8cdbb1ae..b5b477f6 100644 --- a/src/Service/ShopContent/CarrierDetailsService.php +++ b/src/Service/ShopContent/CarrierDetailsService.php @@ -27,9 +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\CountryRepository; -use PrestaShop\Module\PsEventbus\Repository\StateRepository; +use PrestaShop\Module\PsEventbus\Repository\CarrierDetailRepository; if (!defined('_PS_VERSION_')) { exit; @@ -37,12 +35,12 @@ class CarrierDetailsService extends ShopContentAbstractService implements ShopContentServiceInterface { - /** @var CarrierRepository */ - private $carrierRepository; + /** @var CarrierDetailRepository */ + private $carrierDetailRepository; - public function __construct(CarrierRepository $carrierRepository) + public function __construct(CarrierDetailRepository $carrierDetailRepository) { - $this->carrierRepository = $carrierRepository; + $this->carrierDetailRepository = $carrierDetailRepository; } /** @@ -54,19 +52,13 @@ public function __construct(CarrierRepository $carrierRepository) */ public function getContentsForFull($offset, $limit, $langIso) { - $result = $this->carrierRepository->retrieveContentsForFull($offset, $limit, $langIso); + $result = $this->carrierDetailRepository->retrieveContentsForFull($offset, $limit, $langIso); if (empty($result)) { return []; } - $carrierDetails = []; - - foreach ($result as $carrierData) { - $carrierDetails = array_merge($carrierDetails, $this->buildCarrierDetails($carrierData)); - } - - $this->castCarrierDetails($carrierDetails); + $this->castCarrierDetails($result); return array_map(function ($item) { return [ @@ -74,7 +66,7 @@ public function getContentsForFull($offset, $limit, $langIso) 'collection' => Config::COLLECTION_CARRIER_DETAILS, 'properties' => $item, ]; - }, $carrierDetails); + }, $result); } /** @@ -87,16 +79,10 @@ 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->carrierDetailRepository->retrieveContentsForIncremental($limit, array_column($upsertedContents, 'id'), $langIso); if (!empty($result)) { - $carrierDetails = []; - - foreach ($result as $carrierData) { - $carrierDetails = array_merge($carrierDetails, $this->buildCarrierDetails($carrierData)); - } - - $this->castCarrierDetails($carrierDetails); + $this->castCarrierDetails($result); } return parent::formatIncrementalSyncResponse(Config::COLLECTION_CARRIER_DETAILS, $result, $deletedContents); @@ -111,7 +97,7 @@ public function getContentsForIncremental($limit, $upsertedContents, $deletedCon */ public function getFullSyncContentLeft($offset, $limit, $langIso) { - return $this->carrierRepository->countFullSyncContentLeft($offset, $limit, $langIso); + return $this->carrierDetailRepository->countFullSyncContentLeft($offset, $limit, $langIso); } /** @@ -125,7 +111,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']; @@ -134,68 +120,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/CarrierTaxesService.php b/src/Service/ShopContent/CarrierTaxesService.php index 6dcf534a..97eecc20 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,12 @@ class CarrierTaxesService extends ShopContentAbstractService implements ShopContentServiceInterface { - /** @var CarrierRepository */ - private $carrierRepository; + /** @var CarrierTaxeRepository */ + private $carrierTaxeRepository; - public function __construct(CarrierRepository $carrierRepository) + public function __construct(CarrierTaxeRepository $carrierTaxeRepository) { - $this->carrierRepository = $carrierRepository; + $this->carrierTaxeRepository = $carrierTaxeRepository; } /** @@ -53,19 +52,13 @@ 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 []; } - $carrierTaxes = []; - - foreach ($result as $carrierData) { - $carrierTaxes = array_merge($carrierTaxes, $this->buildCarrierTaxes($carrierData)); - } - - $this->castCarrierTaxes($carrierTaxes); + $this->castCarrierTaxes($result); return array_map(function ($item) { return [ @@ -73,7 +66,7 @@ public function getContentsForFull($offset, $limit, $langIso) 'collection' => Config::COLLECTION_CARRIER_TAXES, 'properties' => $item, ]; - }, $carrierTaxes); + }, $result); } /** @@ -86,16 +79,10 @@ 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)); - } - - $this->castCarrierTaxes($carrierTaxes); + $this->castCarrierTaxes($result); } return parent::formatIncrementalSyncResponse(Config::COLLECTION_CARRIER_TAXES, $result, $deletedContents); @@ -110,9 +97,7 @@ 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); } /** @@ -127,73 +112,9 @@ private function castCarrierTaxes(&$carrierTaxes) $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['country_id'] = (string) $carrierTaxe['country_id']; $carrierTaxe['state_ids'] = (string) $carrierTaxe['state_ids']; $carrierTaxe['tax_rate'] = (float) $carrierTaxe['tax_rate']; } } - - /** - * Build a CarrierTaxes from Carrier - * - * @param array $carrierData - * - * @return array - * - * @throws \PrestaShopDatabaseException - * @throws \PrestaShopException - */ - private function buildCarrierTaxes($carrierData) - { - /** @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 = []; - - foreach ($deliveryPriceByRanges as $deliveryPriceByRange) { - $range = CarriersService::getCarrierRange($deliveryPriceByRange); - - if (!$range) { - 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); - } - } - - return $carrierTaxes; - } } 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; } /** 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); } /**