Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
venshop
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
huanvl
venshop
Commits
62fea398
Commit
62fea398
authored
Oct 24, 2013
by
vulehuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finish category list page
parent
1b6d61d5
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
2 deletions
+54
-2
venshop_app/app/controllers/product_categories_controller.rb
+8
-0
venshop_app/app/models/product.rb
+12
-0
venshop_app/app/views/product_categories/show.html.erb
+34
-2
No files found.
venshop_app/app/controllers/product_categories_controller.rb
View file @
62fea398
class
ProductCategoriesController
<
ApplicationController
class
ProductCategoriesController
<
ApplicationController
def
show
def
show
term
=
ProductCategory
.
find
(
params
[
:id
])
if
term
==
nil
@items
=
Array
.
new
@title
=
''
else
@items
=
Product
.
get_products_by_category
(
product_category_id:
params
[
:id
],
page:
params
[
:page
],
limit:
16
)
@title
=
term
.
name
end
end
end
end
end
venshop_app/app/models/product.rb
View file @
62fea398
...
@@ -10,4 +10,15 @@ class Product < ActiveRecord::Base
...
@@ -10,4 +10,15 @@ class Product < ActiveRecord::Base
limit
=
options
[
:limit
]
limit
=
options
[
:limit
]
return
Product
.
select
(
'id, name, image_medium, price, price_currency'
).
where
(
availability:
'instock'
).
order
(
'created_at DESC'
).
order
(
'updated_at DESC'
).
order
(
'name'
).
limit
(
limit
)
return
Product
.
select
(
'id, name, image_medium, price, price_currency'
).
where
(
availability:
'instock'
).
order
(
'created_at DESC'
).
order
(
'updated_at DESC'
).
order
(
'name'
).
limit
(
limit
)
end
end
# Returns products in a category
def
self
.
get_products_by_category
(
options
=
{
limit:
16
,
product_category_id:
0
})
limit
=
options
[
:limit
]
product_category_id
=
options
[
:product_category_id
]
page
=
options
[
:page
]
return
Product
.
select
(
'id, name, image_medium, price, price_currency'
)
.
where
(
availability:
'instock'
,
product_category_id:
product_category_id
)
.
paginate
(
:page
=>
page
,
:per_page
=>
limit
)
.
order
(
'created_at DESC'
).
order
(
'updated_at DESC'
).
order
(
'name'
)
end
end
end
\ No newline at end of file
venshop_app/app/views/product_categories/show.html.erb
View file @
62fea398
<h1>
ProductCategories#show
</h1>
<!-- Recommended Items -->
<p>
Find me in app/views/product_categories/show.html.erb
</p>
<div
class=
"body-box grid-view"
>
<h2
class=
"sprite-2"
>
<%=
@title
%>
<span
class=
"sprite-2"
></span>
</h2>
<%
@items
.
each_slice
(
4
)
do
|
row
|
%>
<div
class=
"row"
>
<%
row
.
each
do
|
obj
|
url
=
product_path
(
obj
)
add_to_card_url
=
cards_path
+
"?product_id="
+
obj
.
id
.
to_s
%>
<div
class=
"col-md-3 col-sm-3"
>
<div
class=
"item"
>
<h4>
<a
href=
"
<%=
url
%>
"
title=
"
<%=
obj
.
name
%>
"
>
<%=
obj
.
name
%>
</a>
</h4>
<a
href=
"
<%=
url
%>
"
class=
"thumbnail"
title=
"
<%=
obj
.
name
%>
"
><img
src=
"
<%=
obj
.
image_medium
%>
"
alt=
"
<%=
obj
.
name
%>
"
></a>
<div
class=
"price"
>
Price:
<span>
<%=
number_with_delimiter
(
obj
.
price
)
%>
<%=
obj
.
price_currency
%>
</span>
</div>
<div
class=
"action"
>
<a
class=
"view-detail"
href=
"
<%=
url
%>
"
title=
"
<%=
obj
.
name
%>
"
>
Detail
</a><a
class=
"order"
href=
"
<%=
add_to_card_url
%>
"
>
Order
</a>
</div>
</div>
</div>
<%
end
%>
</div>
<%
end
%>
<%=
will_paginate
@items
,
renderer:
BootstrapPagination
::
Rails
%>
<div
class=
"clearfix"
></div>
</div>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment