Skip to content

Commit

Permalink
fix: use separate endpoint if item exists
Browse files Browse the repository at this point in the history
  • Loading branch information
ankush committed May 31, 2022
1 parent 6b2199f commit 29944f3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 7 additions & 4 deletions ecommerce_integrations/unicommerce/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,17 @@ def get_unicommerce_item(self, sku: str) -> Optional[JsonDict]:
if status:
return item

def create_update_item(self, item_dict: JsonDict) -> Tuple[JsonDict, bool]:
def create_update_item(self, item_dict: JsonDict, update=False) -> Tuple[JsonDict, bool]:
"""Create/update item on unicommerce.
ref: https://documentation.unicommerce.com/docs/createoredit-itemtype.html
"""
return self.request(
endpoint="/services/rest/v1/catalog/itemType/createOrEdit", body={"itemType": item_dict}
)

endpoint = "/services/rest/v1/catalog/itemType/createOrEdit"
if update:
# Edit has separate endpoint even though docs suggest otherwise
endpoint = "/services/rest/v1/catalog/itemType/edit"
return self.request(endpoint=endpoint, body={"itemType": item_dict})

def get_sales_order(self, order_code: str) -> Optional[JsonDict]:
"""Get details for a sales order.
Expand Down
5 changes: 4 additions & 1 deletion ecommerce_integrations/unicommerce/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ def upload_items_to_unicommerce(

for item_code in item_codes:
item_data = _build_unicommerce_item(item_code)
_, status = client.create_update_item(item_data)
sku = item_data.get("skuCode")

item_exists = bool(client.get_unicommerce_item(sku))
_, status = client.create_update_item(item_data, update=item_exists)

if status:
_handle_ecommerce_item(item_code)
Expand Down

0 comments on commit 29944f3

Please sign in to comment.