From 4fc8193e463c0ff8ad984ac4f490176618b1ba4d Mon Sep 17 00:00:00 2001 From: ddm Date: Fri, 23 Aug 2013 11:24:56 +0200 Subject: [PATCH 1/5] CSS improvements bzr revid: ddm@openerp.com-20130823092456-7g783rh2g0irlp63 --- addons/website/static/src/css/editor.css | 17 +++++++++++++---- addons/website/static/src/css/editor.sass | 17 +++++++++++++---- addons/website/static/src/xml/website.xml | 6 +++--- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/addons/website/static/src/css/editor.css b/addons/website/static/src/css/editor.css index e8e69a3a9ca..bd68855d6ed 100644 --- a/addons/website/static/src/css/editor.css +++ b/addons/website/static/src/css/editor.css @@ -156,6 +156,7 @@ background-color: black; border: 2px solid; border-radius: 10px; + border-color: #1a1a1a; margin: auto; position: absolute; top: 0; @@ -164,17 +165,24 @@ right: 0; max-width: 330px; } - -#mobile-preview .modal-header { +#mobile-preview.modal .modal-header { + background-color: black; border-bottom: 0; border-top-left-radius: 10px; border-top-right-radius: 10px; } -#mobile-preview .modal-body { +#mobile-preview.modal .modal-header .oe_mobile_preview_title { + color: #1a1a1a; +} +#mobile-preview.modal .modal-body { + background-color: black; max-height: 600px; padding: 0; margin: 0; } +#mobile-preview.modal .modal-footer { + background-color: black; +} .oe_mobile_viewport { width: 320px; @@ -188,5 +196,6 @@ opacity: 1; } .oe_mobile_preview_header .close:hover { - color: darkgrey; + color: #e00101; + opacity: 1; } diff --git a/addons/website/static/src/css/editor.sass b/addons/website/static/src/css/editor.sass index f324cabc348..7ed368aca47 100644 --- a/addons/website/static/src/css/editor.sass +++ b/addons/website/static/src/css/editor.sass @@ -132,11 +132,15 @@ height: 100% overflow: hidden +$mobile_preview_background: #000000 +$mobile_preview_border: #1A1A1A +$mobile_preview_close: #E00101 #mobile-preview.modal height: 660px - background-color: black + background-color: $mobile_preview_background border: 2px solid border-radius: 10px + border-color: $mobile_preview_border margin: auto position: absolute top: 0 @@ -144,16 +148,20 @@ bottom: 0 right: 0 max-width: 330px - -#mobile-preview .modal-header + background-color: $mobile_preview_background border-bottom: 0 border-top-left-radius: 10px border-top-right-radius: 10px + .oe_mobile_preview_title + color: $mobile_preview_border .modal-body + background-color: $mobile_preview_background max-height: 600px padding: 0 margin: 0 + .modal-footer + background-color: $mobile_preview_background .oe_mobile_viewport width: 320px @@ -166,4 +174,5 @@ color: lightgrey opacity: 1 .close:hover - color: darkgrey + color: $mobile_preview_close + opacity: 1 diff --git a/addons/website/static/src/xml/website.xml b/addons/website/static/src/xml/website.xml index 04868b16ebe..f24498c5568 100644 --- a/addons/website/static/src/xml/website.xml +++ b/addons/website/static/src/xml/website.xml @@ -40,12 +40,12 @@ From 651e511ed9952541799a09c38c9a37a438a34936 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 23 Aug 2013 11:40:17 +0200 Subject: [PATCH 2/5] [IMP] website_sale: fix context value, get order line name insead of product name, wip payment bzr revid: chm@openerp.com-20130823094017-90m72xi2oif4qkuj --- addons/website_sale/controllers/main.py | 98 ++++++++++++------- .../static/src/js/website_sale.js | 10 +- addons/website_sale/views/website_sale.xml | 52 ++++++---- 3 files changed, 104 insertions(+), 56 deletions(-) diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index 79cef4ec07f..790eee534bf 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -27,16 +27,14 @@ def get_order(order_id=None): context = { 'pricelist': order.pricelist_id.id, - 'partner': order.partner_id.id, } return order_obj.browse(request.cr, SUPERUSER_ID, order_id, context=context) def get_current_order(): - order = get_order(request.httprequest.session.get('ecommerce_order_id')) - if order.state != 'draft': - order = get_order() - request.httprequest.session['ecommerce_order_id'] = order.id - return order + if request.httprequest.session.get('ecommerce_order_id'): + return get_order(request.httprequest.session.get('ecommerce_order_id')) + else: + return False class website(osv.osv): _inherit = "website" @@ -60,6 +58,9 @@ class Ecommerce(http.Controller): @http.route(['/shop/', '/shop/category//', '/shop/category//page//', '/shop/page//'], type='http', auth="public") def category(self, cat_id=0, page=0, **post): + if 'promo' in post: + self.change_pricelist(post.get('code')) + website = request.registry['website'] product_obj = request.registry.get('product.template') @@ -81,12 +82,14 @@ class Ecommerce(http.Controller): product_count = len(product_obj.search(request.cr, request.uid, domain)) pager = website.pager(url="/shop/category/%s/" % cat_id, total=product_count, page=page, step=step, scope=7, url_args=post) - product_ids = product_obj.search(request.cr, request.uid, domain, limit=step, offset=pager['offset'], order="website_published,name") + product_ids = product_obj.search(request.cr, request.uid, domain, limit=step, offset=pager['offset']) + + context = request.httprequest.session.get('ecommerce_context', {}) values = website.get_rendering_context({ 'categories': self.get_categories(), 'category_id': cat_id, - 'products': product_obj.browse(request.cr, request.uid, product_ids), + 'products': product_obj.browse(request.cr, request.uid, product_ids, context=context), 'search': post.get("search"), 'pager': pager, }) @@ -94,12 +97,16 @@ class Ecommerce(http.Controller): @http.route(['/shop/product//'], type='http', auth="public") def product(self, cat_id=0, product_id=0, **post): + + if 'promo' in post: + self.change_pricelist(post.get('code')) + website = request.registry['website'] product_id = product_id and int(product_id) or 0 product_obj = request.registry.get('product.template') - context = get_current_order()._context + context = request.httprequest.session.get('ecommerce_context', {}) product = product_obj.browse(request.cr, request.uid, product_id, context=context) values = website.get_rendering_context({ @@ -110,17 +117,33 @@ class Ecommerce(http.Controller): }) return website.render("website_sale.product", values) + def change_pricelist(self, code): + request.httprequest.session.setdefault('ecommerce_context', {}) + + order = get_current_order() + if order: + pricelist_obj = request.registry.get('product.pricelist') + pricelist_ids = pricelist_obj.search(request.cr, SUPERUSER_ID, [('code', '=', code)]) + if pricelist_ids: + pricelist_id = pricelist_ids[0] + else: + pricelist_id = order.onchange_partner_id(request.uid, context={})['value']['pricelist_id'] + + request.httprequest.session['ecommerce_context']['pricelist'] = pricelist_id + values = {'pricelist_id': pricelist_id} + values.update(order.onchange_pricelist_id(pricelist_id, None)['value']) + order.write(values) + for line in order.order_line: + self.add_product_to_cart(line.product_id.id, 0) + @http.route(['/shop/mycart/'], type='http', auth="public") def mycart(self, **post): order = get_current_order() website = request.registry['website'] prod_obj = request.registry.get('product.product') - if post.get('code'): - pricelist_obj = request.registry.get('product.pricelist') - pricelist_ids = pricelist_obj.search(request.cr, SUPERUSER_ID, [('code', '=', post.get('code'))]) - if pricelist_ids: - order.write({'pricelist_id': pricelist_ids[0]}) + if 'promo' in post: + self.change_pricelist(post.get('promo')) suggested_ids = [] for line in order.order_line: @@ -139,13 +162,16 @@ class Ecommerce(http.Controller): return website.render("website_sale.mycart", values) def add_product_to_cart(self, product_id=0, number=1, set_number=-1): - context = {} + context = request.httprequest.session.get('ecommerce_context', {}) order_line_obj = request.registry.get('sale.order.line') user_obj = request.registry.get('res.users') product_id = product_id and int(product_id) or 0 order = get_current_order() + if not order: + order = get_order() + request.httprequest.session['ecommerce_order_id'] = order.id quantity = 0 @@ -158,27 +184,32 @@ class Ecommerce(http.Controller): quantity = set_number else: quantity = order_line['product_uom_qty'] + number - if quantity <= 0: - order_line_obj.unlink(request.cr, SUPERUSER_ID, order_line_ids, context=context) + if quantity < 0: + quantity = 0 else: fields = [k for k, v in order_line_obj._columns.items()] values = order_line_obj.default_get(request.cr, SUPERUSER_ID, fields, context=context) quantity = 1 + values['product_uom_qty'] = quantity values['product_id'] = product_id values['order_id'] = order.id # change and record value - if quantity > 0: - pricelist_id = order.pricelist_id and order.pricelist_id.id or False - values.update(order_line_obj.product_id_change(request.cr, SUPERUSER_ID, [], pricelist_id, product_id, - partner_id=user_obj.browse(request.cr, SUPERUSER_ID, request.uid).partner_id.id, - context=context)['value']) - if order_line_ids: - order_line_obj.write(request.cr, SUPERUSER_ID, order_line_ids, values, context=context) - else: - order_line_id = order_line_obj.create(request.cr, SUPERUSER_ID, values, context=context) - order.write({'order_line': [(4, order_line_id)]}, context=context) + pricelist_id = order.pricelist_id and order.pricelist_id.id or False + + vals = order_line_obj.product_id_change(request.cr, SUPERUSER_ID, [], pricelist_id, product_id, + partner_id=user_obj.browse(request.cr, SUPERUSER_ID, request.uid).partner_id.id, + context=context)['value'] + + values.update(vals) + if order_line_ids: + order_line_obj.write(request.cr, SUPERUSER_ID, order_line_ids, values, context=context) + if not quantity: + order_line_obj.unlink(request.cr, SUPERUSER_ID, order_line_ids, context=context) + else: + order_line_id = order_line_obj.create(request.cr, SUPERUSER_ID, values, context=context) + order.write({'order_line': [(4, order_line_id)]}, context=context) return quantity @@ -319,7 +350,6 @@ class Ecommerce(http.Controller): shipping_id = partner_obj.create(request.cr, SUPERUSER_ID, shipping_value) order_value = { - 'state': 'progress', 'partner_id': partner_id, 'partner_invoice_id': partner_id, 'partner_shipping_id': shipping_id or partner_id @@ -327,17 +357,14 @@ class Ecommerce(http.Controller): order_value.update(request.registry.get('sale.order').onchange_partner_id(request.cr, SUPERUSER_ID, [], request.uid, context={})['value']) order.write(order_value) - request.httprequest.session['ecommerce_order_id_old'] = order.id - request.httprequest.session['ecommerce_order_id'] = None - return werkzeug.utils.redirect("/shop/payment/") @http.route(['/shop/payment/'], type='http', auth="public") def payment(self, **post): website = request.registry['website'] - order = get_order(request.httprequest.session.get('ecommerce_order_id_old')) + order = get_current_order() - if order.state != 'progress': + if not order or not order.order_line: return self.mycart(**post) values = website.get_rendering_context({ @@ -354,4 +381,9 @@ class Ecommerce(http.Controller): return website.render("website_sale.payment", values) + @http.route(['/shop/payment_validate/'], type='http', auth="public") + def payment_validate(self, **post): + request.httprequest.session['ecommerce_order_id'] = False + return werkzeug.utils.redirect("/shop/") + # vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/website_sale/static/src/js/website_sale.js b/addons/website_sale/static/src/js/website_sale.js index 6d72a829b1d..e79b6a4341c 100644 --- a/addons/website_sale/static/src/js/website_sale.js +++ b/addons/website_sale/static/src/js/website_sale.js @@ -1,13 +1,19 @@ $(document).ready(function () { - $(".oe_website_sale input[name='shipping_different']").change(function() { + $(".oe_website_sale input[name='shipping_different']").change(function () { $(".oe_website_sale .js_shipping").toggle(); }); - $(".oe_website_sale .oe_mycart input.js_quantity").change(function() { + $(".oe_website_sale .oe_mycart input.js_quantity").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 + '/'; } }); + $payment = $(".oe_website_sale .js_payment"); + $("input[name='payment_type']", $payment).click(function (ev) { + var payment_id = $(ev.target).val(); + $("div[data-id]", $payment).addClass("hidden"); + $("a.btn:last, div[data-id='"+payment_id+"']", $payment).removeClass("hidden"); + }); }); diff --git a/addons/website_sale/views/website_sale.xml b/addons/website_sale/views/website_sale.xml index 107a6517c58..b861b009bd7 100644 --- a/addons/website_sale/views/website_sale.xml +++ b/addons/website_sale/views/website_sale.xml @@ -22,7 +22,7 @@ My cart - + @@ -116,9 +116,14 @@
-
€
+
+ + € + + € +
@@ -196,7 +201,7 @@

My Shopping Cart

- +
@@ -220,16 +225,14 @@ - - -
- - () -
+
- + € - € + €
@@ -253,12 +256,9 @@
Subtotal €
Taxes €

Total

€

Proceed To Payment
- + Proceed To Payment
@@ -319,7 +319,7 @@