2016-05-02 06:13:44 +00:00
|
|
|
{% from "erpnext/templates/includes/cart/cart_macros.html" import show_address %}
|
2019-03-19 06:18:32 +00:00
|
|
|
|
|
|
|
{% if addresses | length == 1%}
|
|
|
|
{% set select_address = True %}
|
|
|
|
{% endif %}
|
|
|
|
|
2019-08-12 08:09:25 +00:00
|
|
|
{% set show_coupon_code = frappe.db.get_single_value('Shopping Cart Settings', 'show_apply_coupon_code_in_website') %}
|
|
|
|
{% if show_coupon_code == 1%}
|
|
|
|
<div class="mb-3">
|
|
|
|
<div class="row no-gutters">
|
|
|
|
<input type="text" class="txtcoupon form-control mr-3 w-25" placeholder="Enter Coupon Code" name="txtcouponcode" ></input>
|
|
|
|
<button class="btn btn-primary btn-sm bt-coupon">{{ _("Apply Coupon Code") }}</button>
|
|
|
|
<input type="hidden" class="txtreferral_sales_partner" placeholder="Enter Sales Partner" name="txtreferral_sales_partner" type="text"></input>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{% endif %}
|
2021-01-20 12:22:54 +00:00
|
|
|
<div class="mb-3 frappe-card p-5" data-section="shipping-address">
|
|
|
|
<h6>{{ _("Shipping Address") }}</h6>
|
|
|
|
<hr>
|
|
|
|
{% for address in shipping_addresses %}
|
|
|
|
{% if doc.shipping_address_name == address.name %}
|
2019-03-19 06:18:32 +00:00
|
|
|
<div class="row no-gutters" data-fieldname="shipping_address_name">
|
2021-01-20 12:22:54 +00:00
|
|
|
<div class="w-100 address-container" data-address-name="{{address.name}}" data-address-type="shipping" data-active>
|
|
|
|
{% include "templates/includes/cart/address_card.html" %}
|
|
|
|
</div>
|
2015-09-16 13:22:52 +00:00
|
|
|
</div>
|
2021-01-20 12:22:54 +00:00
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
2019-03-19 06:18:32 +00:00
|
|
|
</div>
|
2021-01-20 12:22:54 +00:00
|
|
|
<div class="checkbox ml-1 mb-2">
|
|
|
|
<label for="input_same_billing">
|
|
|
|
<input type="checkbox" id="input_same_billing" checked>
|
|
|
|
<span class="label-area">{{ _('Billing Address is same as Shipping Address') }}</span>
|
|
|
|
</label>
|
2015-09-16 13:22:52 +00:00
|
|
|
</div>
|
2021-01-20 12:22:54 +00:00
|
|
|
<div class="mb-3 frappe-card p-5" data-section="billing-address">
|
|
|
|
<h6>{{ _("Billing Address") }}</h6>
|
|
|
|
<hr>
|
|
|
|
{% for address in billing_addresses %}
|
|
|
|
{% if doc.customer_address == address.name %}
|
|
|
|
<div class="row no-gutters" data-fieldname="customer_address">
|
|
|
|
<div class="w-100 address-container" data-address-name="{{address.name}}" data-address-type="billing" data-active>
|
|
|
|
{% include "templates/includes/cart/address_card.html" %}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
2019-03-19 06:18:32 +00:00
|
|
|
</div>
|
2021-01-20 12:22:54 +00:00
|
|
|
<button class="btn btn-outline-primary btn-sm mt-1 btn-new-address bg-white">{{ _("Add a new address") }}</button>
|
2019-03-19 06:18:32 +00:00
|
|
|
|
|
|
|
<script>
|
|
|
|
frappe.ready(() => {
|
|
|
|
$(document).on('click', '.address-card', (e) => {
|
|
|
|
const $target = $(e.currentTarget);
|
|
|
|
const $section = $target.closest('[data-section]');
|
|
|
|
$section.find('.address-card').removeClass('active');
|
|
|
|
$target.addClass('active');
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#input_same_billing').change((e) => {
|
|
|
|
const $check = $(e.target);
|
|
|
|
toggle_billing_address_section(!$check.is(':checked'));
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.btn-new-address').click(() => {
|
2021-01-20 12:22:54 +00:00
|
|
|
console.log('clicked');
|
2019-03-19 06:18:32 +00:00
|
|
|
const d = new frappe.ui.Dialog({
|
|
|
|
title: __('New Address'),
|
|
|
|
fields: [
|
|
|
|
{
|
|
|
|
label: __('Address Title'),
|
|
|
|
fieldname: 'address_title',
|
|
|
|
fieldtype: 'Data',
|
|
|
|
reqd: 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __('Address Line 1'),
|
|
|
|
fieldname: 'address_line1',
|
|
|
|
fieldtype: 'Data',
|
|
|
|
reqd: 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __('Address Line 2'),
|
|
|
|
fieldname: 'address_line2',
|
|
|
|
fieldtype: 'Data'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __('City/Town'),
|
|
|
|
fieldname: 'city',
|
|
|
|
fieldtype: 'Data',
|
|
|
|
reqd: 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __('State'),
|
|
|
|
fieldname: 'state',
|
|
|
|
fieldtype: 'Data'
|
|
|
|
},
|
2019-12-11 12:13:04 +00:00
|
|
|
{
|
|
|
|
label: __('Country'),
|
|
|
|
fieldname: 'country',
|
|
|
|
fieldtype: 'Link',
|
|
|
|
options: 'Country',
|
|
|
|
reqd: 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldname: "column_break0",
|
|
|
|
fieldtype: "Column Break",
|
|
|
|
width: "50%"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __('Address Type'),
|
|
|
|
fieldname: 'address_type',
|
|
|
|
fieldtype: 'Select',
|
|
|
|
options: [
|
|
|
|
'Billing',
|
|
|
|
'Shipping'
|
|
|
|
],
|
|
|
|
reqd: 1
|
|
|
|
},
|
2019-03-19 06:18:32 +00:00
|
|
|
{
|
2020-06-17 05:23:13 +00:00
|
|
|
label: __('Postal Code'),
|
2019-03-19 06:18:32 +00:00
|
|
|
fieldname: 'pincode',
|
|
|
|
fieldtype: 'Data'
|
|
|
|
},
|
|
|
|
{
|
2019-12-11 12:13:04 +00:00
|
|
|
fieldname: "phone",
|
|
|
|
fieldtype: "Data",
|
|
|
|
label: "Phone"
|
2019-03-19 06:18:32 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
primary_action_label: __('Save'),
|
|
|
|
primary_action: (values) => {
|
|
|
|
frappe.call('erpnext.shopping_cart.cart.add_new_address', { doc: values })
|
|
|
|
.then(r => {
|
2020-03-12 09:00:28 +00:00
|
|
|
frappe.call({
|
|
|
|
method: "erpnext.shopping_cart.cart.update_cart_address",
|
|
|
|
args: {
|
|
|
|
address_type: r.message.address_type,
|
|
|
|
address_name: r.message.name
|
|
|
|
},
|
|
|
|
callback: function (r) {
|
|
|
|
d.hide();
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
});
|
2019-03-19 06:18:32 +00:00
|
|
|
});
|
2020-03-12 09:00:28 +00:00
|
|
|
|
2019-03-19 06:18:32 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
d.show();
|
|
|
|
});
|
|
|
|
|
|
|
|
function setup_state() {
|
|
|
|
const shipping_address = $('[data-section="shipping-address"]')
|
|
|
|
.find('[data-address-name][data-active]').attr('data-address-name');
|
|
|
|
|
|
|
|
const billing_address = $('[data-section="billing-address"]')
|
|
|
|
.find('[data-address-name][data-active]').attr('data-address-name');
|
|
|
|
|
|
|
|
$('#input_same_billing').prop('checked', shipping_address === billing_address).trigger('change');
|
|
|
|
|
|
|
|
if (!shipping_address && !billing_address) {
|
|
|
|
$('#input_same_billing').prop('checked', true).trigger('change');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shipping_address) {
|
|
|
|
$(`[data-section="shipping-address"] [data-address-name="${shipping_address}"] .address-card`).addClass('active');
|
|
|
|
}
|
|
|
|
if (billing_address) {
|
|
|
|
$(`[data-section="billing-address"] [data-address-name="${billing_address}"] .address-card`).addClass('active');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_state();
|
|
|
|
|
|
|
|
function toggle_billing_address_section(flag) {
|
|
|
|
$('[data-section="billing-address"]').toggle(flag);
|
|
|
|
}
|
2021-01-20 12:22:54 +00:00
|
|
|
|
|
|
|
$('.btn-change-address').click(() => {
|
|
|
|
// const d = new frappe.ui.Dialog({
|
|
|
|
// })
|
|
|
|
|
|
|
|
// d.show();
|
|
|
|
});
|
2019-03-19 06:18:32 +00:00
|
|
|
});
|
|
|
|
</script>
|