[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:
parent
e509f9155b
commit
b89b7e0554
|
@ -906,16 +906,30 @@ class website_sale(http.Controller):
|
||||||
""" Transforms a list of order lines into a dict for google analytics """
|
""" Transforms a list of order lines into a dict for google analytics """
|
||||||
ret = []
|
ret = []
|
||||||
for line in order_lines:
|
for line in order_lines:
|
||||||
|
product = line.product_id
|
||||||
ret.append({
|
ret.append({
|
||||||
'id': line.order_id and line.order_id.id,
|
'id': line.order_id and line.order_id.id,
|
||||||
'sku': line.product_id.id,
|
'sku': product.ean13 or product.id,
|
||||||
'name': line.product_id.name or '-',
|
'name': product.name or '-',
|
||||||
'category': line.product_id.categ_id and line.product_id.categ_id.name or '-',
|
'category': product.categ_id and product.categ_id.name or '-',
|
||||||
'price': line.price_unit,
|
'price': line.price_unit,
|
||||||
'quantity': line.product_uom_qty,
|
'quantity': line.product_uom_qty,
|
||||||
})
|
})
|
||||||
return ret
|
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")
|
@http.route(['/shop/tracking_last_order'], type='json', auth="public")
|
||||||
def tracking_cart(self, **post):
|
def tracking_cart(self, **post):
|
||||||
""" return data about order in JSON needed for google analytics"""
|
""" 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')
|
sale_order_id = request.session.get('sale_last_order_id')
|
||||||
if sale_order_id:
|
if sale_order_id:
|
||||||
order = request.registry['sale.order'].browse(cr, SUPERUSER_ID, sale_order_id, context=context)
|
order = request.registry['sale.order'].browse(cr, SUPERUSER_ID, sale_order_id, context=context)
|
||||||
ret['transaction'] = {
|
ret = self.order_2_return_dict(order)
|
||||||
'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
|
return ret
|
||||||
|
|
||||||
@http.route(['/shop/get_unit_price'], type='json', auth="public", methods=['POST'], website=True)
|
@http.route(['/shop/get_unit_price'], type='json', auth="public", methods=['POST'], website=True)
|
||||||
|
|
|
@ -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 """
|
""" 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]
|
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)
|
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
|
||||||
|
|
Loading…
Reference in New Issue