[IMP] website_sale: add product variants
bzr revid: chm@openerp.com-20130819131929-x75ib5y6dcu4bcu7
This commit is contained in:
parent
571d9044d6
commit
55b1378e77
|
@ -328,6 +328,7 @@ class product_template(osv.osv):
|
|||
'mes_type': fields.selection((('fixed', 'Fixed'), ('variable', 'Variable')), 'Measure Type'),
|
||||
'seller_ids': fields.one2many('product.supplierinfo', 'product_id', 'Supplier'),
|
||||
'company_id': fields.many2one('res.company', 'Company', select=1),
|
||||
'product_ids': fields.one2many('product.product', 'product_tmpl_id', 'Product Variants'),
|
||||
}
|
||||
|
||||
def _get_uom_id(self, cr, uid, *args):
|
||||
|
|
|
@ -77,10 +77,18 @@ class Ecommerce(http.Controller):
|
|||
|
||||
product_ids = product_obj.search(request.cr, request.uid, domain, limit=step, offset=pager['offset'])
|
||||
|
||||
products = product_obj.browse(request.cr, request.uid, product_ids)
|
||||
tmpl_ids = []
|
||||
product_tmpl_ids = []
|
||||
for product in products:
|
||||
if product.product_tmpl_id.id not in tmpl_ids:
|
||||
tmpl_ids.append(product.product_tmpl_id.id)
|
||||
product_tmpl_ids.append(product)
|
||||
|
||||
values = website.get_rendering_context({
|
||||
'categories': self.get_categories(),
|
||||
'current_category': cat_id,
|
||||
'products': product_obj.browse(request.cr, request.uid, product_ids),
|
||||
'products': product_tmpl_ids,
|
||||
'search': post.get("search"),
|
||||
'pager': pager,
|
||||
})
|
||||
|
@ -96,9 +104,11 @@ class Ecommerce(http.Controller):
|
|||
|
||||
line = [line for line in order.order_line if line.product_id.id == product_id]
|
||||
|
||||
product = product_obj.browse(request.cr, request.uid, product_id)
|
||||
values = website.get_rendering_context({
|
||||
'categories': self.get_categories(),
|
||||
'product': product_obj.browse(request.cr, request.uid, product_id),
|
||||
'product': product,
|
||||
'product_variants': product.product_tmpl_id.product_ids,
|
||||
})
|
||||
return website.render("website_sale.product", values)
|
||||
|
||||
|
@ -174,7 +184,7 @@ class Ecommerce(http.Controller):
|
|||
|
||||
return quantity
|
||||
|
||||
@http.route(['/shop/add_cart/<product_id>/', '/shop/<path:path>/add_cart/<product_id>/'], type='http', auth="public")
|
||||
@http.route(['/shop/<path:path>/add_cart/', '/shop/add_cart/', '/shop/add_cart/<product_id>/', '/shop/<path:path>/add_cart/<product_id>/'], type='http', auth="public")
|
||||
def add_cart(self, path=None, product_id=0, remove=None):
|
||||
self.add_product_to_cart(product_id, number=(remove and -1 or 1))
|
||||
if path:
|
||||
|
|
|
@ -140,7 +140,15 @@
|
|||
<div id="product_detail">
|
||||
<t t-call="website.publish"><t t-set="object" t-value="product"/></t>
|
||||
<h2 t-field="product.name"></h2>
|
||||
<a t-attf-href="./add_cart/#{ product.id }/" class="btn btn-small btn-success pull-right">Add to cart</a>
|
||||
<a t-if="not product_variants" t-attf-href="/shop/add_cart/#{ product.id }/" class="btn btn-small btn-success pull-right">Add to cart</a>
|
||||
<form t-if="product_variants" action="/shop/add_cart/" class="pull-right">
|
||||
<select name="product_id">
|
||||
<t t-foreach="product_variants" t-as="product">
|
||||
<option t-att-value="product.id"><t t-esc="product.variants"/></option>
|
||||
</t>
|
||||
</select><br/>
|
||||
<button class="btn btn-small btn-success">Add to cart</button>
|
||||
</form>
|
||||
<img class="media-object" t-att-src="product.img('image')"/>
|
||||
<div t-field="product.description_website"></div>
|
||||
<div><t t-field="product.list_price" />€</div>
|
||||
|
@ -200,7 +208,9 @@
|
|||
<a t-attf-href="/shop/product/#{ line.product_id.id }/"><img class="img-rounded" t-att-src="line.product_id.img('image_small')"/></a>
|
||||
</td>
|
||||
<td>
|
||||
<a t-attf-href="/shop/product/#{ line.product_id.id }/"><span t-field="line.product_id.name"/></a><br/>
|
||||
<a t-attf-href="/shop/product/#{ line.product_id.id }/">
|
||||
<span t-field="line.product_id.name"/> <t t-if="line.product_id.variants">(<small t-field="line.product_id.variants"/>)</t>
|
||||
</a><br/>
|
||||
<small t-field="line.product_id.description_sale"/>
|
||||
</td>
|
||||
<td>
|
||||
|
@ -325,7 +335,7 @@
|
|||
<tbody t-if="order.order_line">
|
||||
<t t-foreach="order.order_line" t-as="line">
|
||||
<tr>
|
||||
<td><t t-esc="line.name"/></td>
|
||||
<td><t t-esc="line.name"/> <t t-if="line.product_id.variants">(<small t-field="line.product_id.variants"/>)</t></td>
|
||||
<td><t t-esc="line.product_uom_qty"/></td>
|
||||
<td><t t-esc="line.product_id.list_price"/>€</td>
|
||||
</tr>
|
||||
|
|
|
@ -49,14 +49,14 @@ class product_product(osv.osv):
|
|||
AND sol.product_id not in (%s)
|
||||
GROUP BY sol.product_id
|
||||
ORDER BY COUNT(sol.order_id) DESC
|
||||
LIMIT 8
|
||||
LIMIT 10
|
||||
"""
|
||||
cr.execute(query, (id, id))
|
||||
for p in cr.fetchall():
|
||||
product_ids.append(p[0])
|
||||
|
||||
# search to apply access rules
|
||||
product_ids = self.search(cr, uid, [("id", "in", product_ids)])
|
||||
product_ids = self.search(cr, uid, [("id", "in", product_ids)], limit=3)
|
||||
return self.browse(cr, uid, product_ids)
|
||||
|
||||
def img(self, cr, uid, ids, field='image_small', context=None):
|
||||
|
|
Loading…
Reference in New Issue