chore: Removed Shopping Cart Module

- Moved all files and web templates from Shopping Cart to E-commerce module
- Made Shopping Cart module obsolete
- Moved select E-commerce related files from Portal to E-commerce module
- Minor cleanups
- Fixed Shopping Cart and Product Configurator tests
This commit is contained in:
marination
2021-02-25 13:56:38 +05:30
parent 37a246e738
commit 22f41a17b7
45 changed files with 182 additions and 141 deletions

View File

@@ -1,606 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
import frappe
import frappe.defaults
from frappe import _, throw
from frappe.contacts.doctype.address.address import get_address_display
from frappe.contacts.doctype.contact.contact import get_contact_name
from frappe.utils import cint, cstr, flt, get_fullname
from frappe.utils.nestedset import get_root_of
from erpnext.e_commerce.doctype.e_commerce_settings.e_commerce_settings import get_shopping_cart_settings
from erpnext.accounts.utils import get_account_name
from erpnext.utilities.product import get_qty_in_stock
class WebsitePriceListMissingError(frappe.ValidationError):
pass
def set_cart_count(quotation=None):
if cint(frappe.db.get_singles_value("E Commerce Settings", "enabled")):
if not quotation:
quotation = _get_cart_quotation()
cart_count = cstr(len(quotation.get("items")))
if hasattr(frappe.local, "cookie_manager"):
frappe.local.cookie_manager.set_cookie("cart_count", cart_count)
@frappe.whitelist()
def get_cart_quotation(doc=None):
party = get_party()
if not doc:
quotation = _get_cart_quotation(party)
doc = quotation
set_cart_count(quotation)
addresses = get_address_docs(party=party)
if not doc.customer_address and addresses:
update_cart_address("billing", addresses[0].name)
return {
"doc": decorate_quotation_doc(doc),
"shipping_addresses": get_shipping_addresses(party),
"billing_addresses": get_billing_addresses(party),
"shipping_rules": get_applicable_shipping_rules(party),
"cart_settings": frappe.get_cached_doc("E Commerce Settings")
}
@frappe.whitelist()
def get_shipping_addresses(party=None):
if not party:
party = get_party()
addresses = get_address_docs(party=party)
return [{"name": address.name, "title": address.address_title, "display": address.display}
for address in addresses if address.address_type == "Shipping"
]
@frappe.whitelist()
def get_billing_addresses(party=None):
if not party:
party = get_party()
addresses = get_address_docs(party=party)
return [{"name": address.name, "title": address.address_title, "display": address.display}
for address in addresses if address.address_type == "Billing"
]
@frappe.whitelist()
def place_order():
quotation = _get_cart_quotation()
cart_settings = frappe.db.get_value("E Commerce Settings", None,
["company", "allow_items_not_in_stock"], as_dict=1)
quotation.company = cart_settings.company
quotation.flags.ignore_permissions = True
quotation.submit()
if quotation.quotation_to == 'Lead' and quotation.party_name:
# company used to create customer accounts
frappe.defaults.set_user_default("company", quotation.company)
if not (quotation.shipping_address_name or quotation.customer_address):
frappe.throw(_("Set Shipping Address or Billing Address"))
from erpnext.selling.doctype.quotation.quotation import _make_sales_order
sales_order = frappe.get_doc(_make_sales_order(quotation.name, ignore_permissions=True))
sales_order.payment_schedule = []
if not cint(cart_settings.allow_items_not_in_stock):
for item in sales_order.get("items"):
item.reserved_warehouse, is_stock_item = frappe.db.get_value("Item",
item.item_code, ["website_warehouse", "is_stock_item"])
if is_stock_item:
item_stock = get_qty_in_stock(item.item_code, "website_warehouse")
if not cint(item_stock.in_stock):
throw(_("{1} Not in Stock").format(item.item_code))
if item.qty > item_stock.stock_qty[0][0]:
throw(_("Only {0} in Stock for item {1}").format(item_stock.stock_qty[0][0], item.item_code))
sales_order.flags.ignore_permissions = True
sales_order.insert()
sales_order.submit()
if hasattr(frappe.local, "cookie_manager"):
frappe.local.cookie_manager.delete_cookie("cart_count")
return sales_order.name
@frappe.whitelist()
def request_for_quotation():
quotation = _get_cart_quotation()
quotation.flags.ignore_permissions = True
quotation.submit()
return quotation.name
@frappe.whitelist()
def update_cart(item_code, qty, additional_notes=None, with_items=False):
quotation = _get_cart_quotation()
empty_card = False
qty = flt(qty)
if qty == 0:
quotation_items = quotation.get("items", {"item_code": ["!=", item_code]})
if quotation_items:
quotation.set("items", quotation_items)
else:
empty_card = True
else:
quotation_items = quotation.get("items", {"item_code": item_code})
if not quotation_items:
quotation.append("items", {
"doctype": "Quotation Item",
"item_code": item_code,
"qty": qty,
"additional_notes": additional_notes
})
else:
quotation_items[0].qty = qty
quotation_items[0].additional_notes = additional_notes
apply_cart_settings(quotation=quotation)
quotation.flags.ignore_permissions = True
quotation.payment_schedule = []
if not empty_card:
quotation.save()
else:
quotation.delete()
quotation = None
set_cart_count(quotation)
context = get_cart_quotation(quotation)
if cint(with_items):
return {
"items": frappe.render_template("templates/includes/cart/cart_items.html",
context),
"taxes": frappe.render_template("templates/includes/order/order_taxes.html",
context),
}
else:
return {
'name': quotation.name,
'shopping_cart_menu': get_shopping_cart_menu(context)
}
@frappe.whitelist()
def get_shopping_cart_menu(context=None):
if not context:
context = get_cart_quotation()
return frappe.render_template('templates/includes/cart/cart_dropdown.html', context)
@frappe.whitelist()
def add_new_address(doc):
doc = frappe.parse_json(doc)
doc.update({
'doctype': 'Address'
})
address = frappe.get_doc(doc)
address.save(ignore_permissions=True)
return address
@frappe.whitelist(allow_guest=True)
def create_lead_for_item_inquiry(lead, subject, message):
lead = frappe.parse_json(lead)
lead_doc = frappe.new_doc('Lead')
lead_doc.update(lead)
lead_doc.set('lead_owner', '')
if not frappe.db.exists('Lead Source', 'Product Inquiry'):
frappe.get_doc({
'doctype': 'Lead Source',
'source_name' : 'Product Inquiry'
}).insert(ignore_permissions=True)
lead_doc.set('source', 'Product Inquiry')
try:
lead_doc.save(ignore_permissions=True)
except frappe.exceptions.DuplicateEntryError:
frappe.clear_messages()
lead_doc = frappe.get_doc('Lead', {'email_id': lead['email_id']})
lead_doc.add_comment('Comment', text='''
<div>
<h5>{subject}</h5>
<p>{message}</p>
</div>
'''.format(subject=subject, message=message))
return lead_doc
@frappe.whitelist()
def get_terms_and_conditions(terms_name):
return frappe.db.get_value('Terms and Conditions', terms_name, 'terms')
@frappe.whitelist()
def update_cart_address(address_type, address_name):
quotation = _get_cart_quotation()
address_doc = frappe.get_doc("Address", address_name).as_dict()
address_display = get_address_display(address_doc)
if address_type.lower() == "billing":
quotation.customer_address = address_name
quotation.address_display = address_display
quotation.shipping_address_name = quotation.shipping_address_name or address_name
address_doc = next((doc for doc in get_billing_addresses() if doc["name"] == address_name), None)
elif address_type.lower() == "shipping":
quotation.shipping_address_name = address_name
quotation.shipping_address = address_display
quotation.customer_address = quotation.customer_address or address_name
address_doc = next((doc for doc in get_shipping_addresses() if doc["name"] == address_name), None)
apply_cart_settings(quotation=quotation)
quotation.flags.ignore_permissions = True
quotation.save()
context = get_cart_quotation(quotation)
context['address'] = address_doc
return {
"taxes": frappe.render_template("templates/includes/order/order_taxes.html",
context),
"address": frappe.render_template("templates/includes/cart/address_card.html",
context)
}
def guess_territory():
territory = None
geoip_country = frappe.session.get("session_country")
if geoip_country:
territory = frappe.db.get_value("Territory", geoip_country)
return territory or \
frappe.db.get_value("E Commerce Settings", None, "territory") or \
get_root_of("Territory")
def decorate_quotation_doc(doc):
for d in doc.get("items", []):
d.update(frappe.db.get_value("Website Item", {"item_code": d.item_code},
["thumbnail", "website_image", "description", "route"], as_dict=True))
return doc
def _get_cart_quotation(party=None):
'''Return the open Quotation of type "Shopping Cart" or make a new one'''
if not party:
party = get_party()
quotation = frappe.get_all("Quotation", fields=["name"], filters=
{"party_name": party.name, "order_type": "Shopping Cart", "docstatus": 0},
order_by="modified desc", limit_page_length=1)
if quotation:
qdoc = frappe.get_doc("Quotation", quotation[0].name)
else:
company = frappe.db.get_value("E Commerce Settings", None, ["company"])
qdoc = frappe.get_doc({
"doctype": "Quotation",
"naming_series": get_shopping_cart_settings().quotation_series or "QTN-CART-",
"quotation_to": party.doctype,
"company": company,
"order_type": "Shopping Cart",
"status": "Draft",
"docstatus": 0,
"__islocal": 1,
"party_name": party.name
})
qdoc.contact_person = frappe.db.get_value("Contact", {"email_id": frappe.session.user})
qdoc.contact_email = frappe.session.user
qdoc.flags.ignore_permissions = True
qdoc.run_method("set_missing_values")
apply_cart_settings(party, qdoc)
return qdoc
def update_party(fullname, company_name=None, mobile_no=None, phone=None):
party = get_party()
party.customer_name = company_name or fullname
party.customer_type = "Company" if company_name else "Individual"
contact_name = frappe.db.get_value("Contact", {"email_id": frappe.session.user})
contact = frappe.get_doc("Contact", contact_name)
contact.first_name = fullname
contact.last_name = None
contact.customer_name = party.customer_name
contact.mobile_no = mobile_no
contact.phone = phone
contact.flags.ignore_permissions = True
contact.save()
party_doc = frappe.get_doc(party.as_dict())
party_doc.flags.ignore_permissions = True
party_doc.save()
qdoc = _get_cart_quotation(party)
if not qdoc.get("__islocal"):
qdoc.customer_name = company_name or fullname
qdoc.run_method("set_missing_lead_customer_details")
qdoc.flags.ignore_permissions = True
qdoc.save()
def apply_cart_settings(party=None, quotation=None):
if not party:
party = get_party()
if not quotation:
quotation = _get_cart_quotation(party)
cart_settings = frappe.get_doc("E Commerce Settings")
set_price_list_and_rate(quotation, cart_settings)
quotation.run_method("calculate_taxes_and_totals")
set_taxes(quotation, cart_settings)
_apply_shipping_rule(party, quotation, cart_settings)
def set_price_list_and_rate(quotation, cart_settings):
"""set price list based on billing territory"""
_set_price_list(cart_settings, quotation)
# reset values
quotation.price_list_currency = quotation.currency = \
quotation.plc_conversion_rate = quotation.conversion_rate = None
for item in quotation.get("items"):
item.price_list_rate = item.discount_percentage = item.rate = item.amount = None
# refetch values
quotation.run_method("set_price_list_and_item_details")
if hasattr(frappe.local, "cookie_manager"):
# set it in cookies for using in product page
frappe.local.cookie_manager.set_cookie("selling_price_list", quotation.selling_price_list)
def _set_price_list(cart_settings, quotation=None):
"""Set price list based on customer or shopping cart default"""
from erpnext.accounts.party import get_default_price_list
party_name = quotation.get("party_name") if quotation else get_party().get("name")
selling_price_list = None
# check if default customer price list exists
if party_name and frappe.db.exists("Customer", party_name):
selling_price_list = get_default_price_list(frappe.get_doc("Customer", party_name))
# check default price list in shopping cart
if not selling_price_list:
selling_price_list = cart_settings.price_list
if quotation:
quotation.selling_price_list = selling_price_list
return selling_price_list
def set_taxes(quotation, cart_settings):
"""set taxes based on billing territory"""
from erpnext.accounts.party import set_taxes
customer_group = frappe.db.get_value("Customer", quotation.party_name, "customer_group")
quotation.taxes_and_charges = set_taxes(quotation.party_name, "Customer",
quotation.transaction_date, quotation.company, customer_group=customer_group, supplier_group=None,
tax_category=quotation.tax_category, billing_address=quotation.customer_address,
shipping_address=quotation.shipping_address_name, use_for_shopping_cart=1)
#
# # clear table
quotation.set("taxes", [])
#
# # append taxes
quotation.append_taxes_from_master()
def get_party(user=None):
if not user:
user = frappe.session.user
contact_name = get_contact_name(user)
party = None
if contact_name:
contact = frappe.get_doc('Contact', contact_name)
if contact.links:
party_doctype = contact.links[0].link_doctype
party = contact.links[0].link_name
cart_settings = frappe.get_doc("E Commerce Settings")
debtors_account = ''
if cart_settings.enable_checkout:
debtors_account = get_debtors_account(cart_settings)
if party:
return frappe.get_doc(party_doctype, party)
else:
if not cart_settings.enabled:
frappe.local.flags.redirect_location = "/contact"
raise frappe.Redirect
customer = frappe.new_doc("Customer")
fullname = get_fullname(user)
customer.update({
"customer_name": fullname,
"customer_type": "Individual",
"customer_group": get_shopping_cart_settings().default_customer_group,
"territory": get_root_of("Territory")
})
if debtors_account:
customer.update({
"accounts": [{
"company": cart_settings.company,
"account": debtors_account
}]
})
customer.flags.ignore_mandatory = True
customer.insert(ignore_permissions=True)
contact = frappe.new_doc("Contact")
contact.update({
"first_name": fullname,
"email_ids": [{"email_id": user, "is_primary": 1}]
})
contact.append('links', dict(link_doctype='Customer', link_name=customer.name))
contact.flags.ignore_mandatory = True
contact.insert(ignore_permissions=True)
return customer
def get_debtors_account(cart_settings):
if not cart_settings.payment_gateway_account:
frappe.throw(_("Payment Gateway Account not set"), _("Mandatory"))
payment_gateway_account_currency = \
frappe.get_doc("Payment Gateway Account", cart_settings.payment_gateway_account).currency
account_name = _("Debtors ({0})").format(payment_gateway_account_currency)
debtors_account_name = get_account_name("Receivable", "Asset", is_group=0,\
account_currency=payment_gateway_account_currency, company=cart_settings.company)
if not debtors_account_name:
debtors_account = frappe.get_doc({
"doctype": "Account",
"account_type": "Receivable",
"root_type": "Asset",
"is_group": 0,
"parent_account": get_account_name(root_type="Asset", is_group=1, company=cart_settings.company),
"account_name": account_name,
"currency": payment_gateway_account_currency
}).insert(ignore_permissions=True)
return debtors_account.name
else:
return debtors_account_name
def get_address_docs(doctype=None, txt=None, filters=None, limit_start=0, limit_page_length=20,
party=None):
if not party:
party = get_party()
if not party:
return []
address_names = frappe.db.get_all('Dynamic Link', fields=('parent'),
filters=dict(parenttype='Address', link_doctype=party.doctype, link_name=party.name))
out = []
for a in address_names:
address = frappe.get_doc('Address', a.parent)
address.display = get_address_display(address.as_dict())
out.append(address)
return out
@frappe.whitelist()
def apply_shipping_rule(shipping_rule):
quotation = _get_cart_quotation()
quotation.shipping_rule = shipping_rule
apply_cart_settings(quotation=quotation)
quotation.flags.ignore_permissions = True
quotation.save()
return get_cart_quotation(quotation)
def _apply_shipping_rule(party=None, quotation=None, cart_settings=None):
if not quotation.shipping_rule:
shipping_rules = get_shipping_rules(quotation, cart_settings)
if not shipping_rules:
return
elif quotation.shipping_rule not in shipping_rules:
quotation.shipping_rule = shipping_rules[0]
if quotation.shipping_rule:
quotation.run_method("apply_shipping_rule")
quotation.run_method("calculate_taxes_and_totals")
def get_applicable_shipping_rules(party=None, quotation=None):
shipping_rules = get_shipping_rules(quotation)
if shipping_rules:
rule_label_map = frappe.db.get_values("Shipping Rule", shipping_rules, "label")
# we need this in sorted order as per the position of the rule in the settings page
return [[rule, rule] for rule in shipping_rules]
def get_shipping_rules(quotation=None, cart_settings=None):
if not quotation:
quotation = _get_cart_quotation()
shipping_rules = []
if quotation.shipping_address_name:
country = frappe.db.get_value("Address", quotation.shipping_address_name, "country")
if country:
shipping_rules = frappe.db.sql_list("""select distinct sr.name
from `tabShipping Rule Country` src, `tabShipping Rule` sr
where src.country = %s and
sr.disabled != 1 and sr.name = src.parent""", country)
return shipping_rules
def get_address_territory(address_name):
"""Tries to match city, state and country of address to existing territory"""
territory = None
if address_name:
address_fields = frappe.db.get_value("Address", address_name,
["city", "state", "country"])
for value in address_fields:
territory = frappe.db.get_value("Territory", value)
if territory:
break
return territory
def show_terms(doc):
return doc.tc_name
@frappe.whitelist(allow_guest=True)
def apply_coupon_code(applied_code, applied_referral_sales_partner):
quotation = True
if not applied_code:
frappe.throw(_("Please enter a coupon code"))
coupon_list = frappe.get_all('Coupon Code', filters={'coupon_code': applied_code})
if not coupon_list:
frappe.throw(_("Please enter a valid coupon code"))
coupon_name = coupon_list[0].name
from erpnext.accounts.doctype.pricing_rule.utils import validate_coupon_code
validate_coupon_code(coupon_name)
quotation = _get_cart_quotation()
quotation.coupon_code = coupon_name
quotation.flags.ignore_permissions = True
quotation.save()
if applied_referral_sales_partner:
sales_partner_list = frappe.get_all('Sales Partner', filters={'referral_code': applied_referral_sales_partner})
if sales_partner_list:
sales_partner_name = sales_partner_list[0].name
quotation.referral_sales_partner = sales_partner_name
quotation.flags.ignore_permissions = True
quotation.save()
return quotation

