[FIX] website_sale: checkout shipping address; remove url terminal slash

bzr revid: chm@openerp.com-20140410143524-zrrsh6zvvrg9ntgz
This commit is contained in:
chm@openerp.com 2014-04-10 16:35:24 +02:00
parent 0bae967baa
commit 81cfa028e5
4 changed files with 42 additions and 56 deletions

View File

@ -109,10 +109,10 @@ class website_sale(http.Controller):
pricelist = partner.property_product_pricelist
return pricelist
@http.route(['/shop/',
'/shop/page/<int:page>/',
'/shop/category/<model("product.public.category"):category>/',
'/shop/category/<model("product.public.category"):category>/page/<int:page>/'
@http.route(['/shop',
'/shop/page/<int:page>',
'/shop/category/<model("product.public.category"):category>',
'/shop/category/<model("product.public.category"):category>/page/<int:page>'
], type='http', auth="public", website=True, multilang=True)
def shop(self, page=0, category=None, search='', **post):
cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
@ -133,7 +133,7 @@ class website_sale(http.Controller):
context['pricelist'] = int(self.get_pricelist())
product_obj = pool.get('product.template')
product_count = product_obj.search_count(cr, uid, domain, context=context)
pager = request.website.pager(url="/shop/", total=product_count, page=page, step=PPG, scope=7, url_args=post)
pager = request.website.pager(url="/shop", total=product_count, page=page, step=PPG, scope=7, url_args=post)
product_ids = product_obj.search(cr, uid, domain, limit=PPG+10, offset=pager['offset'], order='website_published desc, website_sequence desc', context=context)
products = product_obj.browse(cr, uid, product_ids, context=context)
@ -169,7 +169,7 @@ class website_sale(http.Controller):
return request.website.render("website_sale.products", values)
@http.route(['/shop/product/<model("product.template"):product>/'], type='http', auth="public", website=True, multilang=True)
@http.route(['/shop/product/<model("product.template"):product>'], type='http', auth="public", website=True, multilang=True)
def product(self, product, category='', search='', **kwargs):
cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
category_obj = pool['product.public.category']
@ -253,7 +253,7 @@ class website_sale(http.Controller):
cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
# must have a draft sale order with lines at this point, otherwise reset
if order.state != 'draft':
if not order or order.state != 'draft':
request.website_sale_reset(cr, uid, context=context)
return request.redirect('/shop')
@ -326,7 +326,7 @@ class website_sale(http.Controller):
# set data
if isinstance(data, dict):
query = dict((field_name, data[field_name]) for field_name in all_fields if data.get(field_name))
query = dict((prefix + field_name, data[prefix + field_name]) for field_name in all_fields if data.get(prefix + field_name))
else:
query = dict((prefix + field_name, getattr(data, field_name))
for field_name in all_fields if field_name != "company" and getattr(data, field_name))
@ -351,6 +351,7 @@ class website_sale(http.Controller):
if data.get("shipping_different"):
for field_name in self.mandatory_shipping_fields:
field_name = 'shipping_' + field_name
if not data.get(field_name):
error[field_name] = 'missing'
@ -447,6 +448,7 @@ class website_sale(http.Controller):
return redirection
values = self.checkout_values(post)
values["error"] = self.checkout_form_validate(values["checkout"])
if values["error"]:
return request.website.render("website_sale.checkout", values)
@ -532,7 +534,7 @@ class website_sale(http.Controller):
order = request.website.sale_get_order(context=context)
if not order or not order.order_line or acquirer_id is None:
return request.redirect("/shop/checkout/")
return request.redirect("/shop/checkout")
# find an already existing transaction
tx = request.website.sale_get_transaction()
@ -627,7 +629,7 @@ class website_sale(http.Controller):
assert order.id == request.session.get('sale_last_order_id')
if not tx or not order:
return request.redirect('/shop/')
return request.redirect('/shop')
if not order.amount_total or tx.state == 'done':
# confirm the quotation
@ -644,9 +646,9 @@ class website_sale(http.Controller):
# clean context and session, then redirect to the confirmation page
request.website.sale_reset(context=context)
return request.redirect('/shop/confirmation/')
return request.redirect('/shop/confirmation')
@http.route(['/shop/confirmation/'], type='http', auth="public", website=True, multilang=True)
@http.route(['/shop/confirmation'], type='http', auth="public", website=True, multilang=True)
def payment_confirmation(self, **post):
""" End of checkout process controller. Confirmation is basically seing
the status of a sale.order. State at this point :
@ -661,7 +663,7 @@ class website_sale(http.Controller):
if sale_order_id:
order = request.registry['sale.order'].browse(cr, SUPERUSER_ID, sale_order_id, context=context)
else:
return request.redirect('/shop/')
return request.redirect('/shop')
return request.website.render("website_sale.confirmation", {'order': order})
@ -669,7 +671,7 @@ class website_sale(http.Controller):
# Edit
#------------------------------------------------------
@http.route(['/shop/add_product/'], type='http', auth="user", methods=['POST'], website=True, multilang=True)
@http.route(['/shop/add_product'], type='http', auth="user", methods=['POST'], website=True, multilang=True)
def add_product(self, name=None, category=0, **post):
cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
if not name:

View File

@ -124,10 +124,12 @@ class website(orm.Model):
self.pool['sale.order'].write(cr, SUPERUSER_ID, [sale_order_id], values, context=context)
request.session['sale_order_id'] = sale_order_id
if sale_order_id:
sale_order = self.pool['sale.order'].browse(cr, SUPERUSER_ID, sale_order_id, context=context)
if not sale_order.exists():
request.session['sale_order_id'] = None
return None
# TODO cache partner_id session
partner = self.pool['res.users'].browse(cr, SUPERUSER_ID, uid, context=context).partner_id
sale_order = self.pool['sale.order'].browse(cr, SUPERUSER_ID, sale_order_id, context=context)
# check for change of pricelist with a coupon
# TODO cache sale_order.pricelist_id.code in session
if code and code != sale_order.pricelist_id.code:

View File

@ -22,11 +22,11 @@
{
title: "click on add to cart",
waitFor: 'input[name="product_id"]:eq(1)[checked]',
element: 'form[action="/shop/add_cart/"] .btn',
element: 'form[action="/shop/add_cart"] .btn',
},
{
title: "add suggested",
element: 'form[action="/shop/add_cart/"] .btn-link:contains("Add to Cart")',
element: 'form[action="/shop/add_cart"] .btn-link:contains("Add to Cart")',
},
{
title: "add one more iPod",
@ -47,19 +47,19 @@
{
title: "go to checkout",
waitFor: '#mycart_products input.js_quantity[value=1]',
element: 'a[href="/shop/checkout/"]',
element: 'a[href="/shop/checkout"]',
},
{
title: "test with input error",
element: 'form[action="/shop/confirm_order/"] .btn:contains("Confirm")',
element: 'form[action="/shop/confirm_order"] .btn:contains("Confirm")',
onload: function (tour) {
$("input[name='phone']").val("");
},
},
{
title: "test without input error",
waitFor: 'form[action="/shop/confirm_order/"] .has-error',
element: 'form[action="/shop/confirm_order/"] .btn:contains("Confirm")',
waitFor: 'form[action="/shop/confirm_order"] .has-error',
element: 'form[action="/shop/confirm_order"] .btn:contains("Confirm")',
onload: function (tour) {
if ($("input[name='name']").val() === "")
$("input[name='name']").val("website_sale-test-shoptest");

View File

@ -21,7 +21,7 @@
<xpath expr="//header//ul[@id='top_menu']/li" position="before">
<t t-set="website_sale_order" t-value="website.sale_get_order()"/>
<li t-att-class="'' if website_sale_order and website_sale_order.cart_quantity else 'hidden'">
<a href="/shop/cart/">
<a href="/shop/cart">
<i class="fa fa-shopping-cart"></i>
My cart <sup t-attf-class="my_cart_quantity label label-primary" t-esc="website_sale_order and website_sale_order.cart_quantity or ''"/>
</a>
@ -46,7 +46,7 @@
<div class="container">
<h1 class="mt32">Product not found!</h1>
<p>Sorry, this product is not available anymore.</p>
<p><a t-attf-href="/shop/">Return to the product list.</a></p>
<p><a t-attf-href="/shop">Return to the product list.</a></p>
</div>
</div>
</div>
@ -87,8 +87,9 @@
<template id="products_description" inherit_option_id="website_sale.products_item" name="Product Description">
<xpath expr="//div[@class='product_price']" position="before">
<div class="text-info oe_subdescription oe_shadow" t-field="product.description_sale"/>
<div class="text-info oe_subdescription" t-field="product.description_sale"/>
<div class="text-info oe_subdescription" contenteditable="false">
<div itemprop="description" t-field="product.description_sale"></div>
</div>
</xpath>
</template>
@ -96,7 +97,7 @@
<xpath expr="//div[@class='product_price']" position="inside">
<form action="/shop/cart/update" method="post" style="display: inline-block;">
<input name="product_id" t-att-value="product.product_variant_ids[0].id" type="hidden"/>
<button type="submit" class="fa fa-shopping-cart"/>
<a class="btn btn-default btn-xs fa fa-shopping-cart a-submit"/>
</form>
</xpath>
</template>
@ -230,27 +231,8 @@
</t>
</template>
<!-- Product Description-->
<template id="product_description" inherit_option_id="website_sale.products_cart" name="Product Description">
<xpath expr="//div[@class='product_price']" position="before">
<div class="text-info oe_subdescription" contenteditable="false">
<div itemprop="description" t-field="product.description_sale"></div>
</div>
</xpath>
</template>
<!-- Add to cart button-->
<template id="add_to_basket" inherit_option_id="website_sale.products_cart" name="Add to Cart">
<xpath expr="//div[@class='product_price']" position="inside">
<form action="/shop/add_cart/" method="post" style="display: inline-block;">
<input name="product_id" t-att-value="product.product_variant_ids[0].id" type="hidden"/>
<a class="btn btn-default btn-xs fa fa-shopping-cart a-submit"/>
</form>
</xpath>
</template>
<template id="categories_recursive" name="Category list">
<li t-att-class="'active' if c.id == category else ''">
<a t-att-href="keep('/shop/category/' + slug(c), category=0)" t-field="c.name"></a>
@ -415,7 +397,7 @@
<div class='mt16 text-center'>
<span t-field="product.image_small" t-field-options='{"widget": "image", "class": "img-rounded shadow" }'/>
<h5>
<a t-attf-href="/shop/product/#{ slug(product) }/" style="display: block">
<a t-attf-href="/shop/product/#{ slug(product) }" style="display: block">
<span t-field='product.name' style="display: block"/>
</a>
</h5>
@ -538,7 +520,7 @@
</td>
<td t-if="line.product_id.product_tmpl_id">
<div>
<a t-attf-href="/shop/product/#{ slug(line.product_id.product_tmpl_id) }/">
<a t-attf-href="/shop/product/#{ slug(line.product_id.product_tmpl_id) }">
<strong t-field="line.name"/>
</a>
</div>
@ -579,7 +561,7 @@
</table>
<t t-call="website_sale.total"/>
<div class="clearfix"/>
<a t-if="website_sale_order and website_sale_order.website_order_line" href="/shop/checkout/" class="btn btn-primary pull-right mb32">Process Checkout <span class="fa fa-long-arrow-right"/></a>
<a t-if="website_sale_order and website_sale_order.website_order_line" href="/shop/checkout" class="btn btn-primary pull-right mb32">Process Checkout <span class="fa fa-long-arrow-right"/></a>
<div class="oe_structure"/>
</div>
<div class="col-lg-3 col-lg-offset-1 col-sm-3 col-md-3 text-muted" id="right_column">
@ -620,14 +602,14 @@
<tr t-foreach="suggested_products" t-as="product">
<td>
<a t-attf-href="/shop/product/#{ slug(product) }/">
<a t-attf-href="/shop/product/#{ slug(product) }">
<span t-field="product.image_small"
t-field-options='{"widget": "image", "class": "img-rounded"}'/>
</a>
</td>
<td>
<div>
<a t-attf-href="/shop/product/#{ slug(product) }/">
<a t-attf-href="/shop/product/#{ slug(product) }">
<strong t-field="product.name"/>
</a>
</div>
@ -659,7 +641,7 @@
</template>
<template id="continue_shopping" inherit_id="website_sale.cart" inherit_option_id="website_sale.cart" name="Continue Shopping Button">
<xpath expr="//a[@href='/shop/checkout/']" position="before">
<xpath expr="//a[@href='/shop/checkout']" position="before">
<a href="/shop" class="btn btn-default mb32"><span class="fa fa-long-arrow-left"/> Continue Shopping</a>
</xpath>
</template>
@ -670,7 +652,7 @@
<p>
Have a coupon code? Fill in this field and apply.
</p>
<form t-if="website_sale_order and website_sale_order.website_order_line" action="/shop/pricelist/" method="post" class="mb32">
<form t-if="website_sale_order and website_sale_order.website_order_line" action="/shop/pricelist" method="post" class="mb32">
<div class="input-group">
<input name="promo" class='form-control' type="text" placeholder="code..." t-att-value="website_sale_order.pricelist_id.code or ''"/>
<div class="input-group-btn">
@ -700,7 +682,7 @@
<li class="text-muted">Confirmation<span class="chevron"></span></li>
</ul>
<h1>Your Address</h1>
<form action="/shop/confirm_order/" method="post">
<form action="/shop/confirm_order" method="post">
<div class="row">
<div class="col-md-8 oe_cart">
@ -878,7 +860,7 @@
<tr t-foreach="website_sale_order.website_order_line" t-as="line">
<td colspan="2" t-if="not line.product_id.product_tmpl_id"></td>
<td t-if="line.product_id.product_tmpl_id">
<a t-attf-href="/shop/product/#{ slug(line.product_id.product_tmpl_id) }/">
<a t-attf-href="/shop/product/#{ slug(line.product_id.product_tmpl_id) }">
<span t-field="line.product_id.image_small"
t-field-options='{"widget": "image", "class": "img-rounded"}'/>
</a>
@ -953,7 +935,7 @@
</div>
<div class="js_payment mb64 row" t-if="not website_sale_order.amount_total" id="payment_method">
<div class="col-lg-8 col-sm-8">
<form target="_self" action="/shop/payment/validate/" method="post" class="pull-right">
<form target="_self" action="/shop/payment/validate" method="post" class="pull-right">
<a style="width:100px;" class="btn btn-primary a-submit">
<span>Pay Now <span class="fa fa-long-arrow-right"></span></span>
</a>