Skip to content

Commit

Permalink
solving conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
elitonzky committed Jan 11, 2024
2 parents 15a63df + 61ebb79 commit 8db558f
Show file tree
Hide file tree
Showing 71 changed files with 2,589 additions and 124 deletions.
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# syntax = docker/dockerfile:1

ARG PYTHON_VERSION="3.8"
ARG PYTHON_VERSION="3.9"
ARG DEBIAN_VERSION="buster"
ARG POETRY_VERSION="1.7.0"

Expand Down
18 changes: 18 additions & 0 deletions marketplace/applications/migrations/0017_alter_app_platform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.4 on 2023-11-23 20:57

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('applications', '0016_app_configured'),
]

operations = [
migrations.AlterField(
model_name='app',
name='platform',
field=models.CharField(choices=[('IA', 'inteligence-artificial'), ('WF', 'weni-flows'), ('RC', 'rocketchat'), ('VT', 'vtex')], max_length=2),
),
]
2 changes: 2 additions & 0 deletions marketplace/applications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ class App(AppTypeBaseModel):
PLATFORM_IA = "IA"
PLATFORM_WENI_FLOWS = "WF"
PLATFORM_RC = "RC"
PLATFORM_VTEX = "VT"

PLATFORM_CHOICES = (
(PLATFORM_IA, "inteligence-artificial"),
(PLATFORM_WENI_FLOWS, "weni-flows"),
(PLATFORM_RC, "rocketchat"),
(PLATFORM_VTEX, "vtex"),
)

config = models.JSONField(default=dict)
Expand Down
17 changes: 11 additions & 6 deletions marketplace/clients/facebook/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def get_url(self):

class FacebookClient(FacebookAuthorization, RequestClient):
# Product Catalog
def create_catalog(self, business_id, name, category=None):
def create_catalog(self, business_id, name, category="commerce"):
url = self.get_url + f"{business_id}/owned_product_catalogs"
data = {"name": name}
if category:
Expand Down Expand Up @@ -54,21 +54,26 @@ def create_product_feed(self, product_catalog_id, name):

return response.json()

def upload_product_feed(self, feed_id, file):
def upload_product_feed(
self, feed_id, file, file_name, file_content_type, update_only=False
):
url = self.get_url + f"{feed_id}/uploads"

headers = self._get_headers()
files = {
"file": (
file.name,
file_name,
file,
file.content_type,
file_content_type,
)
}
response = self.make_request(url, method="POST", headers=headers, files=files)
params = {"update_only": update_only}
response = self.make_request(
url, method="POST", headers=headers, params=params, files=files
)
return response.json()

def create_product_feed_via_url(
def create_product_feed_by_url(
self, product_catalog_id, name, feed_url, file_type, interval, hour
): # TODO: adjust this method
url = self.get_url + f"{product_catalog_id}/product_feeds"
Expand Down
26 changes: 26 additions & 0 deletions marketplace/clients/flows/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ def update_config(self, data, flow_object_uuid):
)
return response

def update_vtex_integration_status(self, project_uuid, user_email, action):
url = f"{self.base_url}/api/v2/internals/orgs/{project_uuid}/update-vtex/"
payload = {"user_email": user_email}
self.make_request(
url=url,
method=action,
headers=self.authentication_instance.headers,
json=payload,
)
return True

def update_catalogs(self, flow_object_uuid, catalogs_data):
data = {"data": catalogs_data}
url = f"{self.base_url}/catalogs/{flow_object_uuid}/update-catalog/"
Expand Down Expand Up @@ -90,3 +101,18 @@ def update_facebook_templates(self, flow_object_uuid, fba_templates):
json=data,
)
return response

def update_vtex_products(self, products, flow_object_uuid, dict_catalog):
data = {
"catalog": dict_catalog,
"channel_uuid": flow_object_uuid,
"products": products,
}
url = f"{self.base_url}/products/update-products/"
response = self.make_request(
url,
method="POST",
headers=self.authentication_instance.headers,
json=data,
)
return response
100 changes: 100 additions & 0 deletions marketplace/clients/vtex/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
from marketplace.clients.base import RequestClient