View File

@@ -1,87 +0,0 @@
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
import frappe
class ProductFiltersBuilder:
def __init__(self, item_group=None):
if not item_group or item_group == "E Commerce Settings":
self.doc = frappe.get_doc("E Commerce Settings")
else:
self.doc = frappe.get_doc("Item Group", item_group)
self.item_group = item_group
def get_field_filters(self):
if not self.doc.enable_field_filters: return
filter_fields = [row.fieldname for row in self.doc.filter_fields]
meta = frappe.get_meta('Item')
fields = [df for df in meta.fields if df.fieldname in filter_fields]
filter_data = []
for df in fields:
filters, or_filters = {}, []
if df.fieldtype == "Link":
if self.item_group:
or_filters.extend([
["item_group", "=", self.item_group],
["Website Item Group", "item_group", "=", self.item_group]
])
values = frappe.get_all("Item", fields=[df.fieldname], filters=filters, or_filters=or_filters, distinct="True", pluck=df.fieldname)
else:
doctype = df.get_link_doctype()
# apply enable/disable/show_in_website filter
meta = frappe.get_meta(doctype)
if meta.has_field('enabled'):
filters['enabled'] = 1
if meta.has_field('disabled'):
filters['disabled'] = 0
if meta.has_field('show_in_website'):
filters['show_in_website'] = 1
values = [d.name for d in frappe.get_all(doctype, filters)]
# Remove None
if None in values: values.remove(None)
if values:
filter_data.append([df, values])
return filter_data
def get_attribute_filters(self):
if not self.doc.enable_attribute_filters: return
attributes = [row.attribute for row in self.doc.filter_attributes]
if not attributes:
return []
result = frappe.db.sql(
"""
select
distinct attribute, attribute_value
from
`tabItem Variant Attribute`
where
attribute in %(attributes)s
and attribute_value is not null
""",
{"attributes": attributes},
as_dict=1,
)
attribute_value_map = {}
for d in result:
attribute_value_map.setdefault(d.attribute, []).append(d.attribute_value)
out = []
for name, values in attribute_value_map.items():
out.append(frappe._dict(name=name, item_attribute_values=values))
return out

