Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: billing address not showing in the portal #65

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 0 additions & 77 deletions webshop/templates/includes/cart/address_card.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,80 +15,3 @@
</a>
</div>
</div>


<script>
frappe.ready(() => {
function get_update_address_dialog() {
let d = 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: "webshop.webshop.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.total);
shopping_cart.parent.find(
`.address-container[data-address-type="${address_type}"]`
).html(r.message.address);
}
}
});
}
});

return d;
}

function get_address_template(type) {
return {
shipping: `<div class="mb-3" data-section="shipping-address">
<div class="row no-gutters" data-fieldname="shipping_address_name">
{% for address in shipping_addresses %}
<div class="mr-3 mb-3 w-100" data-address-name="{{address.name}}" data-address-type="shipping"
{% if doc.shipping_address_name == address.name %} data-active {% endif %}>
{% include "templates/includes/cart/address_picker_card.html" %}
</div>
{% endfor %}
</div>
</div>`,
billing: `<div class="mb-3" data-section="billing-address">
<div class="row no-gutters" data-fieldname="customer_address">
{% for address in billing_addresses %}
<div class="mr-3 mb-3 w-100" data-address-name="{{address.name}}" data-address-type="billing"
{% if doc.shipping_address_name == address.name %} data-active {% endif %}>
{% include "templates/includes/cart/address_picker_card.html" %}
</div>
{% endfor %}
</div>
</div>`,
}[type];
}

$(document).on('click', '.btn-change-address', (e) => {
const d = get_update_address_dialog();
const type = $(e.currentTarget).parents('.address-container').attr('data-address-type');

$(d.get_field('address_picker').wrapper).html(
get_address_template(type)
);

d.show();
});
});
</script>
2 changes: 1 addition & 1 deletion webshop/templates/includes/cart/address_picker_card.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ <h5 class="card-title">{{ address.title }}</h5>
<p class="card-text text-muted">
{{ address.display }}
</p>
<a href="/addresses?name={{address.name}}" class="card-link">{{ _('Edit') }}</a>
<a href="/address/{{address.name}}" class="card-link">{{ _('Edit') }}</a>
</div>
</div>
114 changes: 95 additions & 19 deletions webshop/templates/includes/cart/cart_address.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,27 @@
</label>
</div>

{% if billing_addresses %}
<div class="mb-3 frappe-card p-5" data-section="billing-address">
<div class="d-flex">
<div class="col-6 address-header"><h6>{{ _("Billing Address") }}</h6></div>
<div class="col-6" style="padding: 0;">
<a class="ml-4 btn-new-address" role="button">{{ _("Add a new address") }}</a>
</div>
</div>

<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 %}
<div class="mb-3 frappe-card p-5" data-section="billing-address">
<div class="d-flex">
<div class="col-6 address-header"><h6>{{ _("Billing Address") }}</h6></div>
<div class="col-6" style="padding: 0;">
<a class="ml-4 btn-new-address" role="button">{{ _("Add a new address") }}</a>
</div>
</div>
{% endif %}

<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 %}
</div>


<script>
frappe.ready(() => {
Expand Down Expand Up @@ -186,3 +186,79 @@
}
});
</script>

<script>
frappe.ready(() => {
function get_update_address_dialog() {
let d = 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: "webshop.webshop.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.total);
shopping_cart.parent.find(
`.address-container[data-address-type="${address_type}"]`
).html(r.message.address);
}
}
});
}
});

return d;
}

function get_address_template(type) {
return {
shipping: `<div class="mb-3" data-section="shipping-address">
<div class="row no-gutters" data-fieldname="shipping_address_name">
{% for address in shipping_addresses %}
<div class="mr-3 mb-3 w-100" data-address-name="{{address.name}}" data-address-type="shipping"
{% if doc.shipping_address_name == address.name %} data-active {% endif %}>
{% include "templates/includes/cart/address_picker_card.html" %}
</div>
{% endfor %}
</div>
</div>`,
billing: `<div class="mb-3" data-section="billing-address">
<div class="row no-gutters" data-fieldname="customer_address">
{% for address in billing_addresses %}
<div class="mr-3 mb-3 w-100" data-address-name="{{address.name}}" data-address-type="billing"
{% if doc.shipping_address_name == address.name %} data-active {% endif %}>
{% include "templates/includes/cart/address_picker_card.html" %}
</div>
{% endfor %}
</div>
</div>`,
}[type];
}

$(document).on('click', '.btn-change-address', (e) => {
const d = get_update_address_dialog();
const type = $(e.currentTarget).parents('.address-container').attr('data-address-type');

$(d.get_field('address_picker').wrapper).html(
get_address_template(type)
);

d.show();
});
});
</script>