[FIX] website_sale: edit, suggested products

bzr revid: chm@openerp.com-20131002162810-cjo5r9itmuc0x71o
This commit is contained in:
Christophe Matthieu 2013-10-02 18:28:10 +02:00
parent 0a3e643b18
commit adef9bc3df
4 changed files with 49 additions and 6 deletions

View File

@ -379,10 +379,14 @@ class Ecommerce(http.Controller):
self.change_pricelist(post.get('promo'))
suggested_ids = []
product_ids = []
if order:
for line in order.order_line:
suggested_ids += [p.id for p in line.product_id and line.product_id.suggested_product_ids or [] for line in order.order_line]
suggested_ids = prod_obj.search(request.cr, request.uid, [('id', 'in', suggested_ids)], context=request.context)
product_ids.append(line.product_id.id)
suggested_ids = list(set(suggested_ids) - set(product_ids))
if suggested_ids:
suggested_ids = prod_obj.search(request.cr, request.uid, [('id', 'in', suggested_ids)], context=request.context)
# select 3 random products
suggested_products = []

View File

@ -32,6 +32,14 @@ class product_pricelist(osv.Model):
class product_template(osv.Model):
_inherit = "product.template"
_order = 'website_sequence desc, website_published, name'
def _website_url(self, cr, uid, ids, field_name, arg, context=None):
res = {}
base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url')
for prod in self.browse(cr, uid, ids, context=context):
res[prod.id] = "%s/shop/product/%s/" % (base_url, prod.product_variant_ids[0].id)
return res
_columns = {
'website_published': fields.boolean('Available in the website'),
'website_description': fields.html('Description for the website'),
@ -41,6 +49,7 @@ class product_template(osv.Model):
'website_size_y': fields.integer('Size Y'),
'website_style_ids' : fields.many2many('website.product.style','product_website_style_rel', 'product_id', 'style_id', 'Styles'),
'website_sequence': fields.integer('Sequence', help="Determine the display order in the Website E-commerce"),
'website_url': fields.function(_website_url, string="Website url"),
}
_defaults = {
'website_size_x': 1,

View File

@ -36,7 +36,7 @@ $(document).ready(function () {
});
// hack to add and rome from cart with json
$('.oe_website_sale a[href*="/add_cart/"],.oe_website_sale a[href*="/remove_cart/"]').on('click', function (ev) {
$('.oe_website_sale a.js_add_cart_json').on('click', function (ev) {
ev.preventDefault();
var $link = $(ev.currentTarget);
var product = $link.attr("href").match(/product_id=([0-9]+)/);

View File

@ -40,6 +40,36 @@
</field>
</field>
</record>
<record model="ir.ui.view" id="product_template_form_view">
<field name="name">product.template.product.website.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<!-- add state field in header -->
<xpath expr="//sheet" position="before">
<div class="oe_form_box_info oe_text_center" attrs="{'invisible': [('sale_ok', '=', False)]}">
<p attrs="{'invisible': [('website_published', '=', True)]}">
This product is <b>not available</b> for public user in your ecommerce.
</p>
<p attrs="{'invisible': [('website_published', '=', False)]}">
This product is <b>available</b> for public user in your ecommerce.
</p>
<p>Website view: <field class="oe_inline" name="website_url" widget="url"/></p>
</div>
</xpath>
<xpath expr="//group[@string='Product Type']" position="inside">
<field name="website_published"/>
</xpath>
<xpath expr="//page[@string='Information']" position="inside">
<group colspan="4" string="Products On Ecommerce">
<field name="suggested_product_ids" widget="many2many_tags"/>
<field name="website_style_ids" widget="many2many_tags"/>
</group>
</xpath>
</field>
</record>
<!-- Layout add nav and footer -->
@ -232,7 +262,7 @@
<template id="add_to_basket" inherit_option_id="website_sale.products_cart" name="Add to Cart">
<xpath expr="//div[@class='product_price']" position="inside">
<a t-href="./add_cart/?product_id=#{ product.id }">
<a t-href="./add_cart/?product_id=#{ product.id }" class="js_add_cart_json">
<span class="icon-shopping-cart"/>
</a>
</xpath>
@ -302,7 +332,7 @@
</div><div class="col-sm-5 col-md-5 col-lg-4 col-lg-offset-1">
<h1 t-field="product.name">Product Name</h1>
<form t-action="./add_cart/">
<form t-action="./add_cart/" class="js_add_cart_json">
<input type="hidden" t-if="len(product.product_variant_ids) &lt;= 1" name="product_id" t-att-value="product.id"/>
<t t-if="len(product.product_variant_ids) &gt; 1">
<label label-default="label-default" class="radio" t-foreach="product.product_variant_ids" t-as="product">
@ -430,14 +460,14 @@
<td>
<div class="input-group">
<span class="input-group-addon">
<a t-href="./remove_cart/?order_line_id=#{ line.id }" t-att-data-id="line.id" class="mb8">
<a t-href="./remove_cart/?order_line_id=#{ line.id }" t-att-data-id="line.id" class="mb8 js_add_cart_json">
<span class="icon-minus"/>
</a>
</span>
<input type="text" class="js_quantity form-control"
t-att-data-id="line.id" t-att-value="int(line.product_uom_qty)"/>
<span class="input-group-addon">
<a t-href="./add_cart/?order_line_id=#{ line.id }" t-att-data-id="line.id" class="mb8 float_left">
<a t-href="./add_cart/?order_line_id=#{ line.id }" t-att-data-id="line.id" class="mb8 float_left js_add_cart_json">
<span class="icon-plus"/>
</a>
</span>