View File

@@ -1,70 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
import frappe
from erpnext.shopping_cart.cart import _get_cart_quotation, _set_price_list
from erpnext.e_commerce.doctype.e_commerce_settings.e_commerce_settings import (
get_shopping_cart_settings,
show_quantity_in_website
)
from erpnext.utilities.product import get_price, get_qty_in_stock, get_non_stock_item_status
@frappe.whitelist(allow_guest=True)
def get_product_info_for_website(item_code, skip_quotation_creation=False):
"""get product price / stock info for website"""
cart_settings = get_shopping_cart_settings()
if not cart_settings.enabled:
return frappe._dict()
cart_quotation = frappe._dict()
if not skip_quotation_creation:
cart_quotation = _get_cart_quotation()
selling_price_list = cart_quotation.get("selling_price_list") if cart_quotation else _set_price_list(cart_settings, None)
price = get_price(
item_code,
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 get_non_stock_item_status(item_code, "website_warehouse"),
"qty": 0,
"uom": frappe.db.get_value("Item", item_code, "stock_uom"),
"show_stock_qty": show_quantity_in_website(),
"sales_uom": frappe.db.get_value("Item", item_code, "sales_uom")
}
if product_info["price"]:
if frappe.session.user != "Guest":
item = cart_quotation.get({"item_code": item_code}) if cart_quotation else None
if item:
product_info["qty"] = item[0].qty
return frappe._dict({
"product_info": product_info,
"cart_settings": cart_settings
})
def set_product_info_for_website(item):
"""set product price uom for website"""
product_info = get_product_info_for_website(item.item_code, skip_quotation_creation=True).get("product_info")
if product_info:
item.update(product_info)
item["stock_uom"] = product_info.get("uom")
item["sales_uom"] = product_info.get("sales_uom")
if product_info.get("price"):
item["price_stock_uom"] = product_info.get("price").get("formatted_price")
item["price_sales_uom"] = product_info.get("price").get("formatted_price_sales_uom")
else:
item["price_stock_uom"] = ""
item["price_sales_uom"] = ""

