[IMP] website_sale: recommended

bzr revid: chm@openerp.com-20130711142434-natrpfsutm6o66a9
This commit is contained in:
Christophe Matthieu
2013-07-11 16:24:34 +02:00
parent d04da544b0
commit ffbac75519
7 changed files with 133 additions and 49 deletions
+2 -2
View File
@@ -9,11 +9,11 @@ OpenERP Contact Form
""",
'author': 'OpenERP SA',
'depends': ['website', 'crm'],
'installable': True,
'auto_install': True,
'data': [
'views/website_crm.xml'
],
'js': ['static/src/js/ecommerce.js'],
'css': ['static/src/css/ecommerce.css'],
'installable': True,
'auto_install': True,
}
+2 -1
View File
@@ -9,10 +9,11 @@ OpenERP E-Commerce
""",
'author': 'OpenERP SA',
'depends': ['website', 'sale', 'point_of_sale'],
'installable': True,
'data': [
'views/ecommerce.xml'
],
'js': ['static/src/js/ecommerce.js'],
'css': ['static/src/css/ecommerce.css'],
'installable': True,
'auto_install': True,
}
+32 -4
View File
@@ -14,7 +14,7 @@ class Ecommerce(http.Controller):
if request.session._uid:
request.httprequest.session['ecommerce_partner_id'] = False
partner_id = request.registry.get('res.users').browse(cr, uid, uid).partner_id.id
partner_id = request.registry.get('res.users').browse(cr, uid, request.session._uid).partner_id.id
else:
partner_id = request.httprequest.session.get('ecommerce_partner_id', False)
if partner_id and not request.registry.get('res.partner').search(cr, uid, [('id', '=', partner_id)]):
@@ -37,7 +37,7 @@ class Ecommerce(http.Controller):
if not order_id:
fields = [k for k, v in order_obj._columns.items()]
order_value = order_obj.default_get(cr, uid, fields, context=context)
order_value['partner_id'] = partner_id
order_value['partner_id'] = partner_id or request.registry.get('res.users').browse(cr, uid, uid).partner_id.id
order_value.update(order_obj.onchange_partner_id(cr, uid, [], uid, context=context)['value'])
order_id = order_obj.create(cr, uid, order_value, context=context)
request.httprequest.session['ecommerce_order'] = order_id
@@ -87,8 +87,12 @@ class Ecommerce(http.Controller):
product_id = product_id and int(product_id) or 0
product_obj = request.registry.get('product.product')
line = [line for line in values['order'].order_line if line.product_id.id == product_id]
quantity = line and int(line[0].product_uom_qty) or 0
values.update({
'product': product_obj.browse(cr, uid, product_id),
'quantity': quantity,
})
html = request.registry.get("ir.ui.view").render(cr, uid, "website_sale.product", values)
return html
@@ -96,7 +100,29 @@ class Ecommerce(http.Controller):
@http.route(['/shop/my_cart'], type='http', auth="admin")
def my_cart(self, offset=0):
cr, uid, partner_id = self.get_cr_uid()
html = request.registry.get("ir.ui.view").render(cr, uid, "website_sale.my_cart", self.get_values())
values = self.get_values()
my_pids = ",".join([str(line.product_id.id) for line in values['order'].order_line])
product_ids = []
query = """
SELECT sol.product_id
FROM sale_order_line as my
LEFT JOIN sale_order_line as sol
ON sol.order_id = my.order_id
WHERE my.product_id in (%s)
AND sol.product_id not in (%s)
GROUP BY sol.product_id
ORDER BY COUNT(sol.order_id) DESC
LIMIT 8
""" % (my_pids, my_pids)
cr.execute(query)
for p in cr.fetchall():
product_ids.append(p[0])
values["recommended_products"] = request.registry.get('product.product').browse(cr, uid, product_ids)
html = request.registry.get("ir.ui.view").render(cr, uid, "website_sale.my_cart", values)
return html
@http.route(['/shop/add_cart'], type='http', auth="admin")
@@ -132,7 +158,9 @@ class Ecommerce(http.Controller):
# change and record value
if quantity:
pricelist_id = order.pricelist_id and order.pricelist_id.id or False
values.update(order_line_obj.product_id_change(cr, uid, [], pricelist_id, product_id, partner_id=partner_id, context=context)['value'])
values.update(order_line_obj.product_id_change(cr, uid, [], pricelist_id, product_id,
partner_id=partner_id or request.registry.get('res.users').browse(cr, uid, uid).partner_id.id,
context=context)['value'])
if order_line_ids:
order_line_obj.write(cr, uid, order_line_ids, values, context=context)
else:
@@ -85,6 +85,9 @@
top: 6px;
text-align: right;
}
.oe_ecommerce .oe_mycart form input {
margin-bottom: 0;
}
.oe_ecommerce .oe_product {
vertical-align: top;
position: relative;
@@ -100,12 +103,12 @@
-moz-box-shadow: 0 0 3px 1px rgba(0, 0, 0, 0.1);
box-shadow: 0 0 3px 1px rgba(0, 0, 0, 0.1);
}
.oe_ecommerce .oe_product .oe_button_cart {
.oe_ecommerce .oe_button_cart {
width: 100%;
font-size: 11px;
position: absolute;
}
.oe_ecommerce .oe_product .oe_button_cart button {
.oe_ecommerce .oe_button_cart button {
text-shadow: 0px 1px 1px rgba(0, 0, 0, 0.44);
overflow: hidden;
text-align: center;
@@ -117,14 +120,14 @@
height: 22px;
position: relative;
}
.oe_ecommerce .oe_product .oe_button_cart button:first-child {
.oe_ecommerce .oe_button_cart button:first-child {
background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #aaaaaa), color-stop(100%, #999999));
background: -webkit-linear-gradient(#aaaaaa, #999999);
background: -moz-linear-gradient(#aaaaaa, #999999);
background: -o-linear-gradient(#aaaaaa, #999999);
background: linear-gradient(#aaaaaa, #999999);
}
.oe_ecommerce .oe_product .oe_button_cart button:first-child span {
.oe_ecommerce .oe_button_cart button:first-child span {
opacity: 0.8;
filter: alpha(opacity=80);
color: #eb1212;
@@ -133,14 +136,14 @@
top: 3px;
font-size: 20px;
}
.oe_ecommerce .oe_product .oe_button_cart button:last-child {
.oe_ecommerce .oe_button_cart button:last-child {
background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #0088cc), color-stop(100%, #0076b1));
background: -webkit-linear-gradient(#0088cc, #0076b1);
background: -moz-linear-gradient(#0088cc, #0076b1);
background: -o-linear-gradient(#0088cc, #0076b1);
background: linear-gradient(#0088cc, #0076b1);
}
.oe_ecommerce .oe_product .oe_button_cart button:last-child.btn-success {
.oe_ecommerce .oe_button_cart button:last-child.btn-success {
background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #51a351), color-stop(100%, #418541));
background: -webkit-linear-gradient(#51a351, #418541);
background: -moz-linear-gradient(#51a351, #418541);
@@ -155,3 +158,14 @@
margin: 24px;
text-align: center;
}
.oe_ecommerce .oe_product_detail .oe_button_cart {
position: relative;
text-align: right;
}
.oe_ecommerce .oe_recommended a {
margin: 0 3px;
}
.oe_ecommerce .oe_recommended img {
max-width: 64px;
max-height: 64px;
}
@@ -67,6 +67,9 @@
right: 6px
top: 6px
text-align: right
form
input
margin-bottom: 0
.oe_product
vertical-align: top
position: relative
@@ -75,39 +78,49 @@
+border-radius(5px)
border: 1px solid rgba(0,0,0,.1)
+box-shadow(0 0 3px 1px rgba(0,0,0,.1))
.oe_button_cart
width: 100%
font-size: 11px
position: absolute
button
+text-shadow(0px 1px 1px rgba(0, 0, 0, 0.44))
overflow: hidden
text-align: center
font-size: 12px
margin: 0 auto
margin-bottom: 5px
padding: 2px
width: 50px
height: 22px
position: relative
&:first-child
@include background(linear-gradient(#aaaaaa,#999999))
span
opacity: 0.8
filter: alpha(opacity=80)
color: rgb(235, 18, 18)
position: absolute
left: +18px
top: 3px
font-size: 20px
&:last-child
@include background(linear-gradient(#0088cc,#0076b1))
&.btn-success
@include background(linear-gradient(#51a351, #418541))
.oe_button_cart
width: 100%
font-size: 11px
position: absolute
button
+text-shadow(0px 1px 1px rgba(0, 0, 0, 0.44))
overflow: hidden
text-align: center
font-size: 12px
margin: 0 auto
margin-bottom: 5px
padding: 2px
width: 50px
height: 22px
position: relative
&:first-child
@include background(linear-gradient(#aaaaaa,#999999))
span
opacity: 0.8
filter: alpha(opacity=80)
color: rgb(235, 18, 18)
position: absolute
left: +18px
top: 3px
font-size: 20px
&:last-child
@include background(linear-gradient(#0088cc,#0076b1))
&.btn-success
@include background(linear-gradient(#51a351, #418541))
form.oe_signup
display: none
.oe_search
form
width: 100%
margin: 24px
text-align: center
text-align: center
.oe_product_detail
.oe_button_cart
position: relative
text-align: right
.oe_recommended
a
margin: 0 3px
img
max-width: 64px
max-height: 64px
@@ -1,5 +1,5 @@
$(document).ready(function (){
$('.oe_ecommerce').on('click', '.oe_product .btn-success,.oe_product .btn-primary,.btn-inverse', function (e) {
$('.oe_ecommerce').on('click', '.oe_product .btn-success,.oe_product .btn-primary, .oe_product .btn-inverse, .oe_product_detail .btn-success,.oe_product_detail .btn-primary, .oe_product_detail .btn-inverse', function (e) {
var mycart = !!$('.oe_ecommerce .oe_mycart').size();
var $button = $(e.currentTarget);
var link = $button.hasClass('btn-inverse') ? '/shop/remove_cart' : '/shop/add_cart';
+33 -5
View File
@@ -110,6 +110,20 @@
</div>
</field>
</record>
<record id="product_recommended" model="ir.ui.view">
<field name="name">product_recommended</field>
<field name="type">qweb</field>
<field name="arch" type="xml">
<div class="oe_recommended media well well-small">
<h6>Other customers have also take this products:</h6>
<t t-foreach="recommended_products or []" t-as="product">
<a t-att-href="'/shop/product/%%s' %% product.id"><img t-att-src="'data:image/png;base64,' + product.image"/></a>
</t>
</div>
</field>
</record>
<!-- product -->
<record id="product" model="ir.ui.view">
@@ -119,11 +133,18 @@
<t t-call="website_sale.page">
<t t-set="title">Product</t>
<t t-set="shop_content">
<div clas="oe_commerce_product_display">
<h1><span t-record="product" t-field="name"><t t-esc="product.name"/></span></h1>
<img class="media-object" t-att-src="'data:image/png;base64,' + product.image"/>
<div t-record="product" t-field="description_sale"><t t-esc="product.description_sale"/></div>
<div class="oe_ecommerce_price" t-record="product" t-field="list_price"><t t-esc="product.list_price"/> €</div>
<div class="oe_product_detail">
<h1><span t-record="product" t-field="name"><t t-esc="product.name"/></span></h1>
<div class="oe_button_cart">
<button t-att-class="'btn btn-inverse %%s' %% (not quantity and 'oe_hidden' or '')" t-att-data-id="product.id"><span>X</span><i class="icon-shopping-cart icon-large"></i> </button>
<button t-att-class="'btn %%s' %% (quantity and 'btn-success' or 'btn-primary')" t-att-data-id="product.id">
<i class="icon-shopping-cart icon-large"></i>
<span class="oe_txt">(<span class="oe_quantity"><t t-esc="quantity"/></span>)</span>
</button>
</div>
<img class="media-object" t-att-src="'data:image/png;base64,' + product.image"/>
<div t-record="product" t-field="description_sale"><t t-esc="product.description_sale"/></div>
<div class="oe_ecommerce_price" t-record="product" t-field="list_price"><t t-esc="product.list_price"/> €</div>
</div>
</t>
</t>
@@ -145,6 +166,13 @@
<t t-set="quantity" t-value="int(line.product_uom_qty)"/>
<t t-call="website_sale.product_card"/>
</t>
<div class="media well well-small">
<form class="navbar-form">
<input name="code" type="text" placeholder="Reduction Code..."/>
<button class="btn">Submit your Reduction Code</button>
</form>
</div>
<t t-call="website_sale.product_recommended"/>
<t t-call="website_sale.total"/>
<a t-if="order.order_line" href="/shop/customer"><button class="btn btn-success">Next stage</button></a>
</span>