mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-08 15:42:52 +00:00
[webshop] [cart] show prices based on geoip of guest user
This commit is contained in:
@@ -15,6 +15,9 @@ class DocType(DocListController):
|
|||||||
self.validate_tax_masters()
|
self.validate_tax_masters()
|
||||||
self.validate_exchange_rates_exist()
|
self.validate_exchange_rates_exist()
|
||||||
|
|
||||||
|
def on_update(self):
|
||||||
|
webnotes.conn.set_default("shopping_cart_enabled", self.doc.fields.get("enabled") or 0)
|
||||||
|
|
||||||
def validate_overlapping_territories(self, parentfield, fieldname):
|
def validate_overlapping_territories(self, parentfield, fieldname):
|
||||||
# for displaying message
|
# for displaying message
|
||||||
doctype = self.meta.get_field(parentfield).options
|
doctype = self.meta.get_field(parentfield).options
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ def update_cart(item_code, qty, with_doclist=0):
|
|||||||
|
|
||||||
apply_cart_settings(quotation=quotation)
|
apply_cart_settings(quotation=quotation)
|
||||||
|
|
||||||
|
quotation.ignore_permissions = True
|
||||||
|
quotation.save()
|
||||||
|
|
||||||
if with_doclist:
|
if with_doclist:
|
||||||
return get_cart_quotation(quotation.doclist)
|
return get_cart_quotation(quotation.doclist)
|
||||||
else:
|
else:
|
||||||
@@ -67,11 +70,11 @@ def update_cart_address(address_fieldname, address_name):
|
|||||||
quotation.doc.address_display = address_display
|
quotation.doc.address_display = address_display
|
||||||
|
|
||||||
|
|
||||||
|
apply_cart_settings(quotation=quotation)
|
||||||
|
|
||||||
quotation.ignore_permissions = True
|
quotation.ignore_permissions = True
|
||||||
quotation.save()
|
quotation.save()
|
||||||
|
|
||||||
apply_cart_settings(quotation=quotation)
|
|
||||||
|
|
||||||
return get_cart_quotation(quotation.doclist)
|
return get_cart_quotation(quotation.doclist)
|
||||||
|
|
||||||
@webnotes.whitelist()
|
@webnotes.whitelist()
|
||||||
@@ -136,6 +139,8 @@ def get_lead_or_customer():
|
|||||||
"territory": guess_territory(),
|
"territory": guess_territory(),
|
||||||
"status": "Open" # TODO: set something better???
|
"status": "Open" # TODO: set something better???
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if webnotes.session.user != "Guest":
|
||||||
lead_bean.ignore_permissions = True
|
lead_bean.ignore_permissions = True
|
||||||
lead_bean.insert()
|
lead_bean.insert()
|
||||||
|
|
||||||
@@ -211,9 +216,6 @@ def apply_cart_settings(party=None, quotation=None):
|
|||||||
|
|
||||||
_apply_shipping_rule(party, quotation, cart_settings)
|
_apply_shipping_rule(party, quotation, cart_settings)
|
||||||
|
|
||||||
quotation.ignore_permissions = True
|
|
||||||
quotation.save()
|
|
||||||
|
|
||||||
def set_price_list_and_rate(quotation, cart_settings, billing_territory):
|
def set_price_list_and_rate(quotation, cart_settings, billing_territory):
|
||||||
"""set price list based on billing territory"""
|
"""set price list based on billing territory"""
|
||||||
quotation.doc.price_list_name = cart_settings.get_price_list(billing_territory)
|
quotation.doc.price_list_name = cart_settings.get_price_list(billing_territory)
|
||||||
@@ -227,6 +229,9 @@ def set_price_list_and_rate(quotation, cart_settings, billing_territory):
|
|||||||
# refetch values
|
# refetch values
|
||||||
quotation.run_method("set_price_list_and_item_details")
|
quotation.run_method("set_price_list_and_item_details")
|
||||||
|
|
||||||
|
# set it in cookies for using in product page
|
||||||
|
webnotes.cookies[b"price_list_name"] = quotation.doc.price_list_name
|
||||||
|
|
||||||
def set_taxes(quotation, cart_settings, billing_territory):
|
def set_taxes(quotation, cart_settings, billing_territory):
|
||||||
"""set taxes based on billing territory"""
|
"""set taxes based on billing territory"""
|
||||||
quotation.doc.charge = cart_settings.get_tax_master(billing_territory)
|
quotation.doc.charge = cart_settings.get_tax_master(billing_territory)
|
||||||
@@ -247,6 +252,7 @@ def apply_shipping_rule(shipping_rule):
|
|||||||
|
|
||||||
apply_cart_settings(quotation=quotation)
|
apply_cart_settings(quotation=quotation)
|
||||||
|
|
||||||
|
quotation.ignore_permissions = True
|
||||||
quotation.save()
|
quotation.save()
|
||||||
|
|
||||||
return get_cart_quotation(quotation.doclist)
|
return get_cart_quotation(quotation.doclist)
|
||||||
|
|||||||
@@ -6,11 +6,18 @@ from __future__ import unicode_literals
|
|||||||
import webnotes
|
import webnotes
|
||||||
from webnotes.utils import cstr, cint, fmt_money
|
from webnotes.utils import cstr, cint, fmt_money
|
||||||
from webnotes.webutils import build_html, delete_page_cache
|
from webnotes.webutils import build_html, delete_page_cache
|
||||||
|
from website.helpers.cart import _get_cart_quotation
|
||||||
|
|
||||||
@webnotes.whitelist(allow_guest=True)
|
@webnotes.whitelist(allow_guest=True)
|
||||||
def get_product_info(item_code):
|
def get_product_info(item_code):
|
||||||
"""get product price / stock info"""
|
"""get product price / stock info"""
|
||||||
price_list = webnotes.conn.get_value("Price List", {"use_for_website": 1})
|
if not webnotes.conn.get_default("shopping_cart_enabled"):
|
||||||
|
return {}
|
||||||
|
|
||||||
|
cart_quotation = _get_cart_quotation()
|
||||||
|
|
||||||
|
price_list = webnotes.cookies.get("price_list_name").value
|
||||||
|
|
||||||
warehouse = webnotes.conn.get_value("Item", item_code, "website_warehouse")
|
warehouse = webnotes.conn.get_value("Item", item_code, "website_warehouse")
|
||||||
if warehouse:
|
if warehouse:
|
||||||
in_stock = webnotes.conn.sql("""select actual_qty from tabBin where
|
in_stock = webnotes.conn.sql("""select actual_qty from tabBin where
|
||||||
@@ -35,8 +42,7 @@ def get_product_info(item_code):
|
|||||||
or ""
|
or ""
|
||||||
|
|
||||||
if webnotes.session.user != "Guest":
|
if webnotes.session.user != "Guest":
|
||||||
from website.helpers.cart import _get_cart_quotation
|
item = cart_quotation.doclist.get({"item_code": item_code})
|
||||||
item = _get_cart_quotation().doclist.get({"item_code": item_code})
|
|
||||||
if item:
|
if item:
|
||||||
qty = item[0].qty
|
qty = item[0].qty
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,8 @@
|
|||||||
<button class="btn btn-primary">
|
<button class="btn btn-primary">
|
||||||
<i class="icon-shopping-cart"></i> Add to Cart</button>
|
<i class="icon-shopping-cart"></i> Add to Cart</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="item-update-cart" class="input-group col-lg-4" style="display: none;">
|
<div id="item-update-cart" class="input-group col-lg-4" style="display: none;
|
||||||
|
padding-left: 0px; padding-right: 0px;">
|
||||||
<input type="text">
|
<input type="text">
|
||||||
<div class="input-group-btn">
|
<div class="input-group-btn">
|
||||||
<button class="btn btn-primary">
|
<button class="btn btn-primary">
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ $.extend(wn.cart, {
|
|||||||
|
|
||||||
var shipping_rule_added = false;
|
var shipping_rule_added = false;
|
||||||
var taxes_exist = false;
|
var taxes_exist = false;
|
||||||
var shipping_rule_labels = $.map(out.shipping_rules, function(rule) { return rule[1]; });
|
var shipping_rule_labels = $.map(out.shipping_rules || [], function(rule) { return rule[1]; });
|
||||||
$.each(doclist, function(i, doc) {
|
$.each(doclist, function(i, doc) {
|
||||||
if(doc.doctype === "Quotation Item") {
|
if(doc.doctype === "Quotation Item") {
|
||||||
wn.cart.render_item_row($cart_items, doc);
|
wn.cart.render_item_row($cart_items, doc);
|
||||||
|
|||||||
Reference in New Issue
Block a user