View File

@@ -1,171 +0,0 @@
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
import frappe
from erpnext.shopping_cart.product_info import get_product_info_for_website
class ProductQuery:
"""Query engine for product listing
Attributes:
fields (list): Fields to fetch in query
conditions (string): Conditions for query building
or_conditions (string): Search conditions
page_length (Int): Length of page for the query
settings (Document): E Commerce Settings DocType
"""
def __init__(self):
self.settings = frappe.get_doc("E Commerce Settings")
self.page_length = self.settings.products_per_page or 20
self.fields = ['wi.name', 'wi.item_name', 'wi.item_code', 'wi.website_image', 'wi.variant_of',
'wi.has_variants', 'wi.item_group', 'wi.image', 'wi.web_long_description', 'wi.description',
'wi.route']
self.conditions = ""
self.or_conditions = ""
self.substitutions = []
def query(self, attributes=None, fields=None, search_term=None, start=0, item_group=None):
"""Summary
Args:
attributes (dict, optional): Item Attribute filters
fields (dict, optional): Field level filters
search_term (str, optional): Search term to lookup
start (int, optional): Page start
Returns:
list: List of results with set fields
"""
if fields: self.build_fields_filters(fields)
if search_term: self.build_search_filters(search_term)
if self.settings.hide_variants:
self.conditions += " and wi.variant_of is null"
result = []
website_item_groups = []
# if from item group page consider website item group table
if item_group:
website_item_groups = frappe.db.get_all(
"Item",
fields=self.fields + ["`tabWebsite Item Group`.parent as wig_parent"],
filters=[["Website Item Group", "item_group", "=", item_group]]
)
if attributes:
result = self.query_items_with_attributes(attributes, start)
else:
result = self.query_items(self.conditions, self.or_conditions,
self.substitutions, start=start)
# add price info in results
for item in result:
product_info = get_product_info_for_website(item.item_code, skip_quotation_creation=True).get('product_info')
if product_info:
item.formatted_price = (product_info.get('price') or {}).get('formatted_price')
return result
def query_items(self, conditions, or_conditions, substitutions, start=0):
"""Build a query to fetch Website Items based on field filters."""
self.query_fields = (", ").join(self.fields)
return frappe.db.sql("""
select distinct {query_fields}
from
`tabWebsite Item` wi, `tabItem Variant Attribute` iva
where
wi.published = 1
{conditions}
{or_conditions}
limit {limit} offset {start}
""".format(
query_fields=self.query_fields,
conditions=conditions,
or_conditions=or_conditions,
limit=self.page_length,
start=start),
tuple(substitutions),
as_dict=1)
def query_items_with_attributes(self, attributes, start=0):
"""Build a query to fetch Website Items based on field & attribute filters."""
all_items = []
self.conditions += " and iva.parent = wi.item_code"
for attribute, values in attributes.items():
if not isinstance(values, list): values = [values]
conditions_copy = self.conditions
substitutions_copy = self.substitutions.copy()
conditions_copy += " and iva.attribute = '{0}' and iva.attribute_value in ({1})" \
.format(attribute, (", ").join(['%s'] * len(values)))
substitutions_copy.extend(values)
items = self.query_items(conditions_copy, self.or_conditions, substitutions_copy, start=start)
items_dict = {item.name: item for item in items}
# TODO: Replace Variants by their parent templates
all_items.append(set(items_dict.keys()))
result = [items_dict.get(item) for item in list(set.intersection(*all_items))]
return result
def build_fields_filters(self, filters):
"""Build filters for field values
Args:
filters (dict): Filters
"""
for field, values in filters.items():
if not values:
continue
# handle multiselect fields in filter addition
meta = frappe.get_meta('Item', cached=True)
df = meta.get_field(field)
if df.fieldtype == 'Table MultiSelect':
child_doctype = df.options
child_meta = frappe.get_meta(child_doctype, cached=True)
fields = child_meta.get("fields")
if fields:
self.filters.append([child_doctype, fields[0].fieldname, 'IN', values])
elif isinstance(values, list):
# If value is a list use `IN` query
self.conditions += " and wi.{0} in ({1})".format(field, (', ').join(['%s'] * len(values)))
self.substitutions.extend(values)
else:
# `=` will be faster than `IN` for most cases
self.conditions += " and wi.{0} = '{1}'".format(field, values)
def build_search_filters(self, search_term):
"""Query search term in specified fields
Args:
search_term (str): Search candidate
"""
# Default fields to search from
default_fields = {'name', 'item_name', 'description', 'item_group'}
# Get meta search fields
meta = frappe.get_meta("Item")
meta_fields = set(meta.get_search_fields())
# Join the meta fields and default fields set
search_fields = default_fields.union(meta_fields)
try:
if frappe.db.count('Item', cache=True) > 50000:
search_fields.remove('description')
except KeyError:
pass
# Build or filters for query
search = '%{}%'.format(search_term)
for field in search_fields:
self.or_conditions += " or {0} like '{1}'".format(field, search)

View File

@@ -1,126 +0,0 @@
import frappe
from frappe.search.full_text_search import FullTextSearch
from frappe.utils import strip_html_tags
from whoosh.analysis import StemmingAnalyzer
from whoosh.fields import ID, KEYWORD, TEXT, Schema
from whoosh.qparser import FieldsPlugin, MultifieldParser, WildcardPlugin
from whoosh.query import Prefix
INDEX_NAME = "products"
class ProductSearch(FullTextSearch):
""" Wrapper for WebsiteSearch """
def get_schema(self):
return Schema(
title=TEXT(stored=True, field_boost=1.5),
name=ID(stored=True),
path=ID(stored=True),
content=TEXT(stored=True, analyzer=StemmingAnalyzer()),
keywords=KEYWORD(stored=True, scorable=True, commas=True),
)
def get_id(self):
return "name"
def get_items_to_index(self):
"""Get all routes to be indexed, this includes the static pages
in www/ and routes from published documents
Returns:
self (object): FullTextSearch Instance
"""
items = get_all_published_items()
documents = [self.get_document_to_index(item) for item in items]
return documents
def get_document_to_index(self, item):
try:
item = frappe.get_doc("Item", item)
title = item.item_name
keywords = [item.item_group]
if item.brand:
keywords.append(item.brand)
if item.website_image_alt:
keywords.append(item.website_image_alt)
if item.has_variants and item.variant_based_on == "Item Attribute":
keywords = keywords + [attr.attribute for attr in item.attributes]
if item.web_long_description:
content = strip_html_tags(item.web_long_description)
elif item.description:
content = strip_html_tags(item.description)
return frappe._dict(
title=title,
name=item.name,
path=item.route,
content=content,
keywords=", ".join(keywords),
)
except Exception:
pass
def search(self, text, scope=None, limit=20):
"""Search from the current index
Args:
text (str): String to search for
scope (str, optional): Scope to limit the search. Defaults to None.
limit (int, optional): Limit number of search results. Defaults to 20.
Returns:
[List(_dict)]: Search results
"""
ix = self.get_index()
results = None
out = []
with ix.searcher() as searcher:
parser = MultifieldParser(["title", "content", "keywords"], ix.schema)
parser.remove_plugin_class(FieldsPlugin)
parser.remove_plugin_class(WildcardPlugin)
query = parser.parse(text)
filter_scoped = None
if scope:
filter_scoped = Prefix(self.id, scope)
results = searcher.search(query, limit=limit, filter=filter_scoped)
for r in results:
out.append(self.parse_result(r))
return out
def parse_result(self, result):
title_highlights = result.highlights("title")
content_highlights = result.highlights("content")
keyword_highlights = result.highlights("keywords")
return frappe._dict(
title=result["title"],
path=result["path"],
keywords=result["keywords"],
title_highlights=title_highlights,
content_highlights=content_highlights,
keyword_highlights=keyword_highlights,
)
def get_all_published_items():
return frappe.get_all("Website Item", filters={"variant_of": "", "published": 1}, pluck="item_code")
def update_index_for_path(path):
search = ProductSearch(INDEX_NAME)
return search.update_index_by_name(path)
def remove_document_from_index(path):
search = ProductSearch(INDEX_NAME)
return search.remove_document_from_index(path)
def build_index_for_all_routes():
search = ProductSearch(INDEX_NAME)
return search.build()