class VtexAuthorization(RequestClient):
def __init__(self, app_key, app_token):
self.app_key = app_key
self.app_token = app_token

def _get_headers(self):
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"X-VTEX-API-AppKey": self.app_key,
"X-VTEX-API-AppToken": self.app_token,
}
return headers


class VtexCommonClient(RequestClient):
def check_domain(self, domain):
try:
url = f"https://{domain}/api/catalog_system/pub/products/search/"
response = self.make_request(url, method="GET")
return response.status_code == 206
except Exception:
return False


class VtexPublicClient(VtexCommonClient):
def search_product_by_sku_id(self, skuid, domain, sellerid=1):
url = f"https://{domain}/api/catalog_system/pub/products/search?fq=skuId:{skuid}&sellerId={sellerid}"
response = self.make_request(url, method="GET")
return response


class VtexPrivateClient(VtexAuthorization, VtexCommonClient):
def is_valid_credentials(self, domain):
try:
url = (
f"https://{domain}/api/catalog_system/pvt/products/GetProductAndSkuIds"
)
headers = self._get_headers()
response = self.make_request(url, method="GET", headers=headers)
return response.status_code == 200
except Exception:
return False

def list_all_products_sku_ids(self, domain, page_size=1000):
all_skus = []
page = 1

while True:
url = f"https://{domain}/api/catalog_system/pvt/sku/stockkeepingunitids?page={page}&pagesize={page_size}"
headers = self._get_headers()
response = self.make_request(url, method="GET", headers=headers)

sku_ids = response.json()
if not sku_ids:
break

all_skus.extend(sku_ids)
page += 1

return all_skus

def list_active_sellers(self, domain):
url = f"https://{domain}/api/seller-register/pvt/sellers"
headers = self._get_headers()
response = self.make_request(url, method="GET", headers=headers)
sellers_data = response.json()
return [seller["id"] for seller in sellers_data["items"] if seller["isActive"]]

def get_product_details(self, sku_id, domain):
url = (
f"https://{domain}/api/catalog_system/pvt/sku/stockkeepingunitbyid/{sku_id}"
)
headers = self._get_headers()
response = self.make_request(url, method="GET", headers=headers)
return response.json()

def pub_simulate_cart_for_seller(self, sku_id, seller_id, domain):
cart_simulation_url = f"https://{domain}/api/checkout/pub/orderForms/simulation"
payload = {"items": [{"id": sku_id, "quantity": 1, "seller": seller_id}]}

response = self.make_request(cart_simulation_url, method="POST", json=payload)
simulation_data = response.json()

if simulation_data["items"]:
item_data = simulation_data["items"][0]
return {
"is_available": item_data["availability"] == "available",
"price": item_data["price"],
"list_price": item_data["listPrice"],
}
else:
return {
"is_available": False,
"price": 0,
"list_price": 0,
}
3 changes: 3 additions & 0 deletions marketplace/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def __init__(self, *args, **kwargs):
self.type_class = self.context.get("view").type_class

def create(self, validated_data):
if self.type_class and hasattr(self.type_class, "platform"):
validated_data["platform"] = self.type_class.platform

validated_data.pop("modified_by", None)
return super().create(validated_data)

Expand Down
2 changes: 2 additions & 0 deletions marketplace/core/types/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ class AbstractAppType(ABC):
CATEGORY_CLASSIFIER = "CF"
CATEGORY_TICKETER = "TK"
CATEGORY_EXTERNAL = "EXT"
CATEGORY_ECOMMERCE = "ECM"

CATEGORY_CHOICES = (
(CATEGORY_CHANNEL, "channel"),
(CATEGORY_CLASSIFIER, "classifier"),
(CATEGORY_TICKETER, "ticketer"),
(CATEGORY_EXTERNAL, "external"),
(CATEGORY_ECOMMERCE, "ecommerce"),
)

@abstractproperty
Expand Down
Loading

0 comments on commit 8db558f

Please sign in to comment.