posting feature: list user items and warning in product detail page
Showing
| ... | @@ -8,6 +8,12 @@ class ProductsController < ApplicationController | ... | @@ -8,6 +8,12 @@ class ProductsController < ApplicationController |
| def show | def show | ||
| @product = Product.find(params[:id]) | @product = Product.find(params[:id]) | ||
Please
register
or
sign in
to reply
|
|||
| if !@product.status | |||
| user = current_user | |||
| if user == nil || @product.user_id != user.id | |||
|
|||
| redirect_to products_path | |||
| end | |||
| end | |||
| product_category = ProductCategory.find(@product.product_category_id) | product_category = ProductCategory.find(@product.product_category_id) | ||
| if product_category != nil | if product_category != nil | ||
|
|||
| add_breadcrumb product_category.name, product_category_path(product_category) | add_breadcrumb product_category.name, product_category_path(product_category) | ||
| ... | @@ -25,6 +31,8 @@ class ProductsController < ApplicationController | ... | @@ -25,6 +31,8 @@ class ProductsController < ApplicationController |
| @product = Product.new(product_params) | @product = Product.new(product_params) | ||
|
|||
| user = current_user | user = current_user | ||
| @product.user_id = user.id | @product.user_id = user.id | ||
| @product.status = false | |||
| @product.availability = 'instock' | |||
| if @product.save | if @product.save | ||
| flash[:success] = "Add new product successfully!" | flash[:success] = "Add new product successfully!" | ||
| redirect_to @product | redirect_to @product | ||
| ... | @@ -34,12 +42,16 @@ class ProductsController < ApplicationController | ... | @@ -34,12 +42,16 @@ class ProductsController < ApplicationController |
| end | end | ||
| def user_items | def user_items | ||
| add_breadcrumb "My items", url_for(action: 'user_items') | |||
| user = current_user | |||
| all_status = user != nil && user.id.to_s == params[:user_id].to_s | |||
| @products = Product.get_user_items(limit: 16, page: params[:page], user_id: params[:user_id], all_status: all_status) | |||
| end | end | ||
| private | private | ||
| def product_params | def product_params | ||
| params.require(:product).permit(:name, :description, :headline, :availability, :code, :condition, :image_small, :image_medium, :price_currency, :price, :product_category_id) | params.require(:product).permit(:name, :description, :headline, :code, :condition, :image_small, :image_medium, :price_currency, :price, :product_category_id) | ||
| end | end | ||
| # Before filters | # Before filters | ||
| ... | ... |
| ... | @@ -11,7 +11,10 @@ | ... | @@ -11,7 +11,10 @@ |
| </div> | </div> | ||
| <div class="block-user-action"> | <div class="block-user-action"> | ||
| <div class="btn-group"> | <div class="btn-group"> | ||
| <% if signed_in? %> | <% | ||
|
|||
| if signed_in? | |||
| user = current_user | |||
| %> | |||
| <a href="<%= cards_path %>" class="btn btn-danger"> <span class="glyphicon glyphicon-shopping-cart"></span> Your cart | <a href="<%= cards_path %>" class="btn btn-danger"> <span class="glyphicon glyphicon-shopping-cart"></span> Your cart | ||
| </a> | </a> | ||
| <a data-toggle="dropdown" href="#" class="btn btn-default"><span class="glyphicon glyphicon-list"></span> My actions</a> | <a data-toggle="dropdown" href="#" class="btn btn-default"><span class="glyphicon glyphicon-list"></span> My actions</a> | ||
| ... | @@ -22,7 +25,7 @@ | ... | @@ -22,7 +25,7 @@ |
| <% end %> | <% end %> | ||
| </li> | </li> | ||
| <li> | <li> | ||
| <%= link_to url_for(controller: 'products', action:'user_items') do %> | <%= link_to url_for(controller: 'products', action:'user_items', user_id: user.id) do %> | ||
| <span class="glyphicon glyphicon-home"></span> My products | <span class="glyphicon glyphicon-home"></span> My products | ||
| <% end %> | <% end %> | ||
| </li> | </li> | ||
| ... | ... |
| <% | <% | ||
| if items == nil | if items == nil || items.empty? | ||
|
|||
| return '' | |||
| end | |||
| items.each_slice(4) do |row| | |||
| %> | %> | ||
| <div class="row"> | <p>No products available.</p> | ||
| <% | <% | ||
| row.each do |obj| | else | ||
| url = product_path(obj) | items.each_slice(4) do |row| | ||
| add_to_card_url = cards_path + "?product_id=" + obj.id.to_s | |||
| %> | %> | ||
| <div class="col-md-3 col-sm-3"> | <div class="row"> | ||
| <div class="item"> | <% | ||
| <h4> | row.each do |obj| | ||
| <a href="<%= url %>" title="<%= obj.name %>"><%= obj.name %></a> | url = product_path(obj) | ||
| </h4> | add_to_card_url = cards_path + "?product_id=" + obj.id.to_s | ||
| <a href="<%= url %>" class="thumbnail" title="<%= obj.name %>"><img src="<%= obj.image_medium %>" alt="<%= obj.name %>"></a> | %> | ||
| <div class="price"> | <div class="col-md-3 col-sm-3"> | ||
| Price: <span><%= number_with_delimiter(obj.price) %> <%= obj.price_currency %></span> | <div class="item"> | ||
| </div> | <h4> | ||
| <div class="action"> | <a href="<%= url %>" title="<%= obj.name %>"><%= obj.name %></a> | ||
| <a class="view-detail" href="<%= url %>" title="<%= obj.name %>">Detail</a><a class="order" | </h4> | ||
| href="<%= add_to_card_url %>">Order</a> | <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> | </div> | ||
| <% end %> | |||
| </div> | </div> | ||
| </div> | |||
| <% end %> | <% end %> | ||
| </div> | <% end %> | ||
| <% end %> | |||
| \ No newline at end of file |