From b00eb1b0cc2ccf7e31432eb1724e96af27c3ed93 Mon Sep 17 00:00:00 2001 From: prssanna Date: Wed, 20 Jan 2021 17:52:54 +0530 Subject: [PATCH] feat: shopping cart page --- .../images/ui-states/cart-empty-state.png | Bin 0 -> 1593 bytes erpnext/public/scss/shopping_cart.scss | 268 ++++++++++++++++-- erpnext/shopping_cart/cart.py | 36 ++- erpnext/templates/includes/cart.js | 89 ++++-- .../templates/includes/cart/address_card.html | 19 +- .../includes/cart/address_picker_card.html | 12 + .../templates/includes/cart/cart_address.html | 56 ++-- .../includes/cart/cart_address_picker.html | 4 + .../templates/includes/cart/cart_items.html | 16 +- erpnext/templates/includes/macros.html | 4 + .../includes/navbar/navbar_items.html | 8 +- .../templates/includes/order/order_taxes.html | 79 +++--- erpnext/templates/pages/cart.html | 173 ++++++----- erpnext/www/all-products/index.html | 10 +- 14 files changed, 573 insertions(+), 201 deletions(-) create mode 100644 erpnext/public/images/ui-states/cart-empty-state.png create mode 100644 erpnext/templates/includes/cart/address_picker_card.html create mode 100644 erpnext/templates/includes/cart/cart_address_picker.html diff --git a/erpnext/public/images/ui-states/cart-empty-state.png b/erpnext/public/images/ui-states/cart-empty-state.png new file mode 100644 index 0000000000000000000000000000000000000000..e1ead0e175d204e267a9010e70f54ff98d08250c GIT binary patch literal 1593 zcmV-92FCe`P)Fyc*d{ru;znM4Ry#8+h7A#n>pu7kukWQzw`U#dBvLe6H zTCZa;tN7??A$t1ydjH4f(@Q7`g@__SUzS#Ol~Q{o2eb|_lJ{Eaz7X=E7Em+q3(+l$ zFt4KG1YstTh#>sEpE|!)@u?xC+{EW<8H9Nel~hoaG6{1kDyyIlr2F~iWFv5 zlq*3|iV$W+)R-VdE7ionyWkL?!g7g<%^;!w7GMIu#0%)EtE*GjMZ<@%OrjKKbjMe0AyfgJUNn24|*3VY$|T#@ruA*HYp zQ6x!9eU5MThy9=cJTM|mhya6b`si(^5jG;~|wDchS*)~Jp$?_-uxk)(_RkB|_2v@wn~4eAtcB1yZz8`>F4bON>b za%pK(55}z3FE~|A@Bg1sD1%zL?Z!qk{KKM}@+gsBKHb2!&2eO0mq-Y)iu3pV?PuTD z<)j0IGOUh2zAQAuHlH>)!|<8vvGdoz{@#KdkRUq7XZhg598+uRrqnTE>R7_w;p=t! z-o%WGVtUs?w8Fy?d=7lKl6l9GNjlZTMx}*`B2tSA9i)bVHhfR1#Kcj>8`nuXjvN;R zXIiVHxIUv5QQ<(NQz``st4S#juo9-CGA4}T#P!2nrRnCH4C)Ru=<<$Z+7lHHBwX1R zwPF%&e3a5hDCi-znkca^Kx6%;50k_d7B#UlPfE11_0^om#95MDDy2BU%y~>1 zc3*v5+uq#R%X0IUz%s)i8gw^IhG|K{8Ys+5hMC5uQfc9hs!;}kQb+gU^C5K_AqUn) zF}{V32-2Da?b{HYmnn zbbzh6WcJeF=qq+1J z4M}bjM$JC3P!;HGG znb$Cx`%xr?gkj)K$}lkyc0mFmBO_BhI5$QEa5I@W$RIONEkY8JyTj>H7?`1m{_(Ev5+<&%>o8@c z5>?TZq?@z6|C~Sgy)^o`l_q!m-pl zywJyxfq4)X&ZsV}x4-VZ$s~)IWnnj>%%D?<0N=^IYBDRr%rY0oZ~hK{Ks()NV~C*Qi*y%H9N$3Ckl6+p?Ly$Q5vJ6Ks(`(r!qZX<5@im$oqyvzJ)h;H5xxM;D} z+&JXVCyHW<5avTv%=Vwy%^QhDF+PR46qQsElUfwxLzoLuX$3KvMKLag*%Xyk5R+RJ z<3gAXQF#S1)R|CCZl|#=9sciLf|Pz6CLbiDK>&78X^MAf|9pOjMW { + const type = $(e.currentTarget).parents('.address-container').attr('data-address-type'); + $(d.get_field('address_picker').wrapper).html( + this.get_address_template(type) + ); + d.show(); }); }, + get_update_address_dialog() { + return new frappe.ui.Dialog({ + title: "Select Address", + fields: [{ + 'fieldtype': 'HTML', + 'fieldname': 'address_picker', + }], + primary_action_label: __('Set Address'), + primary_action: () => { + const $card = d.$wrapper.find('.address-card.active'); + const address_type = $card.closest('[data-address-type]').attr('data-address-type'); + const address_name = $card.closest('[data-address-name]').attr('data-address-name'); + frappe.call({ + type: "POST", + method: "erpnext.shopping_cart.cart.update_cart_address", + freeze: true, + args: { + address_type, + address_name + }, + callback: function(r) { + d.hide(); + if(!r.exc) { + $(".cart-tax-items").html(r.message.taxes); + shopping_cart.parent.find( + `.address-container[data-address-type="${address_type}"]` + ).html(r.message.address); + } + } + }); + } + }); + }, + + get_address_template(type) { + return { + shipping: `
+
+ {% for address in shipping_addresses %} +
+ {% include "templates/includes/cart/address_picker_card.html" %} +
+ {% endfor %} +
+
`, + billing: `
+
+ {% for address in billing_addresses %} +
+ {% include "templates/includes/cart/address_picker_card.html" %} +
+ {% endfor %} +
+
`, + }[type]; + }, + bind_place_order: function() { $(".btn-place-order").on("click", function() { shopping_cart.place_order(this); @@ -221,6 +269,7 @@ $.extend(shopping_cart, { frappe.ready(function() { $(".cart-icon").hide(); + shopping_cart.parent = $(".cart-container"); shopping_cart.bind_events(); }); diff --git a/erpnext/templates/includes/cart/address_card.html b/erpnext/templates/includes/cart/address_card.html index 646210e65f..667144bd87 100644 --- a/erpnext/templates/includes/cart/address_card.html +++ b/erpnext/templates/includes/cart/address_card.html @@ -1,12 +1,17 @@
-
- +
+ {{ _('Change') }}
-
-
{{ address.title }}
-

+

+
{{ address.title }}
+
{{ address.display }} -

- {{ _('Edit') }} +
+ + + + + {{ _('Edit') }} +
diff --git a/erpnext/templates/includes/cart/address_picker_card.html b/erpnext/templates/includes/cart/address_picker_card.html new file mode 100644 index 0000000000..2334ea2955 --- /dev/null +++ b/erpnext/templates/includes/cart/address_picker_card.html @@ -0,0 +1,12 @@ +
+
+ +
+
+
{{ address.title }}
+

+ {{ address.display }} +

+ {{ _('Edit') }} +
+
\ No newline at end of file diff --git a/erpnext/templates/includes/cart/cart_address.html b/erpnext/templates/includes/cart/cart_address.html index aa25c885fe..3c8267c43d 100644 --- a/erpnext/templates/includes/cart/cart_address.html +++ b/erpnext/templates/includes/cart/cart_address.html @@ -14,31 +14,39 @@
{% endif %} -
-
{{ _("Shipping Address") }}
+
+
{{ _("Shipping Address") }}
+
+ {% for address in shipping_addresses %} + {% if doc.shipping_address_name == address.name %}
- {% for address in shipping_addresses %} -
- {% include "templates/includes/cart/address_card.html" %} -
- {% endfor %} +
+ {% include "templates/includes/cart/address_card.html" %} +
+ {% endif %} + {% endfor %}
-
-
{{ _("Billing Address") }}
-
- {% for address in billing_addresses %} -
- {% include "templates/includes/cart/address_card.html" %} -
- {% endfor %} -
+
+
-
- - +
+
{{ _("Billing Address") }}
+
+ {% for address in billing_addresses %} + {% if doc.customer_address == address.name %} +
+
+ {% include "templates/includes/cart/address_card.html" %} +
+
+ {% endif %} + {% endfor %}
- + diff --git a/erpnext/templates/includes/cart/cart_address_picker.html b/erpnext/templates/includes/cart/cart_address_picker.html new file mode 100644 index 0000000000..72cc5f5142 --- /dev/null +++ b/erpnext/templates/includes/cart/cart_address_picker.html @@ -0,0 +1,4 @@ +
+
{{ _("Shipping Address") }}
+
+ diff --git a/erpnext/templates/includes/cart/cart_items.html b/erpnext/templates/includes/cart/cart_items.html index ca5744bebb..75441c42bc 100644 --- a/erpnext/templates/includes/cart/cart_items.html +++ b/erpnext/templates/includes/cart/cart_items.html @@ -1,15 +1,15 @@ {% for d in doc.items %} -
+
{{ d.item_name }}
-
+
{{ d.item_code }}
{%- set variant_of = frappe.db.get_value('Item', d.item_code, 'variant_of') %} {% if variant_of %} - + {{ _('Variant of') }} {{ variant_of }} {% endif %} @@ -20,20 +20,20 @@
- + - + - +
{% if cart_settings.enable_checkout %} - +
{{ d.get_formatted('amount') }}
- + {{ _('Rate:') }} {{ d.get_formatted('rate') }} diff --git a/erpnext/templates/includes/macros.html b/erpnext/templates/includes/macros.html index 74c84ba27c..0adfbc9dfd 100644 --- a/erpnext/templates/includes/macros.html +++ b/erpnext/templates/includes/macros.html @@ -90,6 +90,10 @@
{% if image %} {{ title }} + {% else %} +
+ {{ frappe.utils.get_abbr(title) }} +
{% endif %} {{ item_card_body(title, description, url, rate, category, is_featured, align) }}
diff --git a/erpnext/templates/includes/navbar/navbar_items.html b/erpnext/templates/includes/navbar/navbar_items.html index 4daf0e74e0..133d99e5eb 100644 --- a/erpnext/templates/includes/navbar/navbar_items.html +++ b/erpnext/templates/includes/navbar/navbar_items.html @@ -2,9 +2,11 @@ {% block navbar_right_extension %} {% endblock %} \ No newline at end of file diff --git a/erpnext/templates/includes/order/order_taxes.html b/erpnext/templates/includes/order/order_taxes.html index ebec838d03..d2c458e0a4 100644 --- a/erpnext/templates/includes/order/order_taxes.html +++ b/erpnext/templates/includes/order/order_taxes.html @@ -29,12 +29,12 @@ {{ _("Discount") }} - {% set tot_quotation_discount = [] %} - {%- for item in doc.items -%} - {% if tot_quotation_discount.append((((item.price_list_rate * item.qty) - * item.discount_percentage) / 100)) %}{% endif %} - {% endfor %} - {{ frappe.utils.fmt_money((tot_quotation_discount | sum),currency=doc.currency) }} + {% set tot_quotation_discount = [] %} + {%- for item in doc.items -%} + {% if tot_quotation_discount.append((((item.price_list_rate * item.qty) + * item.discount_percentage) / 100)) %}{% endif %} + {% endfor %} + {{ frappe.utils.fmt_money((tot_quotation_discount | sum),currency=doc.currency) }} {% endif %} @@ -47,51 +47,52 @@ {{ _("Total Amount") }} - - {% set total_amount = [] %} - {%- for item in doc.items -%} - {% if total_amount.append((item.price_list_rate * item.qty)) %}{% endif %} - {% endfor %} - {{ frappe.utils.fmt_money((total_amount | sum),currency=doc.currency) }} - + + {% set total_amount = [] %} + {%- for item in doc.items -%} + {% if total_amount.append((item.price_list_rate * item.qty)) %}{% endif %} + {% endfor %} + {{ frappe.utils.fmt_money((total_amount | sum),currency=doc.currency) }} + - - {{ _("Applied Coupon Code") }} - - - - {%- for row in frappe.get_all(doctype="Coupon Code", - fields=["coupon_code"], filters={ "name":doc.coupon_code}) -%} - {{ row.coupon_code }} - {% endfor %} - - + + {{ _("Applied Coupon Code") }} + + + + {%- for row in frappe.get_all(doctype="Coupon Code", + fields=["coupon_code"], filters={ "name":doc.coupon_code}) -%} + {{ row.coupon_code }} + {% endfor %} + + - - {{ _("Discount") }} - - - - {% set tot_SO_discount = [] %} - {%- for item in doc.items -%} - {% if tot_SO_discount.append((((item.price_list_rate * item.qty) - * item.discount_percentage) / 100)) %}{% endif %} - {% endfor %} - {{ frappe.utils.fmt_money((tot_SO_discount | sum),currency=doc.currency) }} - - + + {{ _("Discount") }} + + + + {% set tot_SO_discount = [] %} + {%- for item in doc.items -%} + {% if tot_SO_discount.append((((item.price_list_rate * item.qty) + * item.discount_percentage) / 100)) %}{% endif %} + {% endfor %} + {{ frappe.utils.fmt_money((tot_SO_discount | sum),currency=doc.currency) }} + + {% endif %} {% endif %} - + + {{ _("Grand Total") }} - + {{ doc.get_formatted("grand_total") }} diff --git a/erpnext/templates/pages/cart.html b/erpnext/templates/pages/cart.html index 3033d1587d..2cabf5a9e0 100644 --- a/erpnext/templates/pages/cart.html +++ b/erpnext/templates/pages/cart.html @@ -2,7 +2,7 @@ {% block title %} {{ _("Shopping Cart") }} {% endblock %} -{% block header %}

{{ _("Shopping Cart") }}

{% endblock %} +{% block header %}

{{ _("Shopping Cart") }}

{% endblock %}