Skip to content

Commit

Permalink
Merge pull request frappe#188 from ankush/scannable_identifier
Browse files Browse the repository at this point in the history
feat: Scannable identifier
  • Loading branch information
ankush authored May 31, 2022
2 parents 6b2199f + bc74a90 commit d970c88
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 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
8 changes: 7 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 All @@ -268,6 +271,9 @@ def _build_unicommerce_item(item_code: ItemCode) -> JsonDict:
item_json["enabled"] = not bool(item.get("disabled"))

for barcode in item.barcodes:
if not item_json.get("scanIdentifier"):
# Set first barcode as scan identifier
item_json["scanIdentifier"] = barcode.barcode
if barcode.barcode_type == "EAN":
item_json["ean"] = barcode.barcode
elif barcode.barcode_type == "UPC-A":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"categoryCode": "Products",
"name": "TITANIUM WATCH",
"description": "This is a watch.",
"scanIdentifier": "TITANIUM_WATCH",
"scanIdentifier": "73513537",
"length": 100,
"width": 100,
"height": 50,
Expand Down

0 comments on commit d970c88

Please sign in to comment.