diff --git a/addons/ecommerce/__init__.py b/addons/ecommerce/__init__.py new file mode 100644 index 00000000000..ee5959455ad --- /dev/null +++ b/addons/ecommerce/__init__.py @@ -0,0 +1 @@ +import controllers diff --git a/addons/ecommerce/__openerp__.py b/addons/ecommerce/__openerp__.py new file mode 100644 index 00000000000..e35f293d8bd --- /dev/null +++ b/addons/ecommerce/__openerp__.py @@ -0,0 +1,16 @@ +{ + 'name': 'E-Commerce', + 'category': 'Sale', + 'version': '1.0', + 'description': """ +OpenERP E-Commerce +================== + + """, + 'author': 'OpenERP SA', + 'depends': ['website', 'sale_stock', 'point_of_sale'], + 'installable': True, + 'data': [ + 'views/ecommerce.xml' + ], +} diff --git a/addons/ecommerce/controllers/__init__.py b/addons/ecommerce/controllers/__init__.py new file mode 100644 index 00000000000..e11f9ba81bb --- /dev/null +++ b/addons/ecommerce/controllers/__init__.py @@ -0,0 +1,3 @@ +import main + +# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/ecommerce/controllers/main.py b/addons/ecommerce/controllers/main.py new file mode 100644 index 00000000000..1f7eabf5211 --- /dev/null +++ b/addons/ecommerce/controllers/main.py @@ -0,0 +1,118 @@ +# -*- coding: utf-8 -*- + +import openerp +from openerp.addons.web import http +from openerp.addons.web.http import request +from werkzeug.exceptions import NotFound +import urllib + + +def get_html_head(): + head = [''] + return "\n ".join(head) + + +class Ecommerce(http.Controller): + + def to_url(self, paths): + url = "" + for path in paths: + if isinstance(path, (int, long)): + path = "%s" % path + url = "%s/%s" % (url, urllib.quote_plus(path.encode('utf-8'))) + return url + + def path_category(self, category_browse): + paths = [] + cat = category_browse + while cat.parent_id: + cat = cat.parent_id + paths.append(cat.name) + paths.append('shop') + paths.reverse() + return paths + + def render_product(self, cr, uid, product_id): + product_obj = request.registry.get('product.product') + product = product_obj.read(cr, uid, product_id, []) + if not product: + raise NotFound() + content = request.registry.get("ir.ui.view").render(cr, uid, 'ecommerce.product', product) + return content + + # select main category or sub categories + def render_product_list(self, cr, uid, category_id=None, search="", offset=0): + product_obj = request.registry.get('product.product') + product_ids = product_obj.search(cr, uid, category_id and [('pos_categ_id.id', 'child_of', category_id)] or [(1, '=', 1)], limit=20, offset=offset) + + products = [] + for prod in product_obj.browse(cr, uid, product_ids): + paths = self.path_category(prod.pos_categ_id) + paths += [prod.pos_categ_id.name, prod.id, prod.name] + product = prod.read(['image_small', 'image_medium', 'list_price', 'description_sale', 'name'])[0] + product['url'] = self.to_url(paths) + products.append(product) + + return request.registry.get("ir.ui.view").render(cr, uid, 'ecommerce.product_list', {'products': products, 'search': search}) + + def render_category_list(self, cr, uid, category_id=None): + category_obj = request.registry.get('pos.category') + category_ids = category_obj.search(cr, uid, [('parent_id', '=', False)]) + + def get_category_data(category): + paths = self.path_category(category) + paths.append(category.name) + child_ids = [] + for child in category.child_id: + child_ids.append(get_category_data(child)) + return { + 'name': category.name, + 'url': self.to_url(paths), + 'selected': category['id'] == category_id, + 'child_ids': child_ids, + } + + categories = [] + for category in category_obj.browse(cr, uid, category_ids): + categories.append(get_category_data(category)) + + return request.registry.get("ir.ui.view").render(cr, uid, 'ecommerce.categories', {'categories': categories}) + + @http.route(['/shop', '/shop/', '/shop/'], type='http', auth="db") + def shop(self, path=None, offset=0): + category_obj = request.registry.get('pos.category') + + cr = request.cr + uid = request.session._uid + paths = [urllib.unquote_plus(path) for path in path and path.strip('/').split('/') or []] + + product_id = None + category_id = None + if paths: + if len(paths) >= 2 and paths[-2].isdigit(): + product_id = int(paths[-2]) + if product_id: + category = len(paths) >= 3 and paths[-3] or None + else: + category = paths[-1] + if category: + category_id = category_obj.search(cr, uid, [('name', 'ilike', category)])[0] + + content = request.registry.get("ir.ui.view").render(cr, uid, 'ecommerce.product_container', {}) + + products = product_id and \ + self.render_product(cr, uid, product_id) or \ + self.render_product_list(cr, uid, category_id, "trucmuch", offset=offset) + content = content.replace('', products) + + categories = self.render_category_list(cr, uid, category_id) + content = content.replace('', categories) + + html = open(openerp.addons.get_module_resource('ecommerce', 'views', 'homepage.html'), 'rb').read().decode('utf8') + html = html.replace('', content) + html = html.replace('', get_html_head()) + + return html + + +# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/ecommerce/views/ecommerce.xml b/addons/ecommerce/views/ecommerce.xml new file mode 100644 index 00000000000..b59a17ee568 --- /dev/null +++ b/addons/ecommerce/views/ecommerce.xml @@ -0,0 +1,96 @@ + + + + + + + + ecommerce_product_container + form + + + Want to use E-Commerce on OpenERP? + Contact a local partner + + + + + + + + + + + + ecommerce_product_list + form + + + + + + + + + + + + + + + + + + + + + + ecommerce_product + form + + + + + + + + + + + + + + + + + + + + ecommerce_categories + form + + + + Product categories + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/addons/ecommerce/views/homepage.html b/addons/ecommerce/views/homepage.html new file mode 100644 index 00000000000..a281429b1a4 --- /dev/null +++ b/addons/ecommerce/views/homepage.html @@ -0,0 +1,184 @@ + + + + + + OpenERP - Beautiful Business Applications + + + + + + + + + + + + + + + + + + + + + + + + Applications + Partners + Training + Free Trial + Download + Contact Us + Sign In + + + + + + + + + OpenERP7.0 + + Beautiful Business Applications + Powerful, Integrated, Open Source + Start your free trial + + + + + + + OpenDays + The Open Source event of the yearJuly 1-5, 2013Agenda & Registration + + + + + + + + + + + + + + + + +