def sync_item_with_shopify(item, price_list, warehouse): variant_item_code_list = [] item_data = { "product": { "title": item.get("item_name"), "body_html": item.get("description"), "product_type": item.get("item_group")} } if item.get("has_variants"): variant_list, options, variant_item_code = get_variant_attributes(item, price_list, warehouse) item_data["product"]["variants"] = variant_list item_data["product"]["options"] = options variant_item_code_list.extend(variant_item_code) else: item_data["product"]["variants"] = [get_price_and_stock_details(item, warehouse, price_list)] erp_item = frappe.get_doc("Item", item.get("item_code")) # check if the item really exists on shopify if item.get("shopify_id"): try: get_request("/admin/products/{}.json".format(item.get("shopify_id"))) except requests.exceptions.HTTPError, e: if e.args[0] and e.args[0].startswith("404"): disable_shopify_sync(erp_item) return else: disable_shopify_sync(erp_item) raise
def create_sales_order(order, shopify_settings): shopify_employee_name = None # Deal with 'user_id in order entry' and 'employee accounts' mapping if order.get("user_id") == 26626308: shopify_employee_name = u"Joyce Teoh" elif order.get("user_id") == 26626372: shopify_employee_name = u"Lucus Tan" elif order.get("user_id") == 29492868: shopify_employee_name = u"Vong Guat Theng" elif order.get("user_id") == 29527236: shopify_employee_name = u"Sam Chong" elif order.get("user_id") == 47503940: shopify_employee_name = u"Too Shen Chew" elif order.get("user_id") == 26202436: shopify_employee_name = u"Massimo Hair Lib" shopify_employee_name = shopify_employee_name or order.get("user_id") create_employee(order.get("user_id"), shopify_employee_name) for item in order.get("line_items"): try: get_request("/admin/products/{}.json".format(item.get("product_id")))["product"] except Exception, e: return None
def validate_access(self): try: get_request('/admin/products.json', {"api_key": self.api_key, "password": self.password, "shopify_url": self.shopify_url, "access_token": self.access_token, "app_type": self.app_type}) except requests.exceptions.HTTPError: self.set("enable_shopify", 0) frappe.throw(_("""Invalid Shopify app credentails or access token"""))
def validate_access(self): try: get_request( '/admin/products.json', { "api_key": self.api_key, "password": self.password, "shopify_url": self.shopify_url, "access_token": self.access_token, "app_type": self.app_type }) except requests.exceptions.HTTPError: self.set("enable_shopify", 0) frappe.throw( _("""Invalid Shopify app credentails or access token"""))
def validate_customer_and_product(order): if not frappe.db.get_value("Customer", {"shopify_id": order.get("customer").get("id")}, "name"): create_customer(order.get("customer")) warehouse = frappe.get_doc("Shopify Settings", "Shopify Settings").warehouse for item in order.get("line_items"): if not frappe.db.get_value("Item", {"shopify_id": item.get("product_id")}, "name"): item = get_request("/admin/products/{}.json".format(item.get("product_id")))["product"] make_item(warehouse, item)
def validate_customer_and_product(order): create_customer(get_shopify_customer_by_id(order.get("customer").get("id"))) warehouse = frappe.get_doc("Shopify Settings", "Shopify Settings").warehouse for item in order.get("line_items"): try: item = get_request("/admin/products/{}.json".format(item.get("product_id")))["product"] make_item(warehouse, item) except Exception, e: continue
def sync_item_with_shopify(item, price_list, warehouse): variant_item_code_list = [] item_data = { "product": { "title": item.get("item_name"), "body_html": item.get("description"), "product_type": item.get("item_group") } } if item.get("has_variants"): variant_list, options, variant_item_code = get_variant_attributes( item, price_list, warehouse) item_data["product"]["variants"] = variant_list item_data["product"]["options"] = options variant_item_code_list.extend(variant_item_code) else: item_data["product"]["variants"] = [ get_price_and_stock_details(item, warehouse, price_list) ] erp_item = frappe.get_doc("Item", item.get("item_code")) # check if the item really exists on shopify if item.get("shopify_id"): try: get_request("/admin/products/{}.json".format( item.get("shopify_id"))) except requests.exceptions.HTTPError, e: if e.args[0] and e.args[0].startswith("404"): disable_shopify_sync(erp_item) return else: disable_shopify_sync(erp_item) raise
def validate_customer_and_product(order): if not frappe.db.get_value("Customer", {"shopify_id": order.get("customer").get("id")}, "name"): create_customer(order.get("customer")) warehouse = frappe.get_doc("Shopify Settings", "Shopify Settings").warehouse for item in order.get("line_items"): if not frappe.db.get_value( "Item", {"shopify_id": item.get("product_id")}, "name"): item = get_request("/admin/products/{}.json".format( item.get("product_id")))["product"] make_item(warehouse, item)
def test_product(self): if self.enabled: shopify_settings = frappe.get_doc("Shopify Settings", "Shopify Settings") self.create_item(test_records[0]) sync_erp_items(shopify_settings.price_list, shopify_settings.warehouse) item = frappe.get_doc("Item", "Test Shopify Item") try: synced_item = get_request('/admin/products/{}.json'.format(item.id))['product'] except ShopifyError: raise ShopifyError self.assertEqual(cint(item.id), synced_item["id"]) self.assertEqual(item.sync_with_shopify, 1)
def test_customer(self): if self.enabled: shopify_settings = frappe.get_doc("Shopify Settings", "Shopify Settings") self.create_customer(test_records[1]) sync_erp_customers() customer = frappe.get_doc("Customer", "_Test Shopify Customer") try: synced_customer = get_request('/admin/customers/{}.json'.format(customer.id))['customer'] except ShopifyError: raise ShopifyError self.assertEqual(cint(customer.id), synced_customer["id"]) self.assertEqual(customer.sync_with_shopify, 1)
def test_customer(self): if self.enabled: shopify_settings = frappe.get_doc("Shopify Settings", "Shopify Settings") self.create_customer(test_records[1]) sync_erp_customers() customer = frappe.get_doc("Customer", "_Test Shopify Customer") try: synced_customer = get_request( '/admin/customers/{}.json'.format(customer.id))['customer'] except ShopifyError: raise ShopifyError self.assertEqual(cint(customer.id), synced_customer["id"]) self.assertEqual(customer.sync_with_shopify, 1)
def test_product(self): if self.enabled: shopify_settings = frappe.get_doc("Shopify Settings", "Shopify Settings") self.create_item(test_records[0]) sync_erp_items(shopify_settings.price_list, shopify_settings.warehouse) item = frappe.get_doc("Item", "Test Shopify Item") try: synced_item = get_request('/admin/products/{}.json'.format( item.id))['product'] except ShopifyError: raise ShopifyError self.assertEqual(cint(item.id), synced_item["id"]) self.assertEqual(item.sync_with_shopify, 1)