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))
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(),
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/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()
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"]
if not check_func(cr, uid, vat_country, vat_number, context=None): # simple_vat_check
error["vat"] = 'error'
- if data.get("shipping_different"):
+ 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):
partner_id = orm_partner.create(cr, SUPERUSER_ID, billing_info, context=context)
# create a new shipping partner
- shipping_id = None
- if checkout.get('shipping_different'):
+ if checkout.get('shipping_id') == -1:
shipping_info = self.checkout_parse('shipping', checkout, True)
shipping_info['type'] = 'delivery'
shipping_info['parent_id'] = partner_id
- 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_obj.write(cr, SUPERUSER_ID, [order.id], order_info, context=context)
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")
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 = '<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 {
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" % slug(product.product_tmpl_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)
-
@http.route(['/shop/change_styles'], type='json', auth="public")
def change_styles(self, id, style_id):
product_obj = request.registry.get('product.template')
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: