from openerp.addons.web import http
from openerp.addons.web.http import request
from openerp.tools.translate import _
+from openerp.addons.website.models.website import slug
PPG = 20 # Products Per Page
PPR = 4 # Products Per Row
index = 0
maxy = 0
for p in products:
- x = p.website_size_x
- y = p.website_size_y
+ x = min(max(p.website_size_x, 1), PPR)
+ y = min(max(p.website_size_y, 1), PPR)
if index>PPG:
x = y = 1
self.table[(pos/PPR)+y2][(pos%PPR)+x2] = False
self.table[pos/PPR][pos%PPR] = {
'product': p, 'x':x, 'y': y,
- 'class': " ".join(map(lambda x: x.html_class, p.website_style_ids))
+ 'class': " ".join(map(lambda x: x.html_class or '', p.website_style_ids))
}
if index<=PPG:
maxy=max(maxy,y+(pos/PPR))
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>/'
- ], type='http', auth="public", website=True, multilang=True)
+ @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)
def shop(self, page=0, category=None, search='', **post):
cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
domain = request.website.sale_product_domain()
if search:
- domain += ['|', ('name', 'ilike', search), ('description', 'ilike', search)]
+ domain += ['|', '|', '|', ('name', 'ilike', search), ('description', 'ilike', search),
+ ('description_sale', 'ilike', search), ('product_variant_ids.default_code', 'ilike', search)]
if category:
- domain += [('product_variant_ids.public_categ_id', 'child_of', int(category))]
+ domain += [('product_variant_ids.public_categ_ids', 'child_of', int(category))]
- attrib_values = map(int,request.httprequest.args.getlist('attrib'))
+ attrib_values = [map(int,v.split(",")) for v in request.httprequest.args.getlist('attrib') if v]
if attrib_values:
- domain += [('attribute_lines.value_id', 'in', attrib_values)]
- attrib_set = set(attrib_values)
+ attrib = None
+ ids = []
+ for value in attrib_values:
+ if not attrib:
+ attrib = value[0]
+ ids.append(value[1])
+ elif value[0] == attrib:
+ ids.append(value[1])
+ else:
+ domain += [('attribute_line_ids.value_ids', 'in', ids)]
+ attrib = value[0]
+ ids = [value[1]]
+ 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)
if not context.get('pricelist'):
context['pricelist'] = int(self.get_pricelist())
product_obj = pool.get('product.template')
+
+ url = "/shop"
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)
+ if search:
+ post["search"] = search
+ if category:
+ url = "/shop/category/%s" % slug(category)
+ pager = request.website.pager(url=url, 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)
values = {
'search': search,
- 'category': category and int(category),
+ 'category': category,
+ 'attrib_values': attrib_values,
'attrib_set': attrib_set,
'pager': pager,
'pricelist': self.get_pricelist(),
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)
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']
+ context.update(active_id=product.id)
+
if category:
category = category_obj.browse(request.cr, request.uid, int(category), context=request.context)
- attrib_values = map(int,request.httprequest.args.getlist('attrib'))
- attrib_set = set(attrib_values)
+ 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)
context['pricelist'] = int(self.get_pricelist())
product = request.registry.get('product.template').browse(request.cr, request.uid, int(product), context=context)
+ variants = [[p.id, map(int, p.attribute_value_ids), p.price] for p in product.product_variant_ids]
+
values = {
'search': search,
'category': category,
'pricelist': self.get_pricelist(),
+ 'attrib_values': attrib_values,
'attrib_set': attrib_set,
'keep': keep,
'category_list': category_list,
'main_object': product,
'product': product,
+ 'variants': variants,
}
return request.website.render("website_sale.product", values)
context=dict(context, mail_create_nosubcribe=True))
return werkzeug.utils.redirect(request.httprequest.referrer + "#comments")
- @http.route(['/shop/cart'], type='http', auth="public", website=True, multilang=True)
+ @http.route(['/shop/pricelist'], type='http', auth="public", website=True)
+ def pricelist(self, promo, **post):
+ cr, uid, context = request.cr, request.uid, request.context
+ request.website.sale_get_order(code=promo, context=context)
+ return request.redirect("/shop/cart")
+
+ @http.route(['/shop/cart'], type='http', auth="public", website=True)
def cart(self, **post):
order = request.website.sale_get_order()
values = {
values['suggested_products'] = order._cart_accessories(context=request.context)
return request.website.render("website_sale.cart", values)
- @http.route(['/shop/cart/update'], type='http', auth="public", methods=['POST'], website=True, multilang=True)
- def cart_update(self, product_id, add_qty=0, set_qty=0, **kw):
+ @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):
cr, uid, context = request.cr, request.uid, request.context
request.website.sale_get_order(force_create=1)._cart_update(product_id=int(product_id), add_qty=add_qty, set_qty=set_qty)
return request.redirect("/shop/cart")
- @http.route(['/shop/cart/update_json'], type='json', auth="public", methods=['POST'], website=True, multilang=True)
- def cart_update_json(self, product_id, add_qty=None, set_qty=None):
+ @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):
order = request.website.sale_get_order(force_create=1)
- quantity = order._cart_update(product_id=product_id, add_qty=add_qty, set_qty=set_qty)
+ quantity = order._cart_update(product_id=product_id, line_id=line_id, add_qty=add_qty, set_qty=set_qty)
return {
'quantity': quantity,
'cart_quantity': order.cart_quantity,
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':
- request.website_sale_reset(cr, uid, context=context)
+ if not order or order.state != 'draft':
+ request.session['sale_order_id'] = None
+ request.session['sale_transaction_id'] = None
return request.redirect('/shop')
# if transaction pending / done: redirect to confirmation
countries = orm_country.browse(cr, SUPERUSER_ID, country_ids, context)
states_ids = state_orm.search(cr, SUPERUSER_ID, [], context=context)
states = state_orm.browse(cr, SUPERUSER_ID, states_ids, context)
+ partner = orm_user.browse(cr, SUPERUSER_ID, request.uid, context).partner_id
+ order = None
+
+ shipping_id = None
+ shipping_ids = []
checkout = {}
if not data:
if request.uid != request.website.user_id.id:
- partner = orm_user.browse(cr, SUPERUSER_ID, request.uid, context).partner_id
checkout.update( self.checkout_parse("billing", partner) )
-
- shipping_ids = orm_partner.search(cr, SUPERUSER_ID, [("parent_id", "=", partner.id), ('type', "=", 'delivery')], limit=1, context=context)
- if shipping_ids:
- shipping = orm_user.browse(cr, SUPERUSER_ID, request.uid, context)
- checkout.update( self.checkout_parse("shipping", shipping) )
- checkout['shipping_different'] = True
+ shipping_ids = orm_partner.search(cr, SUPERUSER_ID, [("parent_id", "=", partner.id), ('type', "=", 'delivery')], context=context)
else:
order = request.website.sale_get_order(force_create=1, context=context)
if order.partner_id:
checkout.update( self.checkout_parse("billing", order.partner_id) )
else:
checkout = self.checkout_parse('billing', data)
- if data.get("shipping_different"):
+ try:
+ shipping_id = int(data["shipping_id"])
+ except ValueError:
+ pass
+ if shipping_id == -1:
checkout.update(self.checkout_parse('shipping', data))
- checkout["shipping_different"] = True
+
+ if shipping_id is None:
+ if not order:
+ order = request.website.sale_get_order(context=context)
+ if order and order.partner_shipping_id:
+ shipping_id = order.partner_shipping_id.id
+
+ shipping_ids = list(set(shipping_ids) - set([partner.id]))
+
+ if shipping_id == partner.id:
+ shipping_id = 0
+ elif shipping_id > 0 and shipping_id not in shipping_ids:
+ shipping_ids.append(shipping_id)
+ elif shipping_id is None and shipping_ids:
+ shipping_id = shipping_ids[0]
+
+ ctx = dict(context, show_address=1)
+ shippings = []
+ if shipping_ids:
+ shippings = shipping_ids and orm_partner.browse(cr, SUPERUSER_ID, list(shipping_ids), ctx) or []
+ if shipping_id > 0:
+ shipping = orm_partner.browse(cr, SUPERUSER_ID, shipping_id, ctx)
+ checkout.update( self.checkout_parse("shipping", shipping) )
+
+ checkout['shipping_id'] = shipping_id
values = {
'countries': countries,
'states': states,
'checkout': checkout,
- 'shipping_different': checkout.get('shipping_different'),
+ 'shipping_id': partner.id != shipping_id and shipping_id or 0,
+ 'shippings': shippings,
'error': {},
}
+
return values
mandatory_billing_fields = ["name", "phone", "email", "street", "city", "country_id", "zip"]
- optional_billing_fields = ["company", "state_id"]
+ optional_billing_fields = ["street2", "state_id", "vat"]
mandatory_shipping_fields = ["name", "phone", "street", "city", "country_id", "zip"]
optional_shipping_fields = ["state_id"]
- def checkout_parse(self, address_type, data):
+ def checkout_parse(self, address_type, data, remove_prefix=False):
""" data is a dict OR a partner browse record
"""
# set mandatory and optional fields
# 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))
+ for field_name in all_fields if field_name != "street2" and getattr(data, field_name))
if data.parent_id:
- query[prefix + 'company'] = data.parent_id.name
+ query[prefix + 'street2'] = data.parent_id.name
if query.get(prefix + 'state_id'):
query[prefix + 'state_id'] = int(query[prefix + 'state_id'])
if query.get(prefix + 'country_id'):
query[prefix + 'country_id'] = int(query[prefix + 'country_id'])
- return query
+ if not remove_prefix:
+ return query
+
+ return dict((field_name, data[prefix + field_name]) for field_name in all_fields if data.get(prefix + field_name))
def checkout_form_validate(self, data):
cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
if not data.get(field_name):
error[field_name] = 'missing'
- if data.get("shipping_different"):
+ if data.get("vat") and hasattr(registry["res.partner"], "check_vat"):
+ if request.website.company_id.vat_check_vies:
+ # force full VIES online check
+ check_func = registry["res.partner"].vies_vat_check
+ else:
+ # quick and partial off-line checksum validation
+ check_func = registry["res.partner"].simple_vat_check
+ vat_country, vat_number = registry["res.partner"]._split_vat(data.get("vat"))
+ if not check_func(cr, uid, vat_country, vat_number, context=None): # simple_vat_check
+ error["vat"] = 'error'
+
+ if data.get("shipping_id") == -1:
for field_name in self.mandatory_shipping_fields:
+ field_name = 'shipping_' + field_name
if not data.get(field_name):
error[field_name] = 'missing'
return error
- def checkout_form_save(self, post):
+ def checkout_form_save(self, checkout):
cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
order = request.website.sale_get_order(force_create=1, context=context)
orm_partner = registry.get('res.partner')
orm_user = registry.get('res.users')
- order_line_obj = request.registry.get('sale.order')
-
- billing_info = self.checkout_parse('billing', post)
-
- # save partner for order
- company_id = None
- if billing_info.get('company'):
- company_name = billing_info['company']
- company_ids = orm_partner.search(cr, SUPERUSER_ID, [("name", "ilike", company_name), ('is_company', '=', True)], context=context)
- company_id = (company_ids and company_ids[0]) or orm_partner.create(cr, SUPERUSER_ID, {'name': company_name, 'is_company': True}, context)
+ order_obj = request.registry.get('sale.order')
- billing_info['parent_id'] = company_id
+ billing_info = self.checkout_parse('billing', checkout, True)
# set partner_id
partner_id = None
if request.uid != request.website.user_id.id:
partner_id = orm_user.browse(cr, SUPERUSER_ID, uid, context=context).partner_id.id
elif order.partner_id:
- domain = [("active", "=", False), ("partner_id", "=", order.partner_id.id)]
- user_ids = request.registry['res.users'].search(cr, SUPERUSER_ID, domain, context=context)
+ user_ids = request.registry['res.users'].search(cr, SUPERUSER_ID,
+ [("partner_id", "=", order.partner_id.id)], context=dict(context or {}, active_test=False))
if not user_ids or request.website.user_id.id not in user_ids:
partner_id = order.partner_id.id
# save partner informations
- if partner_id:
+ if partner_id and request.website.partner_id.id != partner_id:
orm_partner.write(cr, SUPERUSER_ID, [partner_id], billing_info, context=context)
else:
partner_id = orm_partner.create(cr, SUPERUSER_ID, billing_info, context=context)
- # set shipping_id
- shipping_id = None
- if post.get('shipping_different'):
- shipping_info = self.checkout_parse('shipping', post)
- shipping_info = dict ((field_name, shipping_info[field_name]) for field_name in shipping_info.items())
+ # create a new shipping partner
+ if checkout.get('shipping_id') == -1:
+ shipping_info = self.checkout_parse('shipping', checkout, True)
shipping_info['type'] = 'delivery'
shipping_info['parent_id'] = partner_id
-
- domain = [(key, '_id' in key and '=' or 'ilike', value)
- for key, value in shipping_info.items() if key in self.mandatory_shipping_fields + ["type", "parent_id"]]
- shipping_ids = orm_partner.search(cr, SUPERUSER_ID, domain, context=context)
-
- # save shipping informations
- if shipping_ids:
- shipping_id = shipping_ids[0]
- orm_partner.write(cr, SUPERUSER_ID, [shipping_id], shipping_info, context)
- else:
- shipping_id = orm_partner.create(cr, SUPERUSER_ID, shipping_info, context)
+ checkout['shipping_id'] = orm_partner.create(cr, SUPERUSER_ID, shipping_info, context)
order_info = {
'partner_id': partner_id,
'message_follower_ids': [(4, partner_id)],
'partner_invoice_id': partner_id,
- 'partner_shipping_id': shipping_id or partner_id
}
order_info.update(registry.get('sale.order').onchange_partner_id(cr, SUPERUSER_ID, [], partner_id, context=context)['value'])
order_info.pop('user_id')
+ order_info.update(partner_shipping_id=checkout.get('shipping_id') or partner_id)
- order_line_obj.write(cr, SUPERUSER_ID, [order.id], order_info, context=context)
+ order_obj.write(cr, SUPERUSER_ID, [order.id], order_info, context=context)
- @http.route(['/shop/checkout'], type='http', auth="public", website=True, multilang=True)
+ @http.route(['/shop/checkout'], type='http', auth="public", website=True)
def checkout(self, **post):
cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
return request.website.render("website_sale.checkout", values)
- @http.route(['/shop/confirm_order'], type='http', auth="public", website=True, multilang=True)
+ @http.route(['/shop/confirm_order'], type='http', auth="public", website=True)
def confirm_order(self, **post):
cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
order = request.website.sale_get_order(context=context)
+ if not order:
+ return request.redirect("/shop")
redirection = self.checkout_redirection(order)
if redirection:
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)
self.checkout_form_save(values["checkout"])
+
request.session['sale_last_order_id'] = order.id
return request.redirect("/shop/payment")
# Payment
#------------------------------------------------------
- @http.route(['/shop/payment'], type='http', auth="public", website=True, multilang=True)
+ @http.route(['/shop/payment'], type='http', auth="public", website=True)
def payment(self, **post):
""" Payment step. This page proposes several payment means based on available
payment.acquirer. State at this point :
values['acquirers'] = payment_obj.browse(cr, uid, acquirer_ids, context=context)
render_ctx = dict(context, submit_class='btn btn-primary', submit_txt='Pay Now')
for acquirer in values['acquirers']:
- render_ctx['tx_url'] = '/shop/payment/transaction/%s' % acquirer.id
acquirer.button = payment_obj.render(
cr, SUPERUSER_ID, acquirer.id,
order.name,
return request.website.render("website_sale.payment", values)
- @http.route(['/shop/payment/transaction/<int:acquirer_id>'], type='http', methods=['POST'], auth="public", website=True)
- def payment_transaction(self, acquirer_id, **post):
- """ Hook method that creates a payment.transaction and redirect to the
- acquirer, using post values to re-create the post action.
+ @http.route(['/shop/payment/transaction/<int:acquirer_id>'], type='json', auth="public", website=True)
+ def payment_transaction(self, acquirer_id):
+ """ Json method that creates a payment.transaction, used to create a
+ transaction when the user clicks on 'pay now' button. After having
+ created the transaction, the event continues and the user is redirected
+ to the acquirer website.
:param int acquirer_id: id of a payment.acquirer record. If not set the
user is redirected to the checkout page
- :param dict post: should coutain all post data for the acquirer
"""
- # @TDEFIXME: don't know why we received those data, but should not be send to the acquirer
- post.pop('submit.x', None)
- post.pop('submit.y', None)
cr, uid, context = request.cr, request.uid, request.context
- payment_obj = request.registry.get('payment.acquirer')
transaction_obj = request.registry.get('payment.transaction')
+ sale_order_obj = request.registry['sale.order']
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")
+
+ assert order.partner_id.id != request.website.partner_id.id
# find an already existing transaction
tx = request.website.sale_get_transaction()
- if not tx:
+ if tx:
+ if tx.state == 'draft': # button cliked but no more info -> rewrite on tx or create a new one ?
+ tx.write({
+ 'acquirer_id': acquirer_id,
+ })
+ tx_id = tx.id
+ else:
tx_id = transaction_obj.create(cr, SUPERUSER_ID, {
'acquirer_id': acquirer_id,
'type': 'form',
'amount': order.amount_total,
'currency_id': order.pricelist_id.currency_id.id,
'partner_id': order.partner_id.id,
+ 'partner_country_id': order.partner_id.country_id.id,
'reference': order.name,
'sale_order_id': order.id,
}, context=context)
request.session['sale_transaction_id'] = tx_id
- elif tx.state == 'draft': # button cliked but no more info -> rewrite on tx or create a new one ?
- tx.write({
- 'acquirer_id': acquirer_id,
- })
- acquirer_form_post_url = payment_obj.get_form_action_url(cr, uid, acquirer_id, context=context)
- acquirer_total_url = '%s?%s' % (acquirer_form_post_url, werkzeug.url_encode(post))
- return request.redirect(acquirer_total_url)
+ # update quotation
+ sale_order_obj.write(
+ cr, SUPERUSER_ID, [order.id], {
+ 'payment_acquirer_id': acquirer_id,
+ 'payment_tx_id': request.session['sale_transaction_id']
+ }, context=context)
+ # confirm the quotation
+ sale_order_obj.action_button_confirm(cr, SUPERUSER_ID, [order.id], context=request.context)
- @http.route('/shop/payment/get_status/<int:sale_order_id>', type='json', auth="public", website=True, multilang=True)
+ return tx_id
+
+ @http.route('/shop/payment/get_status/<int:sale_order_id>', type='json', auth="public", website=True)
def payment_get_status(self, sale_order_id, **post):
cr, uid, context = request.cr, request.uid, request.context
if not order:
return {
'state': 'error',
- 'message': '<p>There seems to be an error with your request.</p>',
+ 'message': '<p>%s</p>' % _('There seems to be an error with your request.'),
}
tx_ids = request.registry['payment.transaction'].search(
- cr, uid, [
+ cr, SUPERUSER_ID, [
'|', ('sale_order_id', '=', order.id), ('reference', '=', order.name)
], context=context)
if order.amount_total:
return {
'state': 'error',
- 'message': '<p>There seems to be an error with your request.</p>',
+ 'message': '<p>%s</p>' % _('There seems to be an error with your request.'),
}
else:
state = 'done'
message = ""
validation = None
else:
- tx = request.registry['payment.transaction'].browse(cr, uid, tx_ids[0], context=context)
+ tx = request.registry['payment.transaction'].browse(cr, SUPERUSER_ID, tx_ids[0], context=context)
state = tx.state
if state == 'done':
- message = '<p>Your payment has been received.</p>'
+ message = '<p>%s</p>' % _('Your payment has been received.')
elif state == 'cancel':
- message = '<p>The payment seems to have been canceled.</p>'
+ message = '<p>%s</p>' % _('The payment seems to have been canceled.')
elif state == 'pending' and tx.acquirer_id.validation == 'manual':
- message = '<p>Your transaction is waiting confirmation.</p>'
- message += tx.acquirer_id.post_msg
+ message = '<p>%s</p>' % _('Your transaction is waiting confirmation.')
+ if tx.acquirer_id.post_msg:
+ message += tx.acquirer_id.post_msg
else:
- message = '<p>Your transaction is waiting confirmation.</p>'
+ message = '<p>%s</p>' % _('Your transaction is waiting confirmation.')
validation = tx.acquirer_id.validation
return {
'validation': validation
}
- @http.route('/shop/payment/validate', type='http', auth="public", website=True, multilang=True)
+ @http.route('/shop/payment/validate', type='http', auth="public", website=True)
def payment_validate(self, transaction_id=None, sale_order_id=None, **post):
""" Method that should be called by the server when receiving an update
for a transaction. State at this point :
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
- sale_order_obj.action_button_confirm(cr, SUPERUSER_ID, [order.id], context=request.context)
- # send by email
- email_act = sale_order_obj.action_quotation_send(cr, SUPERUSER_ID, [order.id], context=request.context)
- elif tx.state == 'pending':
+ if not order.amount_total or tx.state in ['pending', 'done']:
# send by email
email_act = sale_order_obj.action_quotation_send(cr, SUPERUSER_ID, [order.id], context=request.context)
elif tx.state == 'cancel':
# cancel the quotation
sale_order_obj.action_cancel(cr, SUPERUSER_ID, [order.id], context=request.context)
+ # send the email
+ if email_act and email_act.get('context'):
+ composer_values = {}
+ email_ctx = email_act['context']
+ public_id = request.website.user_id.id
+ if uid == public_id:
+ composer_values['email_from'] = request.website.user_id.company_id.email
+ composer_id = request.registry['mail.compose.message'].create(cr, SUPERUSER_ID, composer_values, context=email_ctx)
+ request.registry['mail.compose.message'].send_mail(cr, SUPERUSER_ID, [composer_id], context=email_ctx)
+
# 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)
def payment_confirmation(self, **post):
""" End of checkout process controller. Confirmation is basically seing
the status of a sale.order. State at this point :
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})
# 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)
def add_product(self, name=None, category=0, **post):
cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
if not name:
name = _("New Product")
product_obj = request.registry.get('product.product')
- product_id = product_obj.create(cr, uid, { 'name': name, 'public_categ_id': category }, context=context)
+ product_id = product_obj.create(cr, uid, { 'name': name, 'public_categ_ids': category }, context=context)
product = product_obj.browse(cr, uid, product_id, context=context)
- return request.redirect("/shop/product/%s/?enable_editor=1" % product.product_tmpl_id.id)
-
- @http.route(['/shop/reorder'], type='json', auth="public")
- def reorder(self, product_id, operation):
- request.registry['product.template'].website_reorder(request.cr, request.uid, [id], operation, context=request.context)
+ return request.redirect("/shop/product/%s?enable_editor=1" % slug(product.product_tmpl_id))
@http.route(['/shop/change_styles'], type='json', auth="public")
def change_styles(self, id, style_id):
return not active
+ @http.route(['/shop/change_sequence'], type='json', auth="public")
+ def change_sequence(self, id, sequence):
+ product_obj = request.registry.get('product.template')
+ if sequence == "top":
+ product_obj.set_sequence_top(request.cr, request.uid, [id], context=request.context)
+ elif sequence == "bottom":
+ product_obj.set_sequence_bottom(request.cr, request.uid, [id], context=request.context)
+ elif sequence == "up":
+ product_obj.set_sequence_up(request.cr, request.uid, [id], context=request.context)
+ elif sequence == "down":
+ product_obj.set_sequence_down(request.cr, request.uid, [id], context=request.context)
+
@http.route(['/shop/change_size'], type='json', auth="public")
def change_size(self, id, x, y):
product_obj = request.registry.get('product.template')
product = product_obj.browse(request.cr, request.uid, id, context=request.context)
return product.write({'website_size_x': x, 'website_size_y': y})
+ def order_lines_2_google_api(self, order_lines):
+ """ Transforms a list of order lines into a dict for google analytics """
+ ret = []
+ for line in order_lines:
+ ret.append({
+ 'id': line.order_id and line.order_id.id,
+ 'name': line.product_id.categ_id and line.product_id.categ_id.name or '-',
+ 'sku': line.product_id.id,
+ 'quantity': line.product_uom_qty,
+ 'price': line.price_unit,
+ })
+ return ret
+
+ @http.route(['/shop/tracking_last_order'], type='json', auth="public")
+ def tracking_cart(self, **post):
+ """ return data about order in JSON needed for google analytics"""
+ cr, uid, context = request.cr, request.uid, request.context
+ ret = {}
+ sale_order_id = request.session.get('sale_last_order_id')
+ if sale_order_id:
+ order = request.registry['sale.order'].browse(cr, SUPERUSER_ID, sale_order_id, context=context)
+ ret['transaction'] = {
+ 'id': sale_order_id,
+ 'affiliation': order.company_id.name,
+ 'revenue': order.amount_total,
+ 'currency': order.currency_id.name
+ }
+ ret['lines'] = self.order_lines_2_google_api(order.order_line)
+ return ret
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4: