[webshop] [cart] show prices based on geoip of guest user
diff --git a/website/doctype/shopping_cart_settings/shopping_cart_settings.py b/website/doctype/shopping_cart_settings/shopping_cart_settings.py
index 121422f..7fe14c3 100644
--- a/website/doctype/shopping_cart_settings/shopping_cart_settings.py
+++ b/website/doctype/shopping_cart_settings/shopping_cart_settings.py
@@ -15,6 +15,9 @@
self.validate_tax_masters()
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):
# for displaying message
doctype = self.meta.get_field(parentfield).options
diff --git a/website/helpers/cart.py b/website/helpers/cart.py
index 099fb68..d4ab64d 100644
--- a/website/helpers/cart.py
+++ b/website/helpers/cart.py
@@ -42,6 +42,9 @@
quotation_items[0].qty = qty
apply_cart_settings(quotation=quotation)
+
+ quotation.ignore_permissions = True
+ quotation.save()
if with_doclist:
return get_cart_quotation(quotation.doclist)
@@ -67,10 +70,10 @@
quotation.doc.address_display = address_display
+ apply_cart_settings(quotation=quotation)
+
quotation.ignore_permissions = True
quotation.save()
-
- apply_cart_settings(quotation=quotation)
return get_cart_quotation(quotation.doclist)
@@ -136,9 +139,11 @@
"territory": guess_territory(),
"status": "Open" # TODO: set something better???
})
- lead_bean.ignore_permissions = True
- lead_bean.insert()
+ if webnotes.session.user != "Guest":
+ lead_bean.ignore_permissions = True
+ lead_bean.insert()
+
return lead_bean.doc
def guess_territory():
@@ -202,7 +207,7 @@
billing_territory = get_address_territory(quotation.doc.customer_address) or \
party.territory
-
+
set_price_list_and_rate(quotation, cart_settings, billing_territory)
quotation.run_method("calculate_taxes_and_totals")
@@ -211,9 +216,6 @@
_apply_shipping_rule(party, quotation, cart_settings)
- quotation.ignore_permissions = True
- quotation.save()
-
def set_price_list_and_rate(quotation, cart_settings, billing_territory):
"""set price list based on billing territory"""
quotation.doc.price_list_name = cart_settings.get_price_list(billing_territory)
@@ -227,6 +229,9 @@
# refetch values
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):
"""set taxes based on billing territory"""
quotation.doc.charge = cart_settings.get_tax_master(billing_territory)
@@ -247,6 +252,7 @@
apply_cart_settings(quotation=quotation)
+ quotation.ignore_permissions = True
quotation.save()
return get_cart_quotation(quotation.doclist)
diff --git a/website/helpers/product.py b/website/helpers/product.py
index e513c2d..168c14c 100644
--- a/website/helpers/product.py
+++ b/website/helpers/product.py
@@ -6,11 +6,18 @@
import webnotes
from webnotes.utils import cstr, cint, fmt_money
from webnotes.webutils import build_html, delete_page_cache
+from website.helpers.cart import _get_cart_quotation
@webnotes.whitelist(allow_guest=True)
def get_product_info(item_code):
"""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")
if warehouse:
in_stock = webnotes.conn.sql("""select actual_qty from tabBin where
@@ -35,8 +42,7 @@
or ""
if webnotes.session.user != "Guest":
- from website.helpers.cart import _get_cart_quotation
- item = _get_cart_quotation().doclist.get({"item_code": item_code})
+ item = cart_quotation.doclist.get({"item_code": item_code})
if item:
qty = item[0].qty
diff --git a/website/templates/html/product_page.html b/website/templates/html/product_page.html
index 255d1e7..b3e8be2 100644
--- a/website/templates/html/product_page.html
+++ b/website/templates/html/product_page.html
@@ -43,7 +43,8 @@
<button class="btn btn-primary">
<i class="icon-shopping-cart"></i> Add to Cart</button>
</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">
<div class="input-group-btn">
<button class="btn btn-primary">
diff --git a/website/templates/js/cart.js b/website/templates/js/cart.js
index f1002fc..27f604f 100644
--- a/website/templates/js/cart.js
+++ b/website/templates/js/cart.js
@@ -96,7 +96,7 @@
var shipping_rule_added = 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) {
if(doc.doctype === "Quotation Item") {
wn.cart.render_item_row($cart_items, doc);