def get_product_info(item_code): """get product price / stock info""" if not is_cart_enabled(): return {} qty = 0 cart_quotation = _get_cart_quotation() template_item_code = frappe.db.get_value("Item", item_code, "variant_of") stock_status = get_qty_in_stock(item_code, template_item_code) in_stock = stock_status.in_stock stock_qty = stock_status.stock_qty price = get_price(item_code, template_item_code, cart_quotation.selling_price_list) if price: price["formatted_price"] = fmt_money(price["price_list_rate"], currency=price["currency"]) price["currency"] = not cint(frappe.db.get_default("hide_currency_symbol")) \ and (frappe.db.get_value("Currency", price.currency, "symbol") or price.currency) \ or "" if frappe.session.user != "Guest": item = cart_quotation.get({"item_code": item_code}) if item: qty = item[0].qty return { "price": price, "stock_qty": stock_qty, "in_stock": in_stock, "uom": frappe.db.get_value("Item", item_code, "stock_uom"), "qty": qty, "show_stock_qty": show_quantity_in_website() }
def update_my_account_context(context): if is_cart_enabled(): context["my_account_list"].append({"label": _("Cart"), "url": "cart"}) context["my_account_list"].extend([ { "label": _("Orders"), "url": "orders" }, { "label": _("Invoices"), "url": "invoices" }, { "label": _("Shipments"), "url": "shipments" }, { "label": _("Issues"), "url": "issues" }, { "label": _("Addresses"), "url": "addresses" }, ])
def get_product_info_for_website(item_code): """get product price / stock info for website""" if not is_cart_enabled(): return {} cart_quotation = _get_cart_quotation() cart_settings = get_shopping_cart_settings() price = get_price(item_code, cart_quotation.selling_price_list, cart_settings.default_customer_group, cart_settings.company) stock_status = get_qty_in_stock(item_code, "website_warehouse") product_info = { "price": price, "stock_qty": stock_status.stock_qty, "in_stock": stock_status.in_stock, "qty": 0, "uom": frappe.db.get_value("Item", item_code, "stock_uom"), "show_stock_qty": show_quantity_in_website() } if product_info["price"]: if frappe.session.user != "Guest": item = cart_quotation.get({"item_code": item_code}) if item: product_info["qty"] = item[0].qty return product_info
def get_product_info(item_code): """get product price / stock info""" if not is_cart_enabled(): return {} qty = 0 cart_quotation = _get_cart_quotation() template_item_code = frappe.db.get_value("Item", item_code, "variant_of") stock_status = get_qty_in_stock(item_code, template_item_code) in_stock = stock_status.in_stock stock_qty = stock_status.stock_qty price = get_price(item_code, template_item_code, cart_quotation.selling_price_list) if price: price["formatted_price"] = fmt_money(price["price_list_rate"], currency=price["currency"]) price["currency"] = not cint(frappe.db.get_default("hide_currency_symbol")) \ and (frappe.db.get_value("Currency", price.currency, "symbol") or price.currency) \ or "" if frappe.session.user != "Guest": item = cart_quotation.get({"item_code": item_code}) if item: qty = item[0].qty return { "price": price, "stock_qty": stock_qty, "in_stock": in_stock, "uom": frappe.db.get_value("Item", item_code, "stock_uom"), "qty": qty, "show_stock_qty": show_quantity_in_website() }
def get_product_info_for_website(item_code): """get product price / stock info for website""" if not is_cart_enabled(): return {} cart_quotation = _get_cart_quotation() cart_settings = get_shopping_cart_settings() price = get_price( item_code, cart_quotation.selling_price_list, cart_settings.default_customer_group, cart_settings.company ) stock_status = get_qty_in_stock(item_code, "website_warehouse") product_info = { "price": price, "stock_qty": stock_status.stock_qty, "in_stock": stock_status.in_stock if stock_status.is_stock_item else 1, "qty": 0, "uom": frappe.db.get_value("Item", item_code, "stock_uom"), "show_stock_qty": show_quantity_in_website() if stock_status.is_stock_item else 0 } if product_info["price"]: if frappe.session.user != "Guest": item = cart_quotation.get({"item_code": item_code}) if item: product_info["qty"] = item[0].qty return product_info
def update_website_context(context): cart_enabled = is_cart_enabled() shopping_cart_count = 0 if hasattr(frappe.local, "cookie_manager"): shopping_cart_count = cint( frappe.local.cookie_manager.cookies.get("cart_count", 0)) context.update({ "shopping_cart_enabled": cart_enabled, "shopping_cart_show_count": show_cart_count(), "shopping_cart_count": shopping_cart_count }) # Order for feature: if "order_for" in frappe.session.data: #create a global context variable which is a bool flag for the order_for feature context.update( {"order_for": frappe.session.data.order_for.get('enabled', False)}) customer_name = frappe.session.data.order_for.get("customer_name") if customer_name: customer = frappe.get_doc("Customer", customer_name) primary_contact = frappe.session.data.order_for.get( "customer_primary_contact_name") context.update({ "session_customer": customer, "customer_name": customer_name }) if primary_contact and frappe.db.exists("Contact", primary_contact): contact = frappe.get_doc("Contact", primary_contact) context.update({"session_customer_primary_contact": contact})
def update_website_context(context): cart_enabled = is_cart_enabled() context["shopping_cart_enabled"] = cart_enabled if cart_enabled: post_login = [ {"label": _("Cart"), "url": "cart", "class": "cart-count"}, {"class": "divider"} ] context["post_login"] = post_login + context.get("post_login", [])
def update_my_account_context(context): if is_cart_enabled(): context["my_account_list"].append({"label": _("Cart"), "url": "cart"}) context["my_account_list"].extend([ {"label": _("Orders"), "url": "orders"}, {"label": _("Invoices"), "url": "invoices"}, {"label": _("Shipments"), "url": "shipments"}, # {"label": _("Issues"), "url": "tickets"}, {"label": _("Addresses"), "url": "addresses"}, ])
def get_product_info(item_code): """get product price / stock info""" if not is_cart_enabled(): return {} cart_quotation = _get_cart_quotation() price_list = cart_quotation.selling_price_list warehouse = frappe.db.get_value("Item", item_code, "website_warehouse") if warehouse: in_stock = frappe.db.sql("""select actual_qty from tabBin where item_code=%s and warehouse=%s""", (item_code, warehouse)) if in_stock: in_stock = in_stock[0][0] > 0 and 1 or 0 else: in_stock = -1 price = price_list and frappe.db.sql("""select price_list_rate, currency from `tabItem Price` where item_code=%s and price_list=%s""", (item_code, price_list), as_dict=1) or [] price = price and price[0] or None qty = 0 if price: price["formatted_price"] = fmt_money(price["price_list_rate"], currency=price["currency"]) price["currency"] = not cint(frappe.db.get_default("hide_currency_symbol")) \ and (frappe.db.get_value("Currency", price.currency, "symbol") or price.currency) \ or "" if frappe.session.user != "Guest": item = cart_quotation.get({"item_code": item_code}) if item: qty = item[0].qty return { "price": price, "stock": in_stock, "uom": frappe.db.get_value("Item", item_code, "stock_uom"), "qty": qty }
def update_website_context(context): cart_enabled = is_cart_enabled() context["shopping_cart_enabled"] = cart_enabled
def show_cart_count(): if (is_cart_enabled() and frappe.db.get_value( "User", frappe.session.user, "user_type") == "Website User"): return True return False
def show_cart_count(): if (is_cart_enabled() and frappe.db.get_value("User", frappe.session.user, "user_type") == "Website User"): return True return False
def update_website_context(context): cart_enabled = is_cart_enabled() context["shopping_cart_enabled"] = cart_enabled