[IMP] ecommerce

bzr revid: chm@openerp.com-20130628162804-l6aejjkzwprg932r
This commit is contained in:
Christophe Matthieu 2013-06-28 18:28:04 +02:00
parent 849900b304
commit ffb4119120
6 changed files with 418 additions and 0 deletions

View File

@ -0,0 +1 @@
import controllers

View File

@ -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'
],
}

View File

@ -0,0 +1,3 @@
import main
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -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 = ['<link href="https://www.openerp.com/saas_master/static/site_new/fonts/lato/stylesheet.css" rel="stylesheet" type="text/css">']
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/<path:path>'], 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('<div class="placeholder_product"/>', products)
categories = self.render_category_list(cr, uid, category_id)
content = content.replace('<div class="placeholder_category"/>', categories)
html = open(openerp.addons.get_module_resource('ecommerce', 'views', 'homepage.html'), 'rb').read().decode('utf8')
html = html.replace('<!--placeholder_container-->', content)
html = html.replace('<!--editable-->', get_html_head())
return html
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Product container -->
<record id="product_container" model="ir.ui.view">
<field name="name">ecommerce_product_container</field>
<field name="type">form</field>
<field name="arch" type="xml">
<html>
<h2 class="oe_slogan">Want to use E-Commerce on OpenERP?</h2>
<h3 class="oe_slogan">Contact a local partner</h3>
<div class="oe_row">
<div class="placeholder_category"/>
<div class="placeholder_product"/>
</div>
</html>
</field>
</record>
<!-- Product list -->
<record id="product_list" model="ir.ui.view">
<field name="name">ecommerce_product_list</field>
<field name="type">form</field>
<field name="arch" type="xml">
<html>
<div class='oe_span9 oe_partners'>
<t t-foreach="products">
<div class='oe_span9 oe_partner oe_clearfix'>
<div class='oe_partner_logo'><img t-att-src="'data:image/png;base64,' + image_medium"/></div>
<div class='oe_content'>
<a class='oe_name' t-att-href='url'><t t-esc="name"/></a>
<div t-if="description_sale" class="oe_partner_listing_descr"><t t-esc="description_sale"/></div>
<div class="oe_price"><t t-esc="list_price"/></div>
</div>
</div>
</t>
</div>
</html>
</field>
</record>
<!-- Product detail -->
<record id="product" model="ir.ui.view">
<field name="name">ecommerce_product</field>
<field name="type">form</field>
<field name="arch" type="xml">
<html>
<div class='oe_span9'>
<h3 class='oe_slogan'><t t-esc="name"/></h3>
<div class='oe_span9 oe_partner oe_clearfix'>
<div class='oe_partner_logo'><img t-att-src="'data:image/png;base64,' + image"/></div>
<div class='oe_content'>
<div t-if="description_sale" class="oe_partner_listing_descr"><t t-esc="description_sale"/></div>
<div class="oe_price"><t t-esc="list_price"/></div>
</div>
</div>
</div>
</html>
</field>
</record>
<!-- List of categories -->
<record id="categories" model="ir.ui.view">
<field name="name">ecommerce_categories</field>
<field name="type">form</field>
<field name="arch" type="xml">
<html>
<div class='oe_span3 oe_left oe_categories'>
<h4>Product categories</h4>
<ul>
<t t-foreach="categories">
<li t-att-class="selected and 'oe_selected' or ''"><a t-att-href="url"><t t-esc="name"/></a></li>
<ul t-id="child_ids">
<t t-foreach="child_ids">
<li t-att-class="selected and 'oe_selected' or ''"><a t-att-href="url"><t t-esc="name"/></a></li>
<ul t-id="child_ids">
<t t-foreach="child_ids">
<li t-att-class="selected and 'oe_selected' or ''"><a t-att-href="url"><t t-esc="name"/></a></li>
</t>
</ul>
</t>
</ul>
</t>
</ul>
</div>
</html>
</field>
</record>
</data>
</openerp>

View File

