diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index 9f0005908ad..a3c686a2724 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -90,6 +90,7 @@ class QueryURL(object): for k,v in kw.items(): if v: if isinstance(v, list) or isinstance(v, set): + print k, v l.append(werkzeug.url_encode([(k,i) for i in v])) else: l.append(werkzeug.url_encode([(k,v)])) @@ -126,6 +127,8 @@ class website_sale(http.Controller): domain += [('product_variant_ids.public_categ_ids', 'child_of', int(category))] attrib_values = [map(int,v.split(",")) for v in request.httprequest.args.getlist('attrib') if v] + attrib_set = set([v[1] for v in attrib_values]) + if attrib_values: attrib = None ids = [] @@ -142,8 +145,8 @@ class website_sale(http.Controller): if attrib: domain += [('attribute_line_ids.value_ids', 'in', ids)] - attrib_set = set([v[1] for v in attrib_values]) - keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_set) + attrib_query = set(["%s,%s" % (v[0],v[1]) for v in attrib_values]) + keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_query) if not context.get('pricelist'): context['pricelist'] = int(self.get_pricelist()) @@ -201,7 +204,8 @@ class website_sale(http.Controller): attrib_values = [map(int,v.split(",")) for v in request.httprequest.args.getlist('attrib') if v] attrib_set = set([v[1] for v in attrib_values]) - keep = QueryURL('/shop', category=category and category.id, search=search, attrib=attrib_set) + attrib_query = set(["%s,%s" % (v[0],v[1]) for v in attrib_values]) + keep = QueryURL('/shop', category=category and category.id, search=search, attrib=attrib_query) category_ids = category_obj.search(cr, uid, [], context=context) category_list = category_obj.name_get(cr, uid, category_ids, context=context) @@ -260,12 +264,25 @@ class website_sale(http.Controller): return request.website.render("website_sale.cart", values) @http.route(['/shop/cart/update'], type='http', auth="public", methods=['POST'], website=True) - def cart_update(self, product_id, add_qty=1, set_qty=0, **kw): + def cart_update(self, product_id, add_qty=1, set_qty=0, goto_shop=None, **kw): cr, uid, context, pool = request.cr, request.uid, request.context, request.registry order = request.website.sale_get_order(force_create=1) if add_qty or set_qty: order._cart_update(product_id=int(product_id), add_qty=int(add_qty), set_qty=int(set_qty)) - return request.redirect("/shop/cart") + if goto_shop: + path = "/shop" + l = list() + for k,v in kw.items(): + if v and k in ["category", "search", "attrib"]: + if isinstance(v, list) or isinstance(v, set): + l.append(werkzeug.url_encode([(k,i) for i in v])) + else: + l.append(werkzeug.url_encode([(k,v)])) + if l: + path += '?' + '&'.join(l) + return request.redirect(path) + else: + return request.redirect("/shop/cart") @http.route(['/shop/cart/update_json'], type='json', auth="public", methods=['POST'], website=True) def cart_update_json(self, product_id, line_id, add_qty=None, set_qty=None, display=True): diff --git a/addons/website_sale/static/src/css/website_sale.css b/addons/website_sale/static/src/css/website_sale.css index 232872fa19f..cff966fed88 100644 --- a/addons/website_sale/static/src/css/website_sale.css +++ b/addons/website_sale/static/src/css/website_sale.css @@ -302,16 +302,13 @@ display: none; } -.css_not_available .row > div:nth-child(3), .css_not_available .row > div:nth-child(4) { +.css_not_available.js_product > *:nth-child(3) > *, .css_not_available.js_product *:nth-child(4) > * { display: none; } -.css_not_available .row > div:last-child { - display: block; -} -.css_not_available .product_price { +.css_not_available.js_product .product_price { display: none; } -.css_not_available .css_not_available_msg { +.css_not_available.js_product .css_not_available_msg { display: block; } diff --git a/addons/website_sale/static/src/css/website_sale.sass b/addons/website_sale/static/src/css/website_sale.sass index bb6a329a821..09bcbad36e8 100644 --- a/addons/website_sale/static/src/css/website_sale.sass +++ b/addons/website_sale/static/src/css/website_sale.sass @@ -259,12 +259,9 @@ .css_not_available_msg display: none -.css_not_available - .row - > div:nth-child(3), > div:nth-child(4) - display: none - > div:last-child - display: block +.css_not_available.js_product + > *:nth-child(3) > *, *:nth-child(4) > * + display: none .product_price display: none .css_not_available_msg diff --git a/addons/website_sale/static/src/js/website_sale.js b/addons/website_sale/static/src/js/website_sale.js index 149b54d7c8e..978ee10cab9 100644 --- a/addons/website_sale/static/src/js/website_sale.js +++ b/addons/website_sale/static/src/js/website_sale.js @@ -123,24 +123,39 @@ $(document).ready(function () { $('input.js_variant_change, select.js_variant_change', this).first().trigger('change'); }); + + $("a.js_add, a.js_remove").click(function (event) { + event.preventDefault(); + var $parent = $(this).parents('.js_product:first'); + $parent.find("a.js_add, span.js_remove").toggleClass("hidden"); + $parent.find("input.js_optional_same_quantity").val( $(this).hasClass("js_add") ? 1 : 0 ); + }); + $('#product_detail form[action^="/shop/cart/update"] .a-submit').off("click").click(function (event) { event.preventDefault(); var $link = $(this); var $form = $link.parents("form:first"); + var quantity = parseInt($('input[name="add_qty"]').val() || 1, 10); var defs = []; $link.attr('disabled', 'disabled'); $('.js_product', $form).each(function () { var product_id = parseInt($('input.optional_product_id', this).val(),10); - var quantity = parseInt($('input.js_quantity', this).val(),10); - if (product_id && quantity) { + var qty = parseInt($('input.js_quantity', this).val(),10); + if($('input.js_optional_same_quantity', this).val() !== '0') { + qty = quantity; + } + if (product_id && qty) { defs.push(openerp.jsonRpc("/shop/cart/update_json", 'call', { 'line_id': null, 'product_id': product_id, - 'add_qty': quantity, + 'add_qty': qty, 'display': false})); } }); $.when.apply($.when, defs).then(function () { + if ($link.hasClass("js_goto_shop")) { + $form.prepend(''); + } $form.submit(); }); return false; diff --git a/addons/website_sale/views/templates.xml b/addons/website_sale/views/templates.xml index 1483482f7b8..4a1a2f4c649 100644 --- a/addons/website_sale/views/templates.xml +++ b/addons/website_sale/views/templates.xml @@ -373,28 +373,147 @@

Product Name