Widget button: Fall back to front page if no items are specified

This commit is contained in:
Raphael Michel
2018-08-13 14:35:13 +02:00
parent a83bb23540
commit 723fedc066
2 changed files with 12 additions and 6 deletions

View File

@@ -143,7 +143,7 @@ resources. Then, instead of the ``pretix-widget`` tag, use the ``pretix-button``
As you can see, the ``pretix-button`` element takes an additional ``items`` attribute that specifies the items that As you can see, the ``pretix-button`` element takes an additional ``items`` attribute that specifies the items that
should be added to the cart. The syntax of this attribute is ``item_ITEMID=1,item_ITEMID=2,variation_ITEMID_VARID=4`` should be added to the cart. The syntax of this attribute is ``item_ITEMID=1,item_ITEMID=2,variation_ITEMID_VARID=4``
where ``ITEMID`` are the internal IDs of items to be added and ``VARID`` are the internal IDs of variations of those where ``ITEMID`` are the internal IDs of items to be added and ``VARID`` are the internal IDs of variations of those
items, if the items have variations. items, if the items have variations. If you omit the ``items`` attribute, the general start page will be presented.
Just as the widget, the button supports the optional attributes ``voucher`` and ``skip-ssl-check``. Just as the widget, the button supports the optional attributes ``voucher`` and ``skip-ssl-check``.

View File

@@ -392,10 +392,14 @@ var shared_methods = {
} else { } else {
return; return;
} }
var url = this.$root.formTarget + "&locale=" + lang + "&ajax=1"; if (this.$root.is_button && this.$root.items.length === 0) {
this.$root.frame_loading = true; this.resume();
this.async_task_interval = 100; } else {
api._postFormJSON(url, this.$refs.form, this.buy_callback, this.buy_error_callback); var url = this.$root.formTarget + "&locale=" + lang + "&ajax=1";
this.$root.frame_loading = true;
this.async_task_interval = 100;
api._postFormJSON(url, this.$refs.form, this.buy_callback, this.buy_error_callback);
}
}, },
buy_error_callback: function (xhr, data) { buy_error_callback: function (xhr, data) {
this.$root.error_message = strings['cart_error']; this.$root.error_message = strings['cart_error'];
@@ -740,6 +744,7 @@ var create_widget = function (element) {
return { return {
event_url: event_url, event_url: event_url,
subevent: subevent, subevent: subevent,
is_button: false,
categories: null, categories: null,
currency: null, currency: null,
voucher_code: voucher, voucher_code: voucher,
@@ -787,7 +792,7 @@ var create_button = function (element) {
var itemsplit = raw_items.split(","); var itemsplit = raw_items.split(",");
var items = []; var items = [];
for (var i = 0; i < itemsplit.length; i++) { for (var i = 0; i < itemsplit.length; i++) {
if (itemsplit[i].indexOf("=")) { if (itemsplit[i].indexOf("=") > 0 ) {
var splitthis = itemsplit[i].split("="); var splitthis = itemsplit[i].split("=");
items.push({'item': splitthis[0], 'count': splitthis[1]}) items.push({'item': splitthis[0], 'count': splitthis[1]})
} }
@@ -799,6 +804,7 @@ var create_button = function (element) {
return { return {
event_url: event_url, event_url: event_url,
subevent: subevent, subevent: subevent,
is_button: true,
skip_ssl: skip_ssl, skip_ssl: skip_ssl,
voucher_code: voucher, voucher_code: voucher,
items: items, items: items,