示例#1
0
def get_context(context):

	path_parts = context.get("pathname", "").split('/')
	print(path_parts)

	login.apply_context(context)

	return context
示例#2
0
def get_context(context):
    """This is a controller extension for erpnext.templates.pages.cart"""

    context["no_cache"] = 1

    settings = frappe.db.get("Awc Settings")
    awc_session = get_awc_session()

    context["countries"] = [
        x for x in frappe.get_list(
            "Country", fields=["country_name", "name"], ignore_permissions=1)
    ]

    default_country = frappe.get_value("System Settings", "System Settings",
                                       "country")
    default_country_doc = next(
        (x for x in context["countries"] if x.name == default_country), None)

    if frappe.session.user != "Guest":
        context["addresses"] = frappe.get_all("Address",
                                              filters={
                                                  "customer":
                                                  get_current_customer().name,
                                                  "disabled":
                                                  False
                                              },
                                              fields="*")

    country_idx = context["countries"].index(default_country_doc)
    context["countries"].pop(country_idx)
    context["countries"] = [default_country_doc] + context["countries"]

    context["shipping_rate_api"] = frappe.get_hooks("shipping_rate_api")[0]
    context["selected_customer"] = awc_session.get("selected_customer")

    # remove? shipping is essential here anyways
    context.shipping_enabled = 1 if settings.awc_shipping_enabled else 0

    # flag to display login form
    context.is_logged = awc.is_logged_in()
    login.apply_context(context)

    if context.is_logged:
        # load gateway provider into context
        gateway_provider = frappe.get_hooks('awc_gateway_form_provider')
        if gateway_provider and len(gateway_provider) > 0:
            context['gateway_provider'] = frappe.call(
                gateway_provider[0],
                context=dict(use_address_same_as=1,
                             address_same_as_label="Same as Shipping Address",
                             address_same_as_source="#awc-shipping-form"))

    awc.reset_shipping()

    return context
示例#3
0
def get_context(context):
	"""This is a controller extension for erpnext.templates.pages.cart"""

	context["no_cache"] = 1

	settings = frappe.db.get("Awc Settings")
	awc_session = get_awc_session()
	customer = get_current_customer()

	context["countries"] = [ x for x in frappe.get_list("Country", fields=["country_name", "name"], ignore_permissions=1) ]

	default_country = frappe.get_value("System Settings", "System Settings", "country")
	default_country_doc = next((x for x in context["countries"] if x.name == default_country), None)

	if frappe.session.user != "Guest":
		address_links = frappe.get_all("Dynamic Link", filters={"link_name" : customer.name}, fields=["parent"])
		addresses = []
		for address in address_links:
			addresses.extend(frappe.get_all("Address", filters={"name" : address.parent, "disabled" : False}, fields="*"))
		context['addresses'] = addresses

		customer_info = frappe.db.get_values("Customer", customer.name, ["has_shipping_account", "fedex_account_number"])[0]
		context["customer_info"] = {
			"has_shipping_acc": customer_info[0],
			"fedex_acc_number": customer_info[1]
		}

	country_idx = context["countries"].index(default_country_doc)
	context["countries"].pop(country_idx)
	context["countries"] = [default_country_doc] + context["countries"]

	context["shipping_rate_api"] = frappe.get_hooks("shipping_rate_api")[0]
	context["selected_customer"] = awc_session.get("selected_customer")

	# ensures clearing address and method selection when visiting checkout page as
	# shipping address widget won't pre-select them.
	awc.reset_shipping(None, awc_session=awc_session, customer=customer)

	# remove? shipping is essential here anyways
	context.shipping_enabled = 1 if settings.awc_shipping_enabled else 0

	related_items = []
	skus_in_cart = []
	# build upsell sku list using or building cache if necessary
	for item in awc_session.get("cart", {}).get("items", []):
		# build cart sku list to dedup later
		skus_in_cart += [item.get("sku")]

		# fetches related items to this sku
		item_related_items = awc.get_related_products_by_sku(
			item.get("sku"), awc_session=awc_session, customer=customer)

		# quick list deduping
		related_items = related_items + list(set(item_related_items) - set(related_items))

	# builds upsell item objects using cache if necessary
	upsell = []
	for sku in related_items:
		if sku not in skus_in_cart:
			# fetches product data to build upsell widget
			product_response = awc.get_product_by_sku(sku, awc_session=awc_session)
			if product_response.get("success"):
				upsell += [product_response.get("data")]

	# upsell widget data is made available to the context here
	context["upsell"] = dict(related_products=upsell)

	# flag to display login form
	context.is_logged = awc.is_logged_in()
	login.apply_context(context)

	if frappe.response.get("awc_alert"):
		context["awc_alert"] = frappe.response.get("awc_alert")


	if context.is_logged:
		# load gateway provider into context
		gateway_provider = frappe.get_hooks('awc_gateway_form_provider')
		if gateway_provider and len(gateway_provider) > 0:
			context['gateway_provider'] = frappe.call(gateway_provider[0], context=dict(
				use_address_same_as=1,
				address_same_as_label="Same as Shipping Address",
				address_same_as_source="#awc-shipping-form"
			))

	return context