From 60727ca7022663d51ba25d164989b53513376ca3 Mon Sep 17 00:00:00 2001 From: lucaslinhares Date: Thu, 18 Jan 2024 18:07:28 -0300 Subject: [PATCH] add flag to configured vtex app --- .../types/channels/whatsapp_cloud/catalogs/views/views.py | 6 ++++++ marketplace/services/facebook/service.py | 5 +++++ marketplace/services/vtex/generic_service.py | 1 + marketplace/wpp_products/tasks.py | 1 + 4 files changed, 13 insertions(+) diff --git a/marketplace/core/types/channels/whatsapp_cloud/catalogs/views/views.py b/marketplace/core/types/channels/whatsapp_cloud/catalogs/views/views.py index 74ccc0ae..ea037dd2 100644 --- a/marketplace/core/types/channels/whatsapp_cloud/catalogs/views/views.py +++ b/marketplace/core/types/channels/whatsapp_cloud/catalogs/views/views.py @@ -107,6 +107,8 @@ def create(self, request, app_uuid, *args, **kwargs): status=status.HTTP_400_BAD_REQUEST, ) + # self._update_connected_catalog_flag(app) + credentials = { "app_key": vtex_app.config.get("api_credentials", {}).get("app_key"), "app_token": vtex_app.config.get("api_credentials", {}).get("app_token"), @@ -178,6 +180,10 @@ def disable_catalog(self, request, *args, **kwargs): ) return Response(status=status.HTTP_200_OK) + def _update_connected_catalog_flag(self, app) -> None: + app.config["connected_catalog"] = True + app.save() + class CommerceSettingsViewSet(BaseViewSet): serializer_class = ToggleVisibilitySerializer diff --git a/marketplace/services/facebook/service.py b/marketplace/services/facebook/service.py index 8ca22d27..93154b59 100644 --- a/marketplace/services/facebook/service.py +++ b/marketplace/services/facebook/service.py @@ -22,6 +22,7 @@ def create_vtex_catalog(self, validated_data, app, vtex_app, user): "created_by": user, } catalog = self._create_catalog_object(data) + self._update_connected_catalog_flag(vtex_app) return catalog, response.get("id") return None, None @@ -109,3 +110,7 @@ def _create_catalog_object(self, data): name=data.get("name"), created_by=data.get("created_by"), ) + + def _update_connected_catalog_flag(self, app) -> None: + app.config["connected_catalog"] = True + app.save() diff --git a/marketplace/services/vtex/generic_service.py b/marketplace/services/vtex/generic_service.py index 641454e1..b0a3b5da 100644 --- a/marketplace/services/vtex/generic_service.py +++ b/marketplace/services/vtex/generic_service.py @@ -79,6 +79,7 @@ def configure(self, app, credentials: APICredentials, wpp_cloud_uuid) -> App: app.config["wpp_cloud_uuid"] = wpp_cloud_uuid app.config["initial_sync_completed"] = False app.config["title"] = credentials.domain + app.config["connected_catalog"] = False app.config["rules"] = [ "exclude_alcoholic_drinks", "calculate_by_weight", diff --git a/marketplace/wpp_products/tasks.py b/marketplace/wpp_products/tasks.py index e29cd63a..5fa83910 100644 --- a/marketplace/wpp_products/tasks.py +++ b/marketplace/wpp_products/tasks.py @@ -140,6 +140,7 @@ def task_insert_vtex_products(**kwargs): app_token=credentials.get("app_token"), domain=credentials.get("domain"), ) + products = vtex_service.first_product_insert(api_credentials, catalog) dict_catalog = { "name": catalog.name,