From 2903251c253b88e58cee2c12e1611c559af0caa5 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 13 Aug 2013 12:39:48 +0200 Subject: [PATCH] [IMP] website_sale: improve layout of my cart and checkout pages bzr revid: chm@openerp.com-20130813103948-fqg91t8nhg3szbn5 --- addons/website_sale/controllers/main.py | 55 ++- .../static/src/js/website_sale.js | 14 +- addons/website_sale/views/website_sale.xml | 352 +++++++++++------- addons/website_sale/website_sale.py | 1 + 4 files changed, 256 insertions(+), 166 deletions(-) diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index 3dddf428a15..d0818918ba1 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -111,7 +111,7 @@ class Ecommerce(http.Controller): }) return website.render("website_sale.mycart", values) - def add_product_to_cart(self, product_id=0, number=1): + def add_product_to_cart(self, product_id=0, number=1, set_number=-1): context = {} order_line_obj = request.registry.get('sale.order.line') @@ -127,7 +127,10 @@ class Ecommerce(http.Controller): order_line_ids = order_line_obj.search(request.cr, openerp.SUPERUSER_ID, [('order_id', '=', order.id), ('product_id', '=', product_id)], context=context) if order_line_ids: order_line = order_line_obj.read(request.cr, openerp.SUPERUSER_ID, order_line_ids, [], context=context)[0] - quantity = order_line['product_uom_qty'] + number + if set_number >= 0: + quantity = set_number + else: + quantity = order_line['product_uom_qty'] + number if quantity <= 0: order_line_obj.unlink(request.cr, openerp.SUPERUSER_ID, order_line_ids, context=context) else: @@ -153,30 +156,29 @@ class Ecommerce(http.Controller): return quantity @http.route(['/shop/add_cart//', '/shop//add_cart//'], type='http', auth="public") - def json_add_cart(self, path=None, product_id=0, remove=False): - self.add_product_to_cart(product_id, remove and -1 or 1) + def add_cart(self, path=None, product_id=0, remove=None): + self.add_product_to_cart(product_id, number=(remove and -1 or 1)) if path: return werkzeug.utils.redirect("/shop/%s/" % path) else: return werkzeug.utils.redirect("/shop/") @http.route(['/shop/remove_cart//', '/shop//remove_cart//'], type='http', auth="public") - def json_remove_cart(self, path=None, product_id=0, remove=False): - return self.json_add_cart(path=path, product_id=product_id, remove=True) + def remove_cart(self, path=None, product_id=0): + return self.add_cart(product_id=product_id, path=path, remove=True) - @http.route(['/shop/remove_cart/'], type='http', auth="public") - def remove_cart(self, product_id=0): - return self.add_cart(product_id=product_id, remove=True) + @http.route(['/shop/set_cart///', '/shop//set_cart///'], type='http', auth="public") + def set_cart(self, path=None, product_id=0, set_number=0): + self.add_product_to_cart(product_id, set_number=set_number) + if path: + return werkzeug.utils.redirect("/shop/%s/" % path) + else: + return werkzeug.utils.redirect("/shop/") @http.route(['/shop/checkout/'], type='http', auth="public") def checkout(self, **post): website = request.registry['website'] - values = website.get_rendering_context({ - 'partner': False, - 'checkout': request.session.setdefault('checkout', {}), - 'error': post.get("error") and dict.fromkeys(post.get("error").split(","), 1) or [] - }) order = get_current_order() if order.state != 'draft' or not order.order_line: @@ -187,12 +189,27 @@ class Ecommerce(http.Controller): country_obj = request.registry.get('res.country') country_state_obj = request.registry.get('res.country.state') + values = website.get_rendering_context({ + 'shipping': post.get("shipping"), + 'error': post.get("error") and dict.fromkeys(post.get("error").split(","), 'error') or {} + }) + + checkout = {} if request.uid != website.get_public_user().id: - values['partner'] = user_obj.browse(request.cr, request.uid, request.uid).partner_id - shipping_ids = partner_obj.search(request.cr, request.uid, [("parent_id", "=", values['partner'].id), ('type', "=", 'delivery')]) - values['shipping'] = None + partner = user_obj.browse(request.cr, request.uid, request.uid).partner_id + partner_id = partner.id + checkout = user_obj.read(request.cr, openerp.SUPERUSER_ID, [partner_id], [])[0] + checkout['company'] = partner.parent_id and partner.parent_id.name or '' + + shipping_ids = partner_obj.search(request.cr, request.uid, [("parent_id", "=", partner_id), ('type', "=", 'delivery')]) if shipping_ids: - values['shipping'] = partner_obj.browse(request.cr, request.uid, shipping_ids[0]) + for k,v in partner_obj.read(request.cr, request.uid, shipping_ids[0]).items(): + checkout['shipping_'+k] = v or '' + + checkout.update(request.session.setdefault('checkout', {})) + for k,v in checkout.items(): + checkout[k] = v or '' + values['checkout'] = checkout values['countries'] = country_obj.browse(request.cr, openerp.SUPERUSER_ID, country_obj.search(request.cr, openerp.SUPERUSER_ID, [(1, "=", 1)])) values['states'] = country_state_obj.browse(request.cr, openerp.SUPERUSER_ID, country_state_obj.search(request.cr, openerp.SUPERUSER_ID, [(1, "=", 1)])) @@ -223,7 +240,7 @@ class Ecommerce(http.Controller): if post.get('shipping_different') and key != 'email' and not post.get("shipping_%s" % key): error.append("shipping_%s" % key) if error: - return werkzeug.utils.redirect("/shop/checkout/?error=%s" % ",".join(error)) + return werkzeug.utils.redirect("/shop/checkout/?error=%s&shipping=%s" % (",".join(error), post.get('shipping_different') and 'on' or '')) # search or create company company_id = None diff --git a/addons/website_sale/static/src/js/website_sale.js b/addons/website_sale/static/src/js/website_sale.js index 548f190e674..8d686f3f356 100644 --- a/addons/website_sale/static/src/js/website_sale.js +++ b/addons/website_sale/static/src/js/website_sale.js @@ -1,5 +1,5 @@ $(document).ready(function () { - $('.oe_ecommerce').on('click', '.js_publish, .js_unpublish', function (e) { + $('.oe_website_sale').on('click', '.js_publish, .js_unpublish', function (e) { e.preventDefault(); var $link = $(this).parent(); $link.find('.js_publish, .js_unpublish').addClass("hidden"); @@ -17,9 +17,15 @@ $(document).ready(function () { }); - var $checkout = $(".oe_ecommerce .oe_checkout"); - $(".oe_ecommerce input[name='shipping_different']").change(function() { - $(".oe_ecommerce .js_shipping").toggle(); + $(".oe_website_sale input[name='shipping_different']").change(function() { + $(".oe_website_sale .js_shipping").toggle(); }); + $(".oe_website_sale .oe_mycart input").change(function() { + var value = parseInt($(this).val()); + if (!isNaN(value)) { + window.location.href = window.location.origin + window.location.pathname + 'set_cart/' + $(this).data('id') + '/' + value + '/'; + } + }); + }); diff --git a/addons/website_sale/views/website_sale.xml b/addons/website_sale/views/website_sale.xml index ee3bf27587d..0ae2dfae3b7 100644 --- a/addons/website_sale/views/website_sale.xml +++ b/addons/website_sale/views/website_sale.xml @@ -51,7 +51,7 @@ Shop - Categories -
+
-
€
+
€
@@ -180,44 +180,45 @@

My Shopping Cart

-

Your cart is empty

- +
- + + + + + + - + + + + - - - - - - - - + + +
ProductQty.Price
ProductPriceQuantity

Your cart is empty

- + - +
+
€
- + - +
- -
Subtotal €
Taxes €

Total

€

Subtotal €
Taxes €

Total

€