コード例 #1
0
def update_item_stock(item_code, shopify_settings, bin=None):
	item = frappe.get_doc("Item", item_code)
	if item.sync_qty_with_shopify:
		if not bin:
			bin = frappe.get_doc("Bin", {"warehouse": shopify_settings.warehouse,
			"item_code": item_code})

		if bin:
			if not item.shopify_id and not item.variant_of:
				sync_item_with_shopify(item, shopify_settings.price_list, shopify_settings.warehouse)

			if item.sync_with_shopify and item.shopify_id and shopify_settings.warehouse == bin.warehouse:
				if item.variant_of:
					item_data, resource = get_product_update_dict_and_resource(frappe.get_value("Item",
						item.variant_of, "shopify_id"), item.shopify_variant_id)

				else:
					item_data, resource = get_product_update_dict_and_resource(item.shopify_id, item.shopify_variant_id)

				item_data["product"]["variants"][0].update({
					"inventory_quantity": cint(bin.actual_qty),
					"inventory_management": "shopify"
				})

				put_request(resource, item_data)
コード例 #2
0
def update_item_stock(item_code, shopify_settings, bin=None):
    item = frappe.get_doc("Item", item_code)
    if item.sync_qty_with_shopify:
        if not bin:
            bin = frappe.get_doc("Bin", {
                "warehouse": shopify_settings.warehouse,
                "item_code": item_code
            })

        if bin:
            if not item.shopify_id and not item.variant_of:
                sync_item_with_shopify(item, shopify_settings.price_list,
                                       shopify_settings.warehouse)

            if item.sync_with_shopify and item.shopify_id and shopify_settings.warehouse == bin.warehouse:
                if item.variant_of:
                    item_data, resource = get_product_update_dict_and_resource(
                        frappe.get_value("Item", item.variant_of,
                                         "shopify_id"),
                        item.shopify_variant_id)

                else:
                    item_data, resource = get_product_update_dict_and_resource(
                        item.shopify_id, item.shopify_variant_id)

                item_data["product"]["variants"][0].update({
                    "inventory_quantity":
                    cint(bin.actual_qty),
                    "inventory_management":
                    "shopify"
                })

                put_request(resource, item_data)
コード例 #3
0
				raise
			
	if not item.get("shopify_id"):
		new_item = post_request("/admin/products.json", item_data)
		erp_item.shopify_id = new_item['product'].get("id")

		if not item.get("has_variants"):
			erp_item.shopify_variant_id = new_item['product']["variants"][0].get("id")

		erp_item.save()

		update_variant_item(new_item, variant_item_code_list)

	else:
		item_data["product"]["id"] = item.get("shopify_id")
		put_request("/admin/products/{}.json".format(item.get("shopify_id")), item_data)
				
	sync_item_image(erp_item)

def sync_item_image(item):
	image_info = {
        "image": {}
	}

	if item.image:
		img_details = frappe.db.get_value("File", {"file_url": item.image}, ["file_name", "content_hash"])

		if img_details and img_details[0] and img_details[1]:
			is_private = item.image.startswith("/private/files/")
			with open(get_files_path(img_details[0].strip("/"), is_private=is_private), "rb") as image_file:
			    image_info["image"]["attachment"] = base64.b64encode(image_file.read())
コード例 #4
0
    if not item.get("shopify_id"):
        new_item = post_request("/admin/products.json", item_data)
        erp_item.shopify_id = new_item['product'].get("id")

        if not item.get("has_variants"):
            erp_item.shopify_variant_id = new_item['product']["variants"][
                0].get("id")

        erp_item.save()

        update_variant_item(new_item, variant_item_code_list)

    else:
        item_data["product"]["id"] = item.get("shopify_id")
        put_request("/admin/products/{}.json".format(item.get("shopify_id")),
                    item_data)

    sync_item_image(erp_item)


def sync_item_image(item):
    image_info = {"image": {}}

    if item.image:
        img_details = frappe.db.get_value("File", {"file_url": item.image},
                                          ["file_name", "content_hash"])

        if img_details and img_details[0] and img_details[1]:
            is_private = item.image.startswith("/private/files/")
            with open(
                    get_files_path(img_details[0].strip("/"),