@ -0,0 +1,184 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>OpenERP - Beautiful Business Applications</title>
<script src='https://www.openerp.com/saas_master/static/site_new/js/lib/html5shiv.js'></script>
<script src="https://www.openerp.com/web/static/lib/jquery/jquery-1.8.3.js"></script>
<script src="//cdn.optimizely.com/js/238505250.js"></script>
<link href='https://www.openerp.com/saas_master/static/site_new/fonts/lato/stylesheet.css' rel='stylesheet' type='text/css'></link>
<link href='//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,300,600,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://www.openerp.com/saas_master/static/site_new/css/normalize.css">
<link rel="stylesheet" href="https://www.openerp.com/saas_master/static/site_new/css/common.css">
<link rel="stylesheet" href="https://www.openerp.com/saas_master/static/site_new/css/website.css">
<link rel="stylesheet" href="https://www.openerp.com/saas_master/static/site_new/css/font-awesome.css">
<script src="https://www.openerp.com/web/static/lib/underscore/underscore.js"></script>
<script src="https://www.openerp.com/web/static/lib/underscore/underscore.string.js"></script>
<script src='https://www.openerp.com/saas_master/static/site_new/js/website.js'></script>
<!--editable-->
</head>
<body class="oe_styling_v8">
<div class='oe_website_contents'>
<header class='oe_website_header'>
<div class='oe_row oe_fit'>
<div class='oe_span3 oe_logo_menu'>
<a href='https://www.openerp.com/' class='ab_menu_logo'>
<img class='oe_logo_img' alt='OpenERP: Open Source Business Apps' src='https://www.openerp.com/saas_master/static/site_new/img/logo_oe_top_old_and_small.png'>
</a>
</div>
<ul class='oe_span9 oe_right oe_top_menu' id='top-menu'> <li class='oe_top_menu_entry'><a class='ab_menu_apps' href='https://www.openerp.com/apps'>Applications</a></li>
<li class='oe_top_menu_entry'><a class='ab_menu_partners' href='https://www.openerp.com/partners/directory'>Partners</a></li>
<li class='oe_top_menu_entry'><a class='ab_menu_training' href="https://www.openerp.com/events#view=training">Training</a></li>
<li class='oe_top_menu_entry'><a class='ab_menu_freetrial' href='https://www.openerp.com/start'>Free Trial</a></li>
<li class='oe_top_menu_entry'><a class='ab_menu_download' href='https://www.openerp.com/start?download'>Download</a></li>
<li class='oe_top_menu_entry'><a class='ab_menu_contact' href='https://www.openerp.com/contact'>Contact Us</a></li>
<li class='oe_top_menu_entry oe_sign_in '><a class='ab_menu_signin' href='https://accounts.openerp.com'>Sign In</a></li>
</ul>
</div>
</header>
<section class='oe_hero oe_home_hero oe_container'>
<div class='oe_slider'>
<div class='oe_slide oe_home_slide'>
<div class='oe_row'>
<div class='oe_slide_title oe_title_font'><span class='oe_open'>Open</span><span class='oe_erp'>ERP</span><span class='oe_version'>7.0</span></div>
<div class='oe_slide_subtitle'>
Beautiful Business Applications<br />
Powerful, Integrated, Open Source<br />
<a href='https://www.openerp.com/start' class='oe_button oe_medium oe_tacky ab_banner_freetrial'>Start your <span class='oe_emph'>free</span> trial <i class='icon-arrow-right'></i></a>
</div>
</div>
</div>
<div class='oe_slide oe_invisible oe_opendays_slide'>
<div class='oe_row'>
<div class='oe_titlebox'>
<div class='oe_title oe_title_font'>OpenDays</div>
<div class='oe_subtitle'>The Open Source event of the year</br>July 1-5, 2013</br><a class='oe_button ab_banner_events' href='http://opendays.openerp.com'>Agenda &amp; Registration</a></div>
</div>
</div>
</div>
</div>
<span class='oe_slider_arrow oe_left'><i class='icon-chevron-left'></i></span>
<span class='oe_slider_arrow oe_right'><i class='icon-chevron-right'></i></span>
</section>
<article class='oe_page'>
<section class='oe_container'>
<!--placeholder_container-->
</section>
<footer class="oe_website_footer">
<article class="oe_row">
<section class="oe_span3">
<h1>About Us</h1>
<ul id='footer-about'>
<li><a href="https://www.openerp.com/events">Events</a></li>
<li><a href="https://www.openerp.com/news">News</a></li>
<li><a href="https://www.openerp.com/jobs">Jobs</a></li>
<li><a href="https://www.openerp.com/contact">Contact</a></li>
<li><a href="https://www.openerp.com/references/directory/">References</a></li>
<li class="oe_mt16"><a href="http://twitter.com/openerp"><i class="icon-twitter-sign"></i>Twitter</a></li>
<li><a href="http://www.facebook.com/OpenERP"><i class="icon-facebook-sign"></i>Facebook</a></li>
<li><a href="https://plus.google.com/+openerp/posts"><i class="icon-google-plus-sign"></i>Google+</a></li>
</ul>
</section>
<section class="oe_span3">
<h1>Developers</h1>
<ul id='footer-devs'>
<li><a href="https://www.openerp.com/start?download">Download</a></li>
<li><a href="https://launchpad.net/openobject">Launchpad</a></li>
<li><a href="http://runbot.openerp.com">Automated Tests</a></li>
<li class="oe_mt16"><a href="https://bugs.launchpad.net/openobject-addons">Report a Bug</a></li>
<li><a href="http://doc.openerp.com/v6.1/contribute/07_improving_translations.html">Help Translate</a></li>
</ul>
</section>
<section class="oe_span3">
<h1>Services</h1>
<ul id='footer-services'>
<li><a href="https://www.openerp.com/pricing">Pricing</a></li>
<li class="oe_mt16"><a href="https://www.openerp.com/partners/directory">Find a Partner</a></li>
<li><a href="https://www.openerp.com/partners">Become a Partner</a></li>
<li class="oe_mt16"><a href="https://www.openerp.com/events#view=training">Training</a></li>
</ul>
</section>
<section class="oe_span3">
<h1>Documentation</h1>
<ul id='footer-doc'>
<li><a href="http://help.openerp.com">Get Help</a></li>
<li><a href="https://doc.openerp.com/">Documentation</a></li>
<li class="oe_mt16"><a href="http://www.amazon.com/s/ref=nb_sb_noss_1?url=search-alias%3Dstripbooks&field-keywords=Openerp&rh=n%3A283155%2Ck%3AOpenerp">Paper Books</a></li>
<li><a href="https://www.openerp.com/ebooks">Free E-Books</a></li>
<li><a href="http://doc.openerp.com/memento/OpenERP_Technical_Memento_latest.pdf">Developer Memento</a></li>
<li><a href="http://www.slideshare.net/openobject/presentations">Presentations</a></li>
</ul>
</section>
</article>
<article class="oe_row">
<div class="oe_span12">
<h1>Offices</h1>
</div>
<section class="oe_span6 oe_fit">
<h2 class="fn org oe_span6">Europe/Africa</h2>
<div class="oe_clearfix">
<div class='oe_span3'>
<ul class="vcard">
<li class="oe_small adr">
<p><strong>Sales Office</strong></p>
<span class="street-address">Avenue Edmond Van Nieuwenhuyse, 5 (Serenitas building)</span>
<span class="postcode">1160</span>
<span class="locality">Brussels</span>,
<span class="country-name">Belgium</span>
</li>
<li class="tel"><a href="tel:+32 2 290 34 90"><i class="icon-phone"></i>+32 2 290 34 90</a></li>
</ul>
</div>
<div class='oe_span3'>
<ul class="vcard oe_span3">
<li class="oe_small adr">
<p><strong>Services & R&D</strong></p>
<span class="street-address">Chaussée de Namur, 40</span>
<span class="postcode">1367</span>
<span class="locality">Grand-Rosière</span>,
<span class="country-name">Belgium</span>
</li>
<li class="tel"><a href="tel:+32 81 81 37 00"><i class="icon-phone"></i>+32 81 81 37 00</a></li>
<li class="fax"><a href="fax:+32 81 73 35 01"><i class="icon-fax"></i>+32 81 73 35 01 (fax)</a></li>
</ul>
</div>
</div>
</section>
<section class="oe_span3 vcard">
<h2 class="fn org">Americas</h2>
<ul>
<li class="oe_small adr">
<p><strong>Sales, Services</strong></p>
<span class="street-address">260 Main Street</span>,
<span class="post-office-box">Suite 203</span>
<span class="locality">Redwood City</span>,
<span class="region">CA</span>
<span class="postal-code">94063</span>,
<span class="country-name">United States</span>
</li>
<li class="tel"><a href="tel:+1(650)307-6736"><i class="icon-phone"></i>+1(650)307-6736</a></li>
</ul>
</section>
<section class="oe_span3 vcard">
<h2 class="fn org">Asia Pacific</h2>
<ul>
<li class="oe_small adr">
<p><strong>Sales, Services, R&D</strong></p>
<span class="street-address">16 / 17, IT Tower 1 Infocity Gate - 1</span>
<span class="locality">Gandhinagar</span> -
<span class="postal-code">382007</span>,
<span class="region">Gujarat</span>
<span class="country-name">India</span>
</li>
<li class="tel"><i class="icon-phone"></i><a href="tel:+91(79)40 500 100">+91(79)40 500 100</a></li>
</ul>
</section>
</article>
</footer>
</body>
</html>