Merge pull request #980 from johan12345/widget-default1

Widget: set default number to 1 if there is only one product
This commit is contained in:
Raphael Michel
2018-08-05 16:38:47 +02:00
committed by GitHub
3 changed files with 12 additions and 5 deletions

View File

@@ -195,7 +195,7 @@ class WidgetAPIProductList(View):
} for item in g
]
})
return grps, display_add_to_cart
return grps, display_add_to_cart, len(items)
def dispatch(self, request, *args, **kwargs):
self.subevent = None
@@ -274,11 +274,12 @@ class WidgetAPIProductList(View):
fail = True
if not fail and (ev.presale_is_running or request.event.settings.show_items_outside_presale_period):
data['items_by_category'], data['display_add_to_cart'] = self._get_items()
data['items_by_category'], data['display_add_to_cart'], data['itemnum'] = self._get_items()
data['display_add_to_cart'] = data['display_add_to_cart'] and ev.presale_is_running
else:
data['items_by_category'] = []
data['display_add_to_cart'] = False
data['itemnum'] = 0
vouchers_exist = self.request.event.get_cache().get('vouchers_exist')
if vouchers_exist is None:

View File

@@ -150,7 +150,8 @@ Vue.component('availbox', {
+ '<input type="checkbox" value="1" v-bind:name="input_name">'
+ '</label>'
+ '<input type="number" class="pretix-widget-item-count-multiple" placeholder="0" min="0"'
+ ' v-bind:max="order_max" v-bind:name="input_name" v-if="order_max !== 1">'
+ ' :value="($root.itemnum == 1 && !item.has_variations) ? 1 : false" v-bind:max="order_max" v-bind:name="input_name"'
+ ' v-if="order_max !== 1">'
+ '</div>'
+ '</div>'),
props: {
@@ -705,7 +706,8 @@ var create_widget = function (element) {
error_message: null,
error_url_after: null,
vouchers_exist: false,
cart_exists: false
cart_exists: false,
itemcount: 0
}
},
created: function () {
@@ -733,6 +735,7 @@ var create_widget = function (element) {
app.cart_id = cart_id;
app.cart_exists = data.cart_exists;
app.vouchers_exist = data.vouchers_exist;
app.itemnum = data.itemnum;
app.loading--;
}, function (error) {
app.categories = [];