View File

@@ -1,237 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import unittest
import frappe
from frappe.utils import add_months, nowdate
from erpnext.accounts.doctype.tax_rule.tax_rule import ConflictingTaxRule
from erpnext.shopping_cart.cart import _get_cart_quotation, get_party, update_cart
from erpnext.tests.utils import create_test_contact_and_address
# test_dependencies = ['Payment Terms Template']
class TestShoppingCart(unittest.TestCase):
"""
Note:
Shopping Cart == Quotation
"""
@classmethod
def tearDownClass(cls):
frappe.db.sql("delete from `tabTax Rule`")
def setUp(self):
frappe.set_user("Administrator")
create_test_contact_and_address()
self.enable_shopping_cart()
def tearDown(self):
frappe.set_user("Administrator")
self.disable_shopping_cart()
def test_get_cart_new_user(self):
self.login_as_new_user()
# test if lead is created and quotation with new lead is fetched
quotation = _get_cart_quotation()
self.assertEqual(quotation.quotation_to, "Customer")
self.assertEqual(quotation.contact_person,
frappe.db.get_value("Contact", dict(email_id="test_cart_user@example.com")))
self.assertEqual(quotation.contact_email, frappe.session.user)
return quotation
def test_get_cart_customer(self):
self.login_as_customer()
# test if quotation with customer is fetched
quotation = _get_cart_quotation()
self.assertEqual(quotation.quotation_to, "Customer")
self.assertEqual(quotation.party_name, "_Test Customer")
self.assertEqual(quotation.contact_email, frappe.session.user)
return quotation
def test_add_to_cart(self):
self.login_as_customer()
# clear existing quotations
self.clear_existing_quotations()
# add first item
update_cart("_Test Item", 1)
quotation = self.test_get_cart_customer()
self.assertEqual(quotation.get("items")[0].item_code, "_Test Item")
self.assertEqual(quotation.get("items")[0].qty, 1)
self.assertEqual(quotation.get("items")[0].amount, 10)
# add second item
update_cart("_Test Item 2", 1)
quotation = self.test_get_cart_customer()
self.assertEqual(quotation.get("items")[1].item_code, "_Test Item 2")
self.assertEqual(quotation.get("items")[1].qty, 1)
self.assertEqual(quotation.get("items")[1].amount, 20)
self.assertEqual(len(quotation.get("items")), 2)
def test_update_cart(self):
# first, add to cart
self.test_add_to_cart()
# update first item
update_cart("_Test Item", 5)
quotation = self.test_get_cart_customer()
self.assertEqual(quotation.get("items")[0].item_code, "_Test Item")
self.assertEqual(quotation.get("items")[0].qty, 5)
self.assertEqual(quotation.get("items")[0].amount, 50)
self.assertEqual(quotation.net_total, 70)
self.assertEqual(len(quotation.get("items")), 2)
def test_remove_from_cart(self):
# first, add to cart
self.test_add_to_cart()
# remove first item
update_cart("_Test Item", 0)
quotation = self.test_get_cart_customer()
self.assertEqual(quotation.get("items")[0].item_code, "_Test Item 2")
self.assertEqual(quotation.get("items")[0].qty, 1)
self.assertEqual(quotation.get("items")[0].amount, 20)
self.assertEqual(quotation.net_total, 20)
self.assertEqual(len(quotation.get("items")), 1)
def test_tax_rule(self):
self.create_tax_rule()
self.login_as_customer()
quotation = self.create_quotation()
from erpnext.accounts.party import set_taxes
tax_rule_master = set_taxes(quotation.party_name, "Customer",
quotation.transaction_date, quotation.company, customer_group=None, supplier_group=None,
tax_category=quotation.tax_category, billing_address=quotation.customer_address,
shipping_address=quotation.shipping_address_name, use_for_shopping_cart=1)
self.assertEqual(quotation.taxes_and_charges, tax_rule_master)
self.assertEqual(quotation.total_taxes_and_charges, 1000.0)
self.remove_test_quotation(quotation)
def create_tax_rule(self):
tax_rule = frappe.get_test_records("Tax Rule")[0]
try:
frappe.get_doc(tax_rule).insert()
except (frappe.DuplicateEntryError, ConflictingTaxRule):
pass
def create_quotation(self):
quotation = frappe.new_doc("Quotation")
values = {
"doctype": "Quotation",
"quotation_to": "Customer",
"order_type": "Shopping Cart",
"party_name": get_party(frappe.session.user).name,
"docstatus": 0,
"contact_email": frappe.session.user,
"selling_price_list": "_Test Price List Rest of the World",
"currency": "USD",
"taxes_and_charges" : "_Test Tax 1 - _TC",
"conversion_rate":1,
"transaction_date" : nowdate(),
"valid_till" : add_months(nowdate(), 1),
"items": [{
"item_code": "_Test Item",
"qty": 1
}],
"taxes": frappe.get_doc("Sales Taxes and Charges Template", "_Test Tax 1 - _TC").taxes,
"company": "_Test Company"
}
quotation.update(values)
quotation.insert(ignore_permissions=True)
return quotation
def remove_test_quotation(self, quotation):
frappe.set_user("Administrator")
quotation.delete()
# helper functions
def enable_shopping_cart(self):
settings = frappe.get_doc("E Commerce Settings", "E Commerce Settings")
settings.update({
"enabled": 1,
"company": "_Test Company",
"default_customer_group": "_Test Customer Group",
"quotation_series": "_T-Quotation-",
"price_list": "_Test Price List India"
})
# insert item price
if not frappe.db.get_value("Item Price", {"price_list": "_Test Price List India",
"item_code": "_Test Item"}):
frappe.get_doc({
"doctype": "Item Price",
"price_list": "_Test Price List India",
"item_code": "_Test Item",
"price_list_rate": 10
}).insert()
frappe.get_doc({
"doctype": "Item Price",
"price_list": "_Test Price List India",
"item_code": "_Test Item 2",
"price_list_rate": 20
}).insert()
settings.save()
frappe.local.shopping_cart_settings = None
def disable_shopping_cart(self):
settings = frappe.get_doc("E Commerce Settings", "E Commerce Settings")
settings.enabled = 0
settings.save()
frappe.local.shopping_cart_settings = None
def login_as_new_user(self):
self.create_user_if_not_exists("test_cart_user@example.com")
frappe.set_user("test_cart_user@example.com")
def login_as_customer(self):
self.create_user_if_not_exists("test_contact_customer@example.com",
"_Test Contact For _Test Customer")
frappe.set_user("test_contact_customer@example.com")
def clear_existing_quotations(self):
quotations = frappe.get_all("Quotation", filters={
"party_name": get_party().name,
"order_type": "Shopping Cart",
"docstatus": 0
}, order_by="modified desc", pluck="name")
for quotation in quotations:
frappe.delete_doc("Quotation", quotation, ignore_permissions=True, force=True)
def create_user_if_not_exists(self, email, first_name = None):
if frappe.db.exists("User", email):
return
frappe.get_doc({
"doctype": "User",
"user_type": "Website User",
"email": email,
"send_welcome_email": 0,
"first_name": first_name or email.split("@")[0]
}).insert(ignore_permissions=True)
test_dependencies = ["Sales Taxes and Charges Template", "Price List", "Item Price", "Shipping Rule", "Currency Exchange",
"Customer Group", "Lead", "Customer", "Contact", "Address", "Item", "Tax Rule"]

