[IMP] website_sale: add product in website

bzr revid: chm@openerp.com-20130904084958-6rq5xu0xjwzcv399
This commit is contained in:
Christophe Matthieu 2013-09-04 10:49:58 +02:00
parent 5373e450f4
commit 7704ce7e03
7 changed files with 47 additions and 9 deletions

View File

@ -65,6 +65,10 @@
outline: none !important;
}
.css_non_editable_mode_hidden {
display: none
}
.oe_carousel_options {
cursor: pointer;
position: absolute;

View File

@ -58,6 +58,9 @@
.oe_editable:focus
outline: none !important
.css_non_editable_mode_hidden:
display: none
.oe_carousel_options
cursor: pointer
position: absolute

View File

@ -129,6 +129,7 @@
this.$buttons.edit.prop('disabled', true);
this.$('#website-top-view').hide();
this.$('#website-top-edit').show();
$('.css_non_editable_mode_hidden').removeClass("css_non_editable_mode_hidden");
// this.$buttons.cancel.add(this.$buttons.snippet).prop('disabled', false)
// .add(this.$buttons.save)

View File

@ -394,7 +394,7 @@
</template>
<template id="publish">
<a href="#" t-att-data-id="object.id" t-att-data-object="object._name" t-att-data-publish="object.website_published and 'on' or 'off'" class="pull-right js_publish" t-if="editable" t-ignore="true">
<a href="#" t-att-data-id="object.id" t-att-data-object="object._name" t-att-data-publish="object.id and object.website_published and 'on' or 'off'" class="pull-right js_publish" t-if="editable" t-ignore="true">
<span t-attf-class="label label-success css_publish">Publish</span>
<span t-attf-class="label label-danger css_unpublish">Unpublish</span>
<span t-attf-class="label label-success css_published">Published</span>

View File

@ -109,18 +109,33 @@ class Ecommerce(http.Controller):
product_id = product_id and int(product_id) or 0
product_obj = request.registry.get('product.template')
category_obj = request.registry.get('product.public.category')
context = {'pricelist': self.get_pricelist()}
category_list = category_obj.name_get(request.cr, request.uid, category_obj.search(request.cr, request.uid, [(1,'=',1)]))
category_list = sorted(category_list, key=lambda category: category[1])
product = product_obj.browse(request.cr, request.uid, product_id, context=context)
values = website.get_rendering_context({
'category_id': post.get('category_id') and int(post.get('category_id')) or None,
'search': post.get("search"),
'categories': self.get_categories(),
'category_list': category_list,
'product': product,
})
return website.render("website_sale.product", values)
@http.route(['/shop/add_product/'], type='http', auth="public")
def add_product(self, **post):
product_id = request.registry.get('product.product').create(request.cr, request.uid, {'name': 'New Product'})
return werkzeug.utils.redirect("/shop/product/%s/" % product_id)
@http.route(['/shop/change_category/<product_id>/'], type='http', auth="public")
def edit_product(self, product_id=0, **post):
request.registry.get('product.template').write(request.cr, request.uid, [int(product_id)], {'public_categ_id': int(post.get('public_categ_id', 0))})
return "1"
def get_pricelist(self):
if not request.httprequest.session.get('ecommerce_pricelist'):
self.change_pricelist(None)

View File

@ -30,6 +30,12 @@ $(document).ready(function () {
});
}
});
$(".oe_website_sale #product_detail select[name='public_categ_id']").change(function () {
var $select = $(this);
$.get("/shop/change_category/"+$select.data('id')+"/", {'public_categ_id': $select.val()});
});
// hack to add and rome from cart with json
$('.oe_website_sale a[href*="/add_cart/"], a[href*="/remove_cart/"]').on('click', function (ev) {

View File

@ -51,6 +51,7 @@
</t>
<t t-set="title">Shop - <t t-raw="title">Categories</t></t>
<div class="container oe_website_sale">
<a t-if="editable" href="/shop/add_product/" class="btn btn-default pull-right">Create New Product</a>
<div class="row">
<div class="col-md-12" id="shop_content">
<t t-raw="shop_content" />
@ -142,14 +143,13 @@
<t t-call="website_sale.layout">
<t t-set="title">Product</t>
<t t-set="shop_content">
<form t-attf-action="/shop/#{ category_id and ('category/%s/' % category_id) or ''}" method="get" class="pull-right">
<input type="text" name="search" class="search-query col-md-2 form-control" placeholder="Search..." t-att-value="search or '' or ''"/>
</form>
<div class="clearfix"/>
<div id="product_detail">
<t t-call="website.publish"><t t-set="object" t-value="product"/></t>
<h1 t-field="product.name"></h1>
<h1 t-field="product.name">Product Name</h1>
<a t-if="len(product.product_variant_ids) &lt;= 1" t-attf-href="./add_cart/?product_id=#{ product.id }" class="btn btn-default btn-sm btn-success pull-right">Add to basket</a>
<form t-if="len(product.product_variant_ids) > 1" action="./add_cart/" class="pull-right">
<label label-default="label-default" class="radio" t-foreach="product.product_variant_ids" t-as="product">
@ -160,15 +160,24 @@
<button class="btn btn-sm btn-success">Add to basket</button>
</form>
<img class="media-object img-responsive" t-att-src="product.img('image_medium')"/>
<h2 t-if="editable">Description for Quotations</h2>
<div t-if="editable" t-field="product.description_sale"><br/></div>
<h2 t-if="editable">Description</h2>
<div t-field="product.website_description"><br/></div>
<div t-if="editable" t-att-class="'well css_non_editable_mode_hidden'">
<h2>Category<br/><small>Select a the public category where this product appear</small></h2>
<select name="public_categ_id" class="form-control" t-att-data-id="product.id">
<option value="0">Choose a Category</option>
<t t-foreach="category_list" t-as="cat">
<option t-att-value="cat[0]" t-att-selected="cat[0] == product.public_categ_id.id and 'selected'"><t t-esc="cat[1]"/></option>
</t>
</select>
<h2>Short Description for Quotations<br/><small>Displayed in your shop categories and for quotations</small></h2>
<div class="form-control" t-field="product.description_sale">Enter a short description for this product</div>
</div>
<div t-field="product.website_description">Enter a short Website description for this product</div>
<div>
<t t-if="product.product_variant_ids[0].lst_price != product.product_variant_ids[0].price">
<h5 class="text-error" style="text-decoration: line-through;"><t t-esc="product.product_variant_ids[0].lst_price" /></h5>
</t>
<h5 class="text-error" style="text-decoration: line-through;" title="Price without reduction"><t t-field="product.product_variant_ids[0].lst_price" /></h5>
<h4><t t-esc="product.product_variant_ids[0].price" /></h4>
</t>
<h4 t-if="product.product_variant_ids[0].lst_price == product.product_variant_ids[0].price"><t t-field="product.product_variant_ids[0].lst_price" /></h4>
</div>
</div>
</t>