[WIP] ecommerce pagination

bzr revid: fva@openerp.com-20130806092344-noe43pgifa3rqr04
This commit is contained in:
Frédéric van der Essen 2013-08-06 11:23:44 +02:00
parent c7ae298ad5
commit c51b8953b4
5 changed files with 89 additions and 202 deletions

View File

@ -175,6 +175,10 @@ h5 {
float: right !important;
}
.thumbnail {
background: white;
}
/* ---- HACK FOR COVERING UP CK EDITOR BOGUS P INSERTION --- */
.navbar .nav > li > p {
margin-bottom: 0px;

View File

@ -131,6 +131,9 @@ h5
.nav > .pull-right
float: right !important //bugfix for flatly theme
.thumbnail
background: white
/* ---- HACK FOR COVERING UP CK EDITOR BOGUS P INSERTION --- */
.navbar .nav > li > p

View File

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import math
import openerp
import simplejson
from openerp.addons.web import http
@ -12,7 +13,9 @@ class Ecommerce(http.Controller):
def get_categories(self):
category_obj = request.registry.get('pos.category')
category_ids = category_obj.search(request.cr, openerp.SUPERUSER_ID, [('parent_id', '=', False)])
return category_obj.browse(request.cr, openerp.SUPERUSER_ID, category_ids)
categories = category_obj.browse(request.cr, openerp.SUPERUSER_ID, category_ids)
print categories
return categories
def get_current_order(self):
order = self.get_order(request.httprequest.session.get('ecommerce_order_id'))
@ -68,23 +71,46 @@ class Ecommerce(http.Controller):
product_ids.append(p[0])
return request.registry.get('product.product').browse(request.cr, request.uid, product_ids)
@http.route(['/shop', '/shop/category/<cat_id>'], type='http', auth="public")
def category(self, cat_id=0, offset=0, **post):
domain = [("sale_ok", "=", True)]
if post.get("search"):
domain += ['|', '|', ('name', 'ilike', "%%%s%%" % post.get("search")), ('desrequest.cription', 'ilike', "%%%s%%" % post.get("search")), ('pos_categ_id.name', 'ilike', "%%%s%%" % post.get("search"))]
if cat_id:
cat_id = cat_id and int(cat_id) or 0
domain = [('pos_categ_id.id', 'child_of', cat_id)] + domain
@http.route(['/shop', '/shop/category/<cat_id>', '/shop/category/<cat_id>/page/<page>', '/shop/page/<page>'], type='http', auth="public")
def category(self, cat_id=0, page=0, **post):
product_obj = request.registry.get('product.product')
domain = [("sale_ok", "=", True)]
if cat_id:
cat_id = int(cat_id)
domain = [('pos_categ_id.id', 'child_of', cat_id)] + domain
product_count = len(product_obj.search(request.cr, request.uid, domain))
page_count = int(math.ceil(product_count / 20.0))
#if post.get("search"):
# domain += ['|', '|', ('name', 'ilike', "%%%s%%" % post.get("search")), ('description', 'ilike', "%%%s%%" % post.get("search")), ('pos_categ_id.name', 'ilike', "%%%s%%" % post.get("search"))]
page = max(1,min(int(page),page_count))
offset = (page-1) * 20
if page_count <= 5 or page <= 3:
pmin = 1
pmax = min(page_count,5)
elif page >= page_count - 2:
pmin = page_count - 4
pmax = page_count
else:
pmin = page - 2
pmax = page + 2
pages = range(pmin, pmax+1)
product_ids = product_obj.search(request.cr, request.uid, domain, limit=20, offset=offset)
values = {
'current_category': cat_id,
'products': product_obj.browse(request.cr, request.uid, product_ids),
'search': post.get("search"),
'page_count': page_count,
'pages': pages,
'page': page,
}
html = self.render("website_sale.products", values)
return html

View File

@ -1,156 +0,0 @@
@import "compass/css3"
//.oe_ecommerce
.oe_total
font-size: 13px
margin-top: 10px
td
padding: 5px 10px
table
width: auto
td:last-child
text-align: right
th:last-child
text-align: center
.oe_products
.oe_product
.oe_hidden
visibility: hidden
.pull-left
margin: 0
float: none
.oe_ecommerce_description
display: none
h4
text-align: center
+text-shadow(0px 1px 1px rgba(200, 200, 200,.2))
margin-bottom: 16px
img
max-height: 110px
max-width: 130px
margin: 0 auto
padding-bottom: 14px
text-align: center
display: inline-block
padding: 4px
width: 180px
height: 220px
margin-right: 15px
margin-left: 3px
padding-top: 8px
&:nth-child(3n)
margin-right: 0
.oe_ecommerce_price
width: 100%
position: absolute
bottom: 44px
+text-shadow(0px 1px 3px rgba(255, 255, 255, 0.7))
text-align: center
font-size: 25px
span
font-weight: bold
.oe_button_cart
bottom: 5px
left: 0
.btn-inverse
display: none
.oe_mycart
.oe_product
display: inline-block
width: 250px
margin-left: 0px
float: none
margin-right: 16px
padding: 8px 5px 6px 10px
> .pull-left
width: 84px
height: 64px
img
max-width: 64px
max-height: 64px
margin: auto
.oe_button_cart
position: static
right: 6px
top: 6px
form
input
margin-bottom: 0
.oe_product
vertical-align: top
position: relative
margin-top: 0
margin-bottom: 15px
+border-radius(5px)
border: 1px solid rgba(0,0,0,.1)
+box-shadow(0px 1px 3px 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
height: 22px
position: relative
&.btn-inverse
@include background(linear-gradient(#aaaaaa,#999999))
&.btn-primary
@include background(linear-gradient(#0088cc,#0076b1))
&.btn-success
@include background(linear-gradient(#51a351, #418541))
.oe_search
form
width: 100%
margin: 24px
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
.oe_checkout
.css_required
input, select
//background-color: #d2d2ff !important
h4
border-bottom: 1px solid #ddd
margin-right: 30px
input:not([type="radio"]):not([type="checkbox"]):not([type="image"])
height: 20px
input[type="image"]
height: 30px
label
> input:not([type="radio"]):not([type="checkbox"]), > div, > select
display: block
margin-top: 3px
select
margin-top: 3px
> div > input
margin-bottom: 0
.css_payments
clear: both
.css_payment
position: relative
width: 80px
overflow: hidden
height: 30px
text-align: center
padding: 10px 10px 0 0
.css_error_payment
width: 100%
height: 100%
position: absolute
top: +O
left: +0
cursor: pointer

View File

@ -54,14 +54,8 @@
<t t-set="title">Shop - <t t-raw="title">Categories</t></t>
<div class="container mt48 oe_ecommerce">
<div class="row">
<div class="span4 css_noprint">
<ul class="nav nav-list">
<t t-foreach="categories" t-as="category">
<t t-call="website_sale.categories_recursive"/>
</t>
</ul>
</div>
<t t-raw="shop_content"></t>
<t t-call='website_sale.categories' />
<t t-raw="shop_content" />
</div>
</div>
</t>
@ -69,9 +63,20 @@
<!-- List of categories -->
<template id="categories">
<div class="span4">
<ul class="nav nav-list">
<li t-att-class=" '' if current_category else 'active' " class='active'><a href='/shop/'>All Products</a></li>
<t t-foreach="categories" t-as="category">
<t t-call="website_sale.categories_recursive"/>
</t>
</ul>
</div>
</template>
<template id="categories_recursive">
<li t-att-class="category.id == current_category and 'active' or ''">
<a t-att-href="'/shop/category/%%s' %% category.id"><span t-field="category.name"><t t-esc="category.name"/></span></a>
<a t-att-href="'/shop/category/%%s' %% category.id" t-field="category.name"></a>
<ul t-if="category.child_id" class="nav nav-list">
<t t-foreach="category.child_id" t-as="category">
<t t-call="website_sale.categories_recursive"/>
@ -82,23 +87,27 @@
<!-- Product list -->
<template id="product_pager">
<div t-if="page_count != 1" t-att-class=" (classname if classname else '') + ' pagination'">
<ul>
<li t-att-class=" 'disabled' if page == 1 else '' " ><a t-att-href=" '#' if page == 1 else ('/shop/category/%%s/page/%%s' %% (current_category, max(0,page-1))) ">Prev</a></li>
<t t-foreach="pages" t-as="p">
<li t-att-class=" 'active' if p == page else '' " ><a t-att-href=" '/shop/category/%%s/page/%%s' %% (current_category, p)" t-raw='p'></a></li>
</t>
<li t-att-class=" 'disabled' if page == page_count else '' "><a t-att-href=" '#' if page == page_count else ('/shop/category/%%s/page/%%s' %% (current_category, min(page_count,page+1))) ">Next</a></li>
</ul>
</div>
</template>
<template id="products">
<t t-call="website_sale.page">
<t t-set="title">Product</t>
<t t-set="shop_content">
<div class='span8 navbar navbar-inverse'>
<div class='navbar-inner'>
<div class='pagination pull-left'>
<ul>
<li><a href='#'>Prev</a></li>
<li class='active'><a href='#'>1</a></li>
<li><a href='#'>2</a></li>
<li><a href='#'>3</a></li>
<li><a href='#'>4</a></li>
<li><a href='#'>5</a></li>
<li><a href='#'>Next</a></li>
</ul>
</div>
<t t-call="website_sale.product_pager" >
<t t-set="classname">pull-left</t>
</t>
<form action="/shop" method="get" class="navbar-search pull-right">
<input type="text" name="search" class="search-query span2" placeholder="Search" t-att-value="search or '' or ''"/>
</form>
@ -113,17 +122,9 @@
</div>
</div>
<div class="span8 offset4 text-center">
<div class='pagination'>
<ul>
<li><a href='#'>Prev</a></li>
<li class='active'><a href='#'>1</a></li>
<li><a href='#'>2</a></li>
<li><a href='#'>3</a></li>
<li><a href='#'>4</a></li>
<li><a href='#'>5</a></li>
<li><a href='#'>Next</a></li>
</ul>
</div>
<t t-call="website_sale.product_pager" >
<t t-set="classname"></t>
</t>
</div>
</t>
</t>
@ -138,7 +139,7 @@
<img class="img-rounded" t-att-src="'data:image/png;base64,' + product.image"/>
</a>
<div>
<div t-field="product.description_sale">FIXME</div>
<div t-field="product.description_sale"></div>
<div><span t-field="product.list_price"></span></div>
<div class="mb8 mt8">
<button t-att-class="'btn mb8 btn-small btn-inverse %%s' %% (not quantity and 'hidden' or '')" t-att-data-id="product.id">Remove one</button>
@ -151,11 +152,20 @@
</template>
<template id="product_recommended">
<div class="oe_recommended media well well-small" t-if="recommended_products">
<h6>Other customers have also take this products:</h6>
<div class="well mt32" t-if="recommended_products">
<h4>Customers who have bought this item also bought</h4>
<div class='row mt16'>
<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>
<div class='span2 thumbnail'>
<a t-att-href="'/shop/product/%%s' %% product.id">
<div class='mt16 text-center'>
<img t-att-src="'data:image/png;base64,' + product.image"/>
<h5 t-field='product.name'></h5>
</div>
</a>
</div>
</t>
</div>
</div>
</template>
@ -180,7 +190,7 @@
</div>
<img class="media-object" t-att-src="'data:image/png;base64,' + product.image"/>
<div t-field="product.description_sale"></div>
<div class="oe_ecommerce_price" t-field="product.list_price"><t t-esc="product.list_price"/> </div>
<div class="oe_ecommerce_price"><t t-field="product.list_price" /></div>
<t t-call="website_sale.product_recommended"/>
</div>
</t>