View File

@@ -1,39 +0,0 @@
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
import frappe
from erpnext.e_commerce.doctype.e_commerce_settings.e_commerce_settings import is_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 set_cart_count(login_manager):
role, parties = check_customer_or_supplier()
if role == 'Supplier': return
if show_cart_count():
from erpnext.shopping_cart.cart import set_cart_count
set_cart_count()
def clear_cart_count(login_manager):
if show_cart_count():
frappe.local.cookie_manager.delete_cookie("cart_count")
def update_website_context(context):
cart_enabled = is_cart_enabled()
context["shopping_cart_enabled"] = cart_enabled
def check_customer_or_supplier():
if frappe.session.user:
contact_name = frappe.get_value("Contact", {"email_id": frappe.session.user})
if contact_name:
contact = frappe.get_doc('Contact', contact_name)
for link in contact.links:
if link.link_doctype in ('Customer', 'Supplier'):
return link.link_doctype, link.link_name
return 'Customer', None

View File

@@ -1,86 +0,0 @@
{%- macro slide(image, title, subtitle, action, label, index, align="Left", theme="Dark") -%}
{%- set align_class = resolve_class({
'text-right': align == 'Right',
'text-centre': align == 'Centre',
'text-left': align == 'Left',
}) -%}
{%- set heading_class = resolve_class({
'text-white': theme == 'Dark',
'': theme == 'Light',
}) -%}
<div class="carousel-item {{ 'active' if index=='1' else ''}}" style="height: 450px;">
<img class="d-block h-100 w-100" style="object-fit: cover;" src="{{ image }}" alt="{{ title }}">
{%- if title or subtitle -%}
<div class="carousel-body container d-flex {{ align_class }}">
<div class="carousel-content align-self-center">
{%- if title -%}<h1 class="{{ heading_class }}">{{ title }}</h1>{%- endif -%}
{%- if subtitle -%}<p class="{{ heading_class }} mt-2">{{ subtitle }}</p>{%- endif -%}
{%- if action -%}
<a href="{{ action }}" class="btn btn-primary mt-3">
{{ label }}
</a>
{%- endif -%}
</div>
</div>
{%- endif -%}
</div>
{%- endmacro -%}
{%- set hero_slider_id = 'id-' + frappe.utils.generate_hash('HeroSlider', 12) -%}
<div id="{{ hero_slider_id }}" class="section-carousel carousel slide" data-ride="carousel">
{%- if show_indicators -%}
<ol class="carousel-indicators">
{%- for index in ['1', '2', '3', '4', '5'] -%}
{%- if values['slide_' + index + '_image'] -%}
<li data-target="#{{ hero_slider_id }}" data-slide-to="{{ frappe.utils.cint(index) - 1 }}" class="{{ 'active' if index=='1' else ''}}"></li>
{%- endif -%}
{%- endfor -%}
</ol>
{%- endif -%}
<div class="carousel-inner {{ resolve_class({'rounded-carousel': rounded }) }}">
{%- for index in ['1', '2', '3', '4', '5'] -%}
{%- set image = values['slide_' + index + '_image'] -%}
{%- set title = values['slide_' + index + '_title'] -%}
{%- set subtitle = values['slide_' + index + '_subtitle'] -%}
{%- set primary_action = values['slide_' + index + '_primary_action'] -%}
{%- set primary_action_label = values['slide_' + index + '_primary_action_label'] -%}
{%- set align = values['slide_' + index + '_content_align'] -%}
{%- set theme = values['slide_' + index + '_theme'] -%}
{%- if image -%}
{{ slide(image, title, subtitle, primary_action, primary_action_label, index, align, theme) }}
{%- endif -%}
{%- endfor -%}
</div>
{%- if show_controls -%}
<a class="carousel-control-prev" href="#{{ hero_slider_id }}" role="button" data-slide="prev">
<div class="carousel-control">
<svg class="mr-1" width="20" height="20" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M11.625 3.75L6.375 9L11.625 14.25" stroke="#4C5A67" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</div>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#{{ hero_slider_id }}" role="button" data-slide="next">
<div class="carousel-control">
<svg class="ml-1" width="20" height="20" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M6.375 14.25L11.625 9L6.375 3.75" stroke="#4C5A67" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</div>
<span class="sr-only">Next</span>
</a>
{%- endif -%}
</div>
<script>
frappe.ready(function () {
$('.carousel').carousel({
interval: false,
pause: "hover",
wrap: true
})
});
</script>

View File

