Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions website_sale_affiliate/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg
:target: http://www.gnu.org/licenses/lgpl
:alt: License: LGPL-3

=================
Affiliate Program
=================

This module allows for the creation of affiliates and the tracking of sales conversions generated by them.

Usage
=====

To use this module, you must first create at least one affiliate (found in Website/Affiliate Program).

Once an affiliate has been created, append one of the following to a compatible shop or product url (see below) to track the affiliate's conversions:

* ?aff_ref=\ *affiliate_id*
* ?aff_ref=\ *affiliate_id*\&aff_key=\ *custom_key*

The "affiliate_id" is the ID displayed on the affiliate's record, e.g. "1".

The "custom_key" (optional) is a url-friendly string of your choice used to track a specific campaign, e.g. "anniversary_sale". Associated affiliate requests will be named after this key, if provided.

**Example:** /shop?aff_ref=1&aff_key=anniversary_sale

Compatible URLs
---------------

* /shop
* /shop/category/{category}
* /shop/category/{category}/page/{page}
* /shop/page/{page}
* /shop/product/{product}

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/113/10.0

Known issues / Roadmap
======================

* Evaluate usefulness of IP as a fallback affiliate request identifier

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/e-commerce/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.

Credits
=======

Images
------

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.

Contributors
------------

* Brent Hughes <brent.hughes@laslabs.com>
* Dave Lasley <dave@laslabs.com>

Do not contact contributors directly about support or help with technical issues.

Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

To contribute to this module, please visit https://odoo-community.org.
5 changes: 5 additions & 0 deletions website_sale_affiliate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2017 LasLabs Inc.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl)

from . import controllers
from . import models
28 changes: 28 additions & 0 deletions website_sale_affiliate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2017 LasLabs Inc.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl)

{
"name": "Affiliate Program",
"summary": "Create an e-commerce affiliate program for the tracking of "
"referrals and conversions.",
"version": "18.0.1.0.0",
"category": "E-Commerce",
"website": "https://github.com/OCA/e-commerce",
"author": "LasLabs, Odoo Community Association (OCA)",
"license": "LGPL-3",
"application": False,
"installable": True,
"depends": [
"website_sale",
],
"data": [
"data/sale_affiliate_data.xml",
"security/ir.model.access.csv",
"views/sale_affiliate_view.xml",
"views/sale_affiliate_request_view.xml",
"views/sale_order_view.xml",
],
"demo": [
"demo/sale_affiliate_demo.xml",
],
}
4 changes: 4 additions & 0 deletions website_sale_affiliate/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2017 LasLabs Inc.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl)

from . import main
42 changes: 42 additions & 0 deletions website_sale_affiliate/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2017 LasLabs Inc.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl)

import logging

from odoo.http import request, route

from odoo.addons.website_sale.controllers.main import WebsiteSale as Base

_logger = logging.getLogger(__name__)


class WebsiteSale(Base):
def _store_affiliate_info(self, **kwargs):
Affiliate = request.env["sale.affiliate"]
affiliate = Affiliate.sudo().find_from_kwargs(**kwargs)
try:
affiliate_request = affiliate.get_request(**kwargs)
request.session["affiliate_request"] = affiliate_request.id
except (AttributeError, ValueError) as err:
_logger.debug("Could not store affiliate info: %s", err)

@route()
def shop(
self,
page=0,
category=None,
search="",
min_price=0.0,
max_price=0.0,
ppg=False,
**post,
):
res = super().shop(page, category, search, min_price, max_price, ppg, **post)
self._store_affiliate_info(**post)
return res

@route()
def product(self, product, category="", search="", **kwargs):
res = super().product(product, category="", search="", **kwargs)
self._store_affiliate_info(**kwargs)
return res
10 changes: 10 additions & 0 deletions website_sale_affiliate/data/sale_affiliate_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2017 LasLabs Inc.
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
<odoo noupdate="1">
<record id="request_sequence" model="ir.sequence">
<field name="name">Affiliate Request Sequence</field>
<field name="padding">10</field>
<field name="number_next">1</field>
</record>
</odoo>
28 changes: 28 additions & 0 deletions website_sale_affiliate/demo/sale_affiliate_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2017 LasLabs Inc.
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
<odoo noupdate="1">
<record id="sale_affiliate_myaffiliate" model="sale.affiliate">
<field name="name">MyAffiliate</field>
<field name="company_id" ref="base.main_company" />
<field name="valid_hours">24</field>
<field name="valid_sales">1</field>
</record>

<record id="sale_affiliate_request_firesale" model="sale.affiliate.request">
<field name="name">firesale</field>
<field name="affiliate_id" ref="sale_affiliate_myaffiliate" />
<field name="ip">0.0.0.0</field>
<field name="referrer">referrer</field>
<field name="user_agent">user agent</field>
<field name="accept_language">language</field>
</record>

<record id="sale.sale_order_1" model="sale.order">
<field name="affiliate_request_id" ref="sale_affiliate_request_firesale" />
</record>

<record id="sale.sale_order_2" model="sale.order">
<field name="affiliate_request_id" ref="sale_affiliate_request_firesale" />
</record>
</odoo>
Loading
Loading