[FIX] website_sale, website_sale_delivery: Improve GA eCommerce data

As eCommerce is not complete and could be improved easily and was
not working anyway until
9d0cb024fd

- Use EAN13 instead of internal product id if available
- Add tax to transaction data
- Add shipping costs if available to transaction data
This commit is contained in:
Wolfgang Taferner 2015-09-04 07:51:36 +02:00 committed by Jeremy Kersten
parent e509f9155b
commit b89b7e0554
2 changed files with 26 additions and 10 deletions

View File

@ -906,16 +906,30 @@ class website_sale(http.Controller):
""" Transforms a list of order lines into a dict for google analytics """
ret = []
for line in order_lines:
product = line.product_id
ret.append({
'id': line.order_id and line.order_id.id,
'sku': line.product_id.id,
'name': line.product_id.name or '-',
'category': line.product_id.categ_id and line.product_id.categ_id.name or '-',
'sku': product.ean13 or product.id,
'name': product.name or '-',
'category': product.categ_id and product.categ_id.name or '-',
'price': line.price_unit,
'quantity': line.product_uom_qty,
})
return ret
def order_2_return_dict(self, order):
""" Returns the tracking_cart dict of the order for Google analytics basically defined to be inherited """
return {
'transaction': {
'id': order.id,
'affiliation': order.company_id.name,
'revenue': order.amount_total,
'tax': order.amount_tax,
'currency': order.currency_id.name
},
'lines': self.order_lines_2_google_api(order.order_line)
}
@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"""
@ -924,13 +938,7 @@ class website_sale(http.Controller):
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)
ret = self.order_2_return_dict(order)
return ret
@http.route(['/shop/get_unit_price'], type='json', auth="public", methods=['POST'], website=True)

View File

@ -26,3 +26,11 @@ class website_sale(openerp.addons.website_sale.controllers.main.website_sale):
""" Transforms a list of order lines into a dict for google analytics """
order_lines_not_delivery = [line for line in order_lines if not line.is_delivery]
return super(website_sale, self).order_lines_2_google_api(order_lines_not_delivery)
def order_2_return_dict(self, order):
""" Returns the tracking_cart dict of the order for Google analytics """
ret = super(website_sale, self).order_2_return_dict(order)
for line in order.order_line:
if line.is_delivery:
ret['transaction']['shipping'] = line.price_unit
return ret