@@ -1,284 +0,0 @@
{
"creation": "2020-11-17 15:21:51.207221",
"docstatus": 0,
"doctype": "Web Template",
"fields": [
{
"fieldname": "slider_name",
"fieldtype": "Data",
"label": "Slider Name",
"reqd": 1
},
{
"default": "1",
"fieldname": "show_indicators",
"fieldtype": "Check",
"label": "Show Indicators",
"reqd": 0
},
{
"default": "1",
"fieldname": "show_controls",
"fieldtype": "Check",
"label": "Show Controls",
"reqd": 0
},
{
"fieldname": "slide_1",
"fieldtype": "Section Break",
"label": "Slide 1",
"reqd": 0
},
{
"fieldname": "slide_1_image",
"fieldtype": "Attach Image",
"label": "Image",
"reqd": 0
},
{
"fieldname": "slide_1_title",
"fieldtype": "Data",
"label": "Title",
"reqd": 0
},
{
"fieldname": "slide_1_subtitle",
"fieldtype": "Small Text",
"label": "Subtitle",
"reqd": 0
},
{
"fieldname": "slide_1_primary_action_label",
"fieldtype": "Data",
"label": "Primary Action Label",
"reqd": 0
},
{
"fieldname": "slide_1_primary_action",
"fieldtype": "Data",
"label": "Primary Action",
"reqd": 0
},
{
"fieldname": "slide_1_content_align",
"fieldtype": "Select",
"label": "Content Align",
"options": "Left\nCentre\nRight",
"reqd": 0
},
{
"fieldname": "slide_1_theme",
"fieldtype": "Select",
"label": "Slide Theme",
"options": "Dark\nLight",
"reqd": 0
},
{
"fieldname": "slide_2",
"fieldtype": "Section Break",
"label": "Slide 2",
"reqd": 0
},
{
"fieldname": "slide_2_image",
"fieldtype": "Attach Image",
"label": "Image ",
"reqd": 0
},
{
"fieldname": "slide_2_title",
"fieldtype": "Data",
"label": "Title ",
"reqd": 0
},
{
"fieldname": "slide_2_subtitle",
"fieldtype": "Small Text",
"label": "Subtitle ",
"reqd": 0
},
{
"fieldname": "slide_2_primary_action_label",
"fieldtype": "Data",
"label": "Primary Action Label ",
"reqd": 0
},
{
"fieldname": "slide_2_primary_action",
"fieldtype": "Data",
"label": "Primary Action ",
"reqd": 0
},
{
"default": "Left",
"fieldname": "slide_2_content_align",
"fieldtype": "Select",
"label": "Content Align",
"options": "Left\nCentre\nRight",
"reqd": 0
},
{
"fieldname": "slide_2_theme",
"fieldtype": "Select",
"label": "Slide Theme",
"options": "Dark\nLight",
"reqd": 0
},
{
"fieldname": "slide_3",
"fieldtype": "Section Break",
"label": "Slide 3",
"reqd": 0
},
{
"fieldname": "slide_3_image",
"fieldtype": "Attach Image",
"label": "Image",
"reqd": 0
},
{
"fieldname": "slide_3_title",
"fieldtype": "Data",
"label": "Title",
"reqd": 0
},
{
"fieldname": "slide_3_subtitle",
"fieldtype": "Small Text",
"label": "Subtitle",
"reqd": 0
},
{
"fieldname": "slide_3_primary_action_label",
"fieldtype": "Data",
"label": "Primary Action Label",
"reqd": 0
},
{
"fieldname": "slide_3_primary_action",
"fieldtype": "Data",
"label": "Primary Action",
"reqd": 0
},
{
"fieldname": "slide_3_content_align",
"fieldtype": "Select",
"label": "Content Align",
"reqd": 0
},
{
"fieldname": "slide_3_theme",
"fieldtype": "Select",
"label": "Slide Theme",
"options": "Dark\nLight",
"reqd": 0
},
{
"fieldname": "slide_4",
"fieldtype": "Section Break",
"label": "Slide 4",
"reqd": 0
},
{
"fieldname": "slide_4_image",
"fieldtype": "Attach Image",
"label": "Image",
"reqd": 0
},
{
"fieldname": "slide_4_title",
"fieldtype": "Data",
"label": "Title",
"reqd": 0
},
{
"fieldname": "slide_4_subtitle",
"fieldtype": "Small Text",
"label": "Subtitle",
"reqd": 0
},
{
"fieldname": "slide_4_primary_action_label",
"fieldtype": "Data",
"label": "Primary Action Label",
"reqd": 0
},
{
"fieldname": "slide_4_primary_action",
"fieldtype": "Data",
"label": "Primary Action",
"reqd": 0
},
{
"fieldname": "slide_4_content_align",
"fieldtype": "Select",
"label": "Content Align",
"reqd": 0
},
{
"fieldname": "slide_4_theme",
"fieldtype": "Select",
"label": "Slide Theme",
"options": "Dark\nLight",
"reqd": 0
},
{
"fieldname": "slide_5",
"fieldtype": "Section Break",
"label": "Slide 5",
"reqd": 0
},
{
"fieldname": "slide_5_image",
"fieldtype": "Attach Image",
"label": "Image",
"reqd": 0
},
{
"fieldname": "slide_5_title",
"fieldtype": "Data",
"label": "Title",
"reqd": 0
},
{
"fieldname": "slide_5_subtitle",
"fieldtype": "Small Text",
"label": "Subtitle",
"reqd": 0
},
{
"fieldname": "slide_5_primary_action_label",
"fieldtype": "Data",
"label": "Primary Action Label",
"reqd": 0
},
{
"fieldname": "slide_5_primary_action",
"fieldtype": "Data",
"label": "Primary Action",
"reqd": 0
},
{
"fieldname": "slide_5_content_align",
"fieldtype": "Select",
"label": "Content Align",
"reqd": 0
},
{
"fieldname": "slide_5_theme",
"fieldtype": "Select",
"label": "Slide Theme",
"options": "Dark\nLight",
"reqd": 0
}
],
"idx": 2,
"modified": "2020-12-29 12:30:02.794994",
"modified_by": "Administrator",
"module": "Shopping Cart",
"name": "Hero Slider",
"owner": "Administrator",
"standard": 1,
"template": "",
"type": "Section"
}

View File

