From d0a22aeae3ea49855586499373c5d1f7b7df0871 Mon Sep 17 00:00:00 2001 From: "John.R" Date: Fri, 22 Nov 2024 15:23:48 +0100 Subject: [PATCH 1/2] fix: add attributes shop content --- config/front/services.yml | 4 + e2e/src/fixtures/1.6/attributes.json | 1 + e2e/src/fixtures/1.7/attributes.json | 1 + e2e/src/fixtures/8/attributes.json | 1 + e2e/src/fixtures/9/attributes.json | 1 + e2e/src/helpers/shop-contents.ts | 1 + src/Config/Config.php | 2 + src/Service/ShopContent/AttributesService.php | 75 +++++++++++++++++++ src/Traits/UseHooks.php | 4 +- 9 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 e2e/src/fixtures/1.6/attributes.json create mode 100644 e2e/src/fixtures/1.7/attributes.json create mode 100644 e2e/src/fixtures/8/attributes.json create mode 100644 e2e/src/fixtures/9/attributes.json create mode 100644 src/Service/ShopContent/AttributesService.php diff --git a/config/front/services.yml b/config/front/services.yml index 4efb7643..15959e8e 100644 --- a/config/front/services.yml +++ b/config/front/services.yml @@ -54,6 +54,10 @@ services: ############################################################################################################ ###################################### SHOP CONTENT SERVICES ############################################### ############################################################################################################ + PrestaShop\Module\PsEventbus\Service\ShopContent\AttributesService: + class: PrestaShop\Module\PsEventbus\Service\ShopContent\AttributesService + public: true + PrestaShop\Module\PsEventbus\Service\ShopContent\BundlesService: class: PrestaShop\Module\PsEventbus\Service\ShopContent\BundlesService public: true diff --git a/e2e/src/fixtures/1.6/attributes.json b/e2e/src/fixtures/1.6/attributes.json new file mode 100644 index 00000000..fe51488c --- /dev/null +++ b/e2e/src/fixtures/1.6/attributes.json @@ -0,0 +1 @@ +[] diff --git a/e2e/src/fixtures/1.7/attributes.json b/e2e/src/fixtures/1.7/attributes.json new file mode 100644 index 00000000..fe51488c --- /dev/null +++ b/e2e/src/fixtures/1.7/attributes.json @@ -0,0 +1 @@ +[] diff --git a/e2e/src/fixtures/8/attributes.json b/e2e/src/fixtures/8/attributes.json new file mode 100644 index 00000000..fe51488c --- /dev/null +++ b/e2e/src/fixtures/8/attributes.json @@ -0,0 +1 @@ +[] diff --git a/e2e/src/fixtures/9/attributes.json b/e2e/src/fixtures/9/attributes.json new file mode 100644 index 00000000..fe51488c --- /dev/null +++ b/e2e/src/fixtures/9/attributes.json @@ -0,0 +1 @@ +[] diff --git a/e2e/src/helpers/shop-contents.ts b/e2e/src/helpers/shop-contents.ts index a654217c..ed67ac07 100644 --- a/e2e/src/helpers/shop-contents.ts +++ b/e2e/src/helpers/shop-contents.ts @@ -1,6 +1,7 @@ import R from "ramda"; export const shopContentMapping = { + attributes: "attributes", bundles: "bundles", carriers: "carriers", carrier_details: "carrier-details", diff --git a/src/Config/Config.php b/src/Config/Config.php index 99f6e6cf..916f46d9 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -64,6 +64,7 @@ class Config self::PS_ACCOUNTS_NOT_INSTALLED => 'PsAccounts not installed', ]; + const COLLECTION_ATTRIBUTES = 'attributes'; const COLLECTION_BUNDLES = 'bundles'; const COLLECTION_CARRIERS = 'carriers'; const COLLECTION_CARRIER_DETAILS = 'carrier_details'; @@ -101,6 +102,7 @@ class Config const COLLECTION_WISHLIST_PRODUCTS = 'wishlist_products'; const SHOP_CONTENTS = [ + self::COLLECTION_ATTRIBUTES, self::COLLECTION_BUNDLES, self::COLLECTION_CARRIERS, self::COLLECTION_CARRIER_DETAILS, diff --git a/src/Service/ShopContent/AttributesService.php b/src/Service/ShopContent/AttributesService.php new file mode 100644 index 00000000..9055003c --- /dev/null +++ b/src/Service/ShopContent/AttributesService.php @@ -0,0 +1,75 @@ + + * @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\Service\ShopContent; + +use PrestaShop\Module\PsEventbus\Config\Config; + +if (!defined('_PS_VERSION_')) { + exit; +} + +// The service exists solely because it is necessary to notify CloudSync about the deleted content, +// and there is nothing specific to synchronize in full sync, or that has been upserted. +class AttributesService extends ShopContentAbstractService implements ShopContentServiceInterface +{ + /** + * @param int $offset + * @param int $limit + * @param string $langIso + * + * @return array + */ + public function getContentsForFull($offset, $limit, $langIso) + { + return []; + } + + /** + * @param int $limit + * @param array $upsertedContents + * @param array $deletedContents + * @param string $langIso + * + * @return array + */ + public function getContentsForIncremental($limit, $upsertedContents, $deletedContents, $langIso) + { + return parent::formatIncrementalSyncResponse(Config::COLLECTION_BUNDLES, [], $deletedContents); + } + + /** + * @param int $offset + * @param int $limit + * @param string $langIso + * + * @return int + */ + public function getFullSyncContentLeft($offset, $limit, $langIso) + { + return 0; + } +} diff --git a/src/Traits/UseHooks.php b/src/Traits/UseHooks.php index 1a3af64d..1b03feb3 100644 --- a/src/Traits/UseHooks.php +++ b/src/Traits/UseHooks.php @@ -767,9 +767,9 @@ public function hookActionObjectCombinationDeleteAfter($parameters) $combination = $parameters['object']; if (isset($combination->id)) { - $synchronizationService->sendLiveSync(Config::COLLECTION_PRODUCTS, 'delete'); + $synchronizationService->sendLiveSync(Config::COLLECTION_ATTRIBUTES, 'delete'); $synchronizationService->insertContentIntoIncremental( - [Config::COLLECTION_PRODUCTS => $combination->id], + [Config::COLLECTION_ATTRIBUTES => $combination->id], Config::INCREMENTAL_TYPE_DELETE, date(DATE_ATOM), $this->shopId, From f1016609f7e8cedd16b46b357906e458d29140cf Mon Sep 17 00:00:00 2001 From: "John.R" Date: Fri, 22 Nov 2024 15:49:16 +0100 Subject: [PATCH 2/2] fix: format --- e2e/src/fixtures/1.6/carrier_details.json | 33 +- e2e/src/fixtures/8/carrier_details.json | 449 +++++++++++----------- 2 files changed, 240 insertions(+), 242 deletions(-) diff --git a/e2e/src/fixtures/1.6/carrier_details.json b/e2e/src/fixtures/1.6/carrier_details.json index 32492964..e0ec1665 100644 --- a/e2e/src/fixtures/1.6/carrier_details.json +++ b/e2e/src/fixtures/1.6/carrier_details.json @@ -1,19 +1,18 @@ [ - { - "action": "upsert", - "collection": "carrier_details", - "properties": { - "id_reference": "2", - "id_zone": "1", - "id_range": "1", - "shipping_method": "range_weight", - "delimiter1": 0, - "delimiter2": 10000, - "country_ids": "GB", - "state_ids": "", - "price": 5, - "id_carrier_detail": "1" - } + { + "action": "upsert", + "collection": "carrier_details", + "properties": { + "id_reference": "2", + "id_zone": "1", + "id_range": "1", + "shipping_method": "range_weight", + "delimiter1": 0, + "delimiter2": 10000, + "country_ids": "GB", + "state_ids": "", + "price": 5, + "id_carrier_detail": "1" } - ] - \ No newline at end of file + } +] diff --git a/e2e/src/fixtures/8/carrier_details.json b/e2e/src/fixtures/8/carrier_details.json index 29bcbd62..89f4a992 100644 --- a/e2e/src/fixtures/8/carrier_details.json +++ b/e2e/src/fixtures/8/carrier_details.json @@ -1,227 +1,226 @@ [ - { - "action": "upsert", - "collection": "carrier_details", - "properties": { - "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": "1", - "shipping_method": "range_weight", - "delimiter1": 0, - "delimiter2": 10000, - "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" - } - }, - { - "action": "upsert", - "collection": "carrier_details", - "properties": { - "id_reference": "3", - "id_zone": "1", - "id_range": "2", - "shipping_method": "range_price", - "delimiter1": 0, - "delimiter2": 50, - "country_ids": "FR", - "state_ids": "", - "price": 0, - "id_carrier_detail": "2" - } - }, - { - "action": "upsert", - "collection": "carrier_details", - "properties": { - "id_reference": "3", - "id_zone": "1", - "id_range": "3", - "shipping_method": "range_price", - "delimiter1": 50, - "delimiter2": 100, - "country_ids": "FR", - "state_ids": "", - "price": 0, - "id_carrier_detail": "3" - } - }, - { - "action": "upsert", - "collection": "carrier_details", - "properties": { - "id_reference": "3", - "id_zone": "1", - "id_range": "4", - "shipping_method": "range_price", - "delimiter1": 100, - "delimiter2": 200, - "country_ids": "FR", - "state_ids": "", - "price": 0, - "id_carrier_detail": "4" - } - }, - { - "action": "upsert", - "collection": "carrier_details", - "properties": { - "id_reference": "3", - "id_zone": "2", - "id_range": "2", - "shipping_method": "range_price", - "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": 0, - "id_carrier_detail": "2" - } - }, - { - "action": "upsert", - "collection": "carrier_details", - "properties": { - "id_reference": "3", - "id_zone": "2", - "id_range": "3", - "shipping_method": "range_price", - "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": 0, - "id_carrier_detail": "3" - } - }, - { - "action": "upsert", - "collection": "carrier_details", - "properties": { - "id_reference": "3", - "id_zone": "2", - "id_range": "4", - "shipping_method": "range_price", - "delimiter1": 100, - "delimiter2": 200, - "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" - } - }, - { - "action": "upsert", - "collection": "carrier_details", - "properties": { - "id_reference": "4", - "id_zone": "1", - "id_range": "2", - "shipping_method": "range_weight", - "delimiter1": 0, - "delimiter2": 1, - "country_ids": "FR", - "state_ids": "", - "price": 6, - "id_carrier_detail": "2" - } - }, - { - "action": "upsert", - "collection": "carrier_details", - "properties": { - "id_reference": "4", - "id_zone": "1", - "id_range": "3", - "shipping_method": "range_weight", - "delimiter1": 1, - "delimiter2": 3, - "country_ids": "FR", - "state_ids": "", - "price": 6, - "id_carrier_detail": "3" - } - }, - { - "action": "upsert", - "collection": "carrier_details", - "properties": { - "id_reference": "4", - "id_zone": "1", - "id_range": "4", - "shipping_method": "range_weight", - "delimiter1": 3, - "delimiter2": 10000, - "country_ids": "FR", - "state_ids": "", - "price": 6, - "id_carrier_detail": "4" - } - }, - { - "action": "upsert", - "collection": "carrier_details", - "properties": { - "id_reference": "4", - "id_zone": "2", - "id_range": "2", - "shipping_method": "range_weight", - "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": 6, - "id_carrier_detail": "2" - } - }, - { - "action": "upsert", - "collection": "carrier_details", - "properties": { - "id_reference": "4", - "id_zone": "2", - "id_range": "3", - "shipping_method": "range_weight", - "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": 6, - "id_carrier_detail": "3" - } - }, - { - "action": "upsert", - "collection": "carrier_details", - "properties": { - "id_reference": "4", - "id_zone": "2", - "id_range": "4", - "shipping_method": "range_weight", - "delimiter1": 3, - "delimiter2": 10000, - "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" - } + { + "action": "upsert", + "collection": "carrier_details", + "properties": { + "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" } - ] - \ No newline at end of file + }, + { + "action": "upsert", + "collection": "carrier_details", + "properties": { + "id_reference": "2", + "id_zone": "2", + "id_range": "1", + "shipping_method": "range_weight", + "delimiter1": 0, + "delimiter2": 10000, + "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" + } + }, + { + "action": "upsert", + "collection": "carrier_details", + "properties": { + "id_reference": "3", + "id_zone": "1", + "id_range": "2", + "shipping_method": "range_price", + "delimiter1": 0, + "delimiter2": 50, + "country_ids": "FR", + "state_ids": "", + "price": 0, + "id_carrier_detail": "2" + } + }, + { + "action": "upsert", + "collection": "carrier_details", + "properties": { + "id_reference": "3", + "id_zone": "1", + "id_range": "3", + "shipping_method": "range_price", + "delimiter1": 50, + "delimiter2": 100, + "country_ids": "FR", + "state_ids": "", + "price": 0, + "id_carrier_detail": "3" + } + }, + { + "action": "upsert", + "collection": "carrier_details", + "properties": { + "id_reference": "3", + "id_zone": "1", + "id_range": "4", + "shipping_method": "range_price", + "delimiter1": 100, + "delimiter2": 200, + "country_ids": "FR", + "state_ids": "", + "price": 0, + "id_carrier_detail": "4" + } + }, + { + "action": "upsert", + "collection": "carrier_details", + "properties": { + "id_reference": "3", + "id_zone": "2", + "id_range": "2", + "shipping_method": "range_price", + "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": 0, + "id_carrier_detail": "2" + } + }, + { + "action": "upsert", + "collection": "carrier_details", + "properties": { + "id_reference": "3", + "id_zone": "2", + "id_range": "3", + "shipping_method": "range_price", + "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": 0, + "id_carrier_detail": "3" + } + }, + { + "action": "upsert", + "collection": "carrier_details", + "properties": { + "id_reference": "3", + "id_zone": "2", + "id_range": "4", + "shipping_method": "range_price", + "delimiter1": 100, + "delimiter2": 200, + "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" + } + }, + { + "action": "upsert", + "collection": "carrier_details", + "properties": { + "id_reference": "4", + "id_zone": "1", + "id_range": "2", + "shipping_method": "range_weight", + "delimiter1": 0, + "delimiter2": 1, + "country_ids": "FR", + "state_ids": "", + "price": 6, + "id_carrier_detail": "2" + } + }, + { + "action": "upsert", + "collection": "carrier_details", + "properties": { + "id_reference": "4", + "id_zone": "1", + "id_range": "3", + "shipping_method": "range_weight", + "delimiter1": 1, + "delimiter2": 3, + "country_ids": "FR", + "state_ids": "", + "price": 6, + "id_carrier_detail": "3" + } + }, + { + "action": "upsert", + "collection": "carrier_details", + "properties": { + "id_reference": "4", + "id_zone": "1", + "id_range": "4", + "shipping_method": "range_weight", + "delimiter1": 3, + "delimiter2": 10000, + "country_ids": "FR", + "state_ids": "", + "price": 6, + "id_carrier_detail": "4" + } + }, + { + "action": "upsert", + "collection": "carrier_details", + "properties": { + "id_reference": "4", + "id_zone": "2", + "id_range": "2", + "shipping_method": "range_weight", + "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": 6, + "id_carrier_detail": "2" + } + }, + { + "action": "upsert", + "collection": "carrier_details", + "properties": { + "id_reference": "4", + "id_zone": "2", + "id_range": "3", + "shipping_method": "range_weight", + "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": 6, + "id_carrier_detail": "3" + } + }, + { + "action": "upsert", + "collection": "carrier_details", + "properties": { + "id_reference": "4", + "id_zone": "2", + "id_range": "4", + "shipping_method": "range_weight", + "delimiter1": 3, + "delimiter2": 10000, + "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" + } + } +]