@@ -1,38 +0,0 @@
{% from "erpnext/templates/includes/macros.html" import item_card, item_card_body %}
<div class="section-with-cards item-card-group-section">
<div class="item-group-header d-flex justify-content-between">
<div class="title-section">
{%- if title -%}
<h2 class="section-title">{{ title }}</h2>
{%- endif -%}
{%- if subtitle -%}
<p class="section-description">{{ subtitle }}</p>
{%- endif -%}
</div>
<div class="primary-action-section">
{%- if primary_action -%}
<a href="{{ action }}" class="btn btn-primary pull-right">
{{ primary_action_label }}
</a>
{%- endif -%}
</div>
</div>
<div class="row">
{%- for index in ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'] -%}
{%- set item = values['card_' + index + '_item'] -%}
{%- if item -%}
{%- set item = frappe.get_doc("Item", item) -%}
{{ item_card(
item.item_name, item.image, item.route, item.description,
None, item.item_group, values['card_' + index + '_featured'],
True, "Center"
) }}
{%- endif -%}
{%- endfor -%}
</div>
</div>
<style>
</style>

View File

@@ -1,273 +0,0 @@
{
"__unsaved": 1,
"creation": "2020-11-17 15:35:05.285322",
"docstatus": 0,
"doctype": "Web Template",
"fields": [
{
"fieldname": "title",
"fieldtype": "Data",
"label": "Title",
"reqd": 1
},
{
"fieldname": "subtitle",
"fieldtype": "Data",
"label": "Subtitle",
"reqd": 0
},
{
"__unsaved": 1,
"fieldname": "primary_action_label",
"fieldtype": "Data",
"label": "Primary Action Label",
"reqd": 0
},
{
"__islocal": 1,
"__unsaved": 1,
"fieldname": "primary_action",
"fieldtype": "Data",
"label": "Primary Action",
"reqd": 0
},
{
"fieldname": "card_1",
"fieldtype": "Section Break",
"label": "Card 1",
"reqd": 0
},
{
"fieldname": "card_1_item",
"fieldtype": "Link",
"label": "Item",
"options": "Item",
"reqd": 0
},
{
"fieldname": "card_1_featured",
"fieldtype": "Check",
"label": "Featured",
"reqd": 0
},
{
"fieldname": "card_2",
"fieldtype": "Section Break",
"label": "Card 2",
"reqd": 0
},
{
"fieldname": "card_2_item",
"fieldtype": "Link",
"label": "Item",
"options": "Item",
"reqd": 0
},
{
"fieldname": "card_2_featured",
"fieldtype": "Check",
"label": "Featured",
"reqd": 0
},
{
"fieldname": "card_3",
"fieldtype": "Section Break",
"label": "Card 3",
"options": "",
"reqd": 0
},
{
"fieldname": "card_3_item",
"fieldtype": "Link",
"label": "Item",
"options": "Item",
"reqd": 0
},
{
"fieldname": "card_3_featured",
"fieldtype": "Check",
"label": "Featured",
"reqd": 0
},
{
"fieldname": "card_4",
"fieldtype": "Section Break",
"label": "Card 4",
"reqd": 0
},
{
"fieldname": "card_4_item",
"fieldtype": "Link",
"label": "Item",
"options": "Item",
"reqd": 0
},
{
"fieldname": "card_4_featured",
"fieldtype": "Check",
"label": "Featured",
"reqd": 0
},
{
"fieldname": "card_5",
"fieldtype": "Section Break",
"label": "Card 5",
"reqd": 0
},
{
"fieldname": "card_5_item",
"fieldtype": "Link",
"label": "Item",
"options": "Item",
"reqd": 0
},
{
"fieldname": "card_5_featured",
"fieldtype": "Check",
"label": "Featured",
"reqd": 0
},
{
"fieldname": "card_6",
"fieldtype": "Section Break",
"label": "Card 6",
"reqd": 0
},
{
"fieldname": "card_6_item",
"fieldtype": "Link",
"label": "Item",
"options": "Item",
"reqd": 0
},
{
"fieldname": "card_6_featured",
"fieldtype": "Check",
"label": "Featured",
"reqd": 0
},
{
"fieldname": "card_7",
"fieldtype": "Section Break",
"label": "Card 7",
"reqd": 0
},
{
"fieldname": "card_7_item",
"fieldtype": "Link",
"label": "Item",
"options": "Item",
"reqd": 0
},
{
"fieldname": "card_7_featured",
"fieldtype": "Check",
"label": "Featured",
"reqd": 0
},
{
"fieldname": "card_8",
"fieldtype": "Section Break",
"label": "Card 8",
"reqd": 0
},
{
"fieldname": "card_8_item",
"fieldtype": "Link",
"label": "Item",
"options": "Item",
"reqd": 0
},
{
"fieldname": "card_8_featured",
"fieldtype": "Check",
"label": "Featured",
"reqd": 0
},
{
"fieldname": "card_9",
"fieldtype": "Section Break",
"label": "Card 9",
"reqd": 0
},
{
"fieldname": "card_9_item",
"fieldtype": "Link",
"label": "Item",
"options": "Item",
"reqd": 0
},
{
"fieldname": "card_9_featured",
"fieldtype": "Check",
"label": "Featured",
"reqd": 0
},
{
"fieldname": "card_10",
"fieldtype": "Section Break",
"label": "Card 10",
"reqd": 0
},
{
"fieldname": "card_10_item",
"fieldtype": "Link",
"label": "Item",
"options": "Item",
"reqd": 0
},
{
"fieldname": "card_10_featured",
"fieldtype": "Check",
"label": "Featured",
"reqd": 0
},
{
"fieldname": "card_11",
"fieldtype": "Section Break",
"label": "Card 11",
"reqd": 0
},
{
"fieldname": "card_11_item",
"fieldtype": "Link",
"label": "Item",
"options": "Item",
"reqd": 0
},
{
"fieldname": "card_11_featured",
"fieldtype": "Check",
"label": "Featured",
"reqd": 0
},
{
"fieldname": "card_12",
"fieldtype": "Section Break",
"label": "Card 12",
"reqd": 0
},
{
"fieldname": "card_12_item",
"fieldtype": "Link",
"label": "Item",
"options": "Item",
"reqd": 0
},
{
"fieldname": "card_12_featured",
"fieldtype": "Check",
"label": "Featured",
"reqd": 0
}
],
"idx": 0,
"modified": "2020-11-19 18:48:52.633045",
"modified_by": "Administrator",
"module": "Shopping Cart",
"name": "Item Card Group",
"owner": "Administrator",
"standard": 1,
"template": "",
"type": "Section"
}

View File

@@ -1,33 +0,0 @@
{
"__unsaved": 1,
"creation": "2020-11-17 15:28:47.809342",
"docstatus": 0,
"doctype": "Web Template",
"fields": [
{
"__unsaved": 1,
"fieldname": "item",
"fieldtype": "Link",
"label": "Item",
"options": "Item",
"reqd": 0
},
{
"__unsaved": 1,
"fieldname": "featured",
"fieldtype": "Check",
"label": "Featured",
"options": "",
"reqd": 0
}
],
"idx": 0,
"modified": "2020-11-17 15:33:34.982515",
"modified_by": "Administrator",
"module": "Shopping Cart",
"name": "Product Card",
"owner": "Administrator",
"standard": 1,
"template": "",
"type": "Component"
}

View File

@@ -1,40 +0,0 @@
{%- macro card(title, image, url, text_primary=False) -%}
{%- set align_class = resolve_class({
'text-right': text_primary,
'text-centre': align == 'Center',
'text-left': align == 'Left',
}) -%}
<div class="card h-100">
{% if image %}
<img class="card-img-top" src="{{ image }}" alt="{{ title }}">
{% endif %}
<div class="card-body text-center text-muted small">
{{ title or '' }}
</div>
<a href="{{ url or '#' }}" class="stretched-link"></a>
</div>
{%- endmacro -%}
<div class="section-with-cards product-category-section">
{%- if title -%}
<h2 class="section-title">{{ title }}</h2>
{%- endif -%}
{%- if subtitle -%}
<p class="section-description">{{ subtitle }}</p>
{%- endif -%}
<!-- {%- set card_size = card_size or 'Small' -%} -->
<div class="{{ resolve_class({'mt-6': title}) }}">
<div class="card-grid">
{%- for index in ['1', '2', '3', '4', '5', '6', '7', '8'] -%}
{%- set category = values['category_' + index] -%}
{%- if category -%}
{%- set category = frappe.get_doc("Item Group", category) -%}
{{ card(category.name, category.image, category.route) }}
{%- endif -%}
{%- endfor -%}
</div>
</div>
</div>
<style>
</style>

View File

@@ -1,85 +0,0 @@
{
"__unsaved": 1,
"creation": "2020-11-17 15:25:50.855934",
"docstatus": 0,
"doctype": "Web Template",
"fields": [
{
"fieldname": "title",
"fieldtype": "Data",
"label": "Title",
"reqd": 1
},
{
"fieldname": "subtitle",
"fieldtype": "Data",
"label": "Subtitle",
"reqd": 0
},
{
"fieldname": "category_1",
"fieldtype": "Link",
"label": "Item Group",
"options": "Item Group",
"reqd": 0
},
{
"fieldname": "category_2",
"fieldtype": "Link",
"label": "Item Group",
"options": "Item Group",
"reqd": 0
},
{
"fieldname": "category_3",
"fieldtype": "Link",
"label": "Item Group",
"options": "Item Group",
"reqd": 0
},
{
"fieldname": "category_4",
"fieldtype": "Link",
"label": "Item Group",
"options": "Item Group",
"reqd": 0
},
{
"fieldname": "category_5",
"fieldtype": "Link",
"label": "Item Group",
"options": "Item Group",
"reqd": 0
},
{
"fieldname": "category_6",
"fieldtype": "Link",
"label": "Item Group",
"options": "Item Group",
"reqd": 0
},
{
"fieldname": "category_7",
"fieldtype": "Link",
"label": "Item Group",
"options": "Item Group",
"reqd": 0
},
{
"fieldname": "category_8",
"fieldtype": "Link",
"label": "Item Group",
"options": "Item Group",
"reqd": 0
}
],
"idx": 0,
"modified": "2020-11-18 17:26:28.726260",
"modified_by": "Administrator",
"module": "Shopping Cart",
"name": "Product Category Cards",
"owner": "Administrator",
"standard": 1,
"template": "",
"type": "Section"
}