Commit 7e199c12 by Hoang Phuc Do

Merge branch 'dhp_stock' of bitbucket.org:hoangphucd3/venshoppv into dhp_stock

# Conflicts:
#	app/controllers/users_controller.rb
#	app/helpers/application_helper.rb
#	app/views/layouts/_header.html.erb
#	app/views/line_items/create.js.erb
parents ceefb1c4 1eaeedd2
(function($) { (function($) {
toastr.options.closeButton = true;
}).apply(this, [jQuery]); }).apply(this, [jQuery]);
\ No newline at end of file
//= require toastr //= require toastr
//= require bootstrap-touchspin //= require bootstrap-touchspin
//= require cart/cart //= require cart/cart
//= require shop-14
\ No newline at end of file
...@@ -11,6 +11,7 @@ class LineItemsController < ApplicationController ...@@ -11,6 +11,7 @@ class LineItemsController < ApplicationController
# POST /line_items # POST /line_items
def create def create
return if params[:product_quantity].to_i.zero?
product = Product.find(params[:product_id]) product = Product.find(params[:product_id])
product_is_in_stock = product_is_in_stock?(product, product_is_in_stock = product_is_in_stock?(product,
get_line_item_quantity(product.id, get_line_item_quantity(product.id,
......
...@@ -14,18 +14,16 @@ class OrdersController < ApplicationController ...@@ -14,18 +14,16 @@ class OrdersController < ApplicationController
# POST /orders # POST /orders
def create def create
@order = current_user.orders.new @order = current_user.orders.create!
create_line_items_for_order(@order) create_line_items_for_order(@order)
respond_to do |format| respond_to do |format|
if @order.save
destroy_cart_session destroy_cart_session
OrderMailer.send_order_detail_to_user(current_user, @order).deliver_later OrderMailer.send_order_detail_to_user(current_user, @order).deliver_later
format.html { redirect_to root_url, notice: 'Your order is successfully created' } format.html { redirect_to root_url, notice: 'Your order is successfully created' }
else
format.html { redirect_to root_url, notice: 'Your order can not be created' }
end
end end
rescue ActiveRecord::RecordNotSaved
redirect_to root_url, notice: 'Your order can not be created'
end end
def create_line_items_for_order(order) def create_line_items_for_order(order)
......
class UsersController < ApplicationController class UsersController < ApplicationController
before_action :authenticate_user!
# GET /users/1 # GET /users/1
def show def show
@user = User.find(current_user.id) @user = User.find(current_user.id)
......
...@@ -2,4 +2,8 @@ module ApplicationHelper ...@@ -2,4 +2,8 @@ module ApplicationHelper
def active_class(page_name, class_name = 'active') def active_class(page_name, class_name = 'active')
class_name if params[:action] == page_name class_name if params[:action] == page_name
end end
def user_own_product?(product)
current_user == product.user
end
end end
class LineItem < ApplicationRecord class LineItem < ApplicationRecord
belongs_to :product, optional: true belongs_to :product, optional: true
belongs_to :order, optional: true belongs_to :order, optional: true
after_create :update_product_quantity
def total_price def total_price
product.price * quantity product.price * quantity
end end
def update_product_quantity
product.update(quantity: product.quantity - quantity)
end
end end
\ No newline at end of file
...@@ -11,6 +11,30 @@ ...@@ -11,6 +11,30 @@
<%= devise_error_messages! %> <%= devise_error_messages! %>
<div class="row"> <div class="row">
<div class="col-md-6">
<div class="form-group">
<%= f.label :first_name %>
<%= f.text_field :first_name, class: "form-control" %>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<%= f.label :last_name %>
<%= f.text_field :last_name, class: "form-control" %>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="form-group">
<%= f.label :username %>
<%= f.text_field :username, class: "form-control" %>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12"> <div class="col-xs-12">
<div class="form-group"> <div class="form-group">
<%= f.label :email %> <%= f.label :email %>
......
<section class="form-section"> <section class="form-section">
<div class="container"> <div class="container">
<h2 class="h2 heading-primary font-weight-normal mb-md mt-xlg"> <h2 class="h2 heading-primary font-weight-normal mb-md mt-xlg">
Welcome back! Sign in to your account Login or Create an Account
</h2> </h2>
<div class="featured-box featured-box-primary featured-box-flat featured-box-text-left mt-md"> <div class="featured-box featured-box-primary featured-box-flat featured-box-text-left mt-md">
<div class="box-content"> <div class="box-content">
<div class="row"> <div class="row">
<div class="col-md-6 col-md-offset-3"> <div class="col-sm-6">
<div class="form-content">
<h3 class="heading-text-color font-weight-normal">New Customers</h3>
<p>By creating an account with our store, you will be able to move through the checkout process faster,
store multiple shipping addresses, view and track your orders in your account and more.</p>
</div>
<div class="form-action clea rfix">
<%= link_to 'Create an Account', new_user_registration_path, class: 'btn btn-primary' %>
</div>
</div>
<div class="col-md-6">
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> <%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="form-content"> <div class="form-content">
<h3 class="heading-text-color font-weight-normal"> <h3 class="heading-text-color font-weight-normal">
...@@ -15,7 +25,7 @@ ...@@ -15,7 +25,7 @@
<div class="form-group"> <div class="form-group">
<%= f.label :login %> <%= f.label :login %>
<%= f.email_field :login, autofocus: true, class: "form-control" %> <%= f.text_field :login, autofocus: true, class: "form-control" %>
</div> </div>
<div class="form-group"> <div class="form-group">
...@@ -25,7 +35,7 @@ ...@@ -25,7 +35,7 @@
</div> </div>
<div class="form-action clearfix"> <div class="form-action clearfix">
<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> <%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
<%= link_to "Lost your password?", new_password_path(resource_name), class: 'pull-left' %> <%# link_to "Lost your password?", new_password_path(resource_name), class: 'pull-left' %>
<% end -%> <% end -%>
<%= f.submit "Submit", class: "btn btn-primary" %> <%= f.submit "Submit", class: "btn btn-primary" %>
</div> </div>
......
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
<%= link_to 'SIGN OUT', destroy_user_session_path, method: :delete %> <%= link_to 'SIGN OUT', destroy_user_session_path, method: :delete %>
<% else %> <% else %>
<%= link_to 'SIGN IN', new_user_session_path %> <%= link_to 'SIGN IN', new_user_session_path %>
<span class="split"></span>
<%= link_to 'SIGN UP', new_user_registration_path %>
<% end %> <% end %>
</div> </div>
<div class="cart-dropdown"> <div class="cart-dropdown">
......
toastr.options.closeButton = true;
toastr.options.timeOut = 1000; // How long the toast will display without user interaction
toastr.options.extendedTimeOut = 2000; // How long the toast will display after a user hovers over it
$('.cart-qty').html("<%= render 'carts/cart_quantity' %>"); $('.cart-qty').html("<%= render 'carts/cart_quantity' %>");
<% if @notice %>
toastr.<%= @notice[:type] %>('<%= @notice[:msg] %>'); toastr.<%= @notice[:type] %>('<%= @notice[:msg] %>');
<% end %>
\ No newline at end of file
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
<div class="product-details-box col-sm-7"> <div class="product-details-box col-sm-7">
<h1 class="product-name"> <h1 class="product-name">
<%= product.title %> <%= product.title %>
<%= link_to fa_icon('pencil'), edit_product_path if user_own_product?(product) %>
</h1> </h1>
<div class="product-short-desc"> <div class="product-short-desc">
<%= product.description %> <%= product.description %>
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
<div class="product-details-area"> <div class="product-details-area">
<h2 class="product-name"> <h2 class="product-name">
<%= link_to product.title, product_url(product) %> <%= link_to product.title, product_url(product) %>
<%= link_to fa_icon('pencil'), edit_product_path(product) if user_own_product?(product) %>
</h2> </h2>
<div class="product-short-desc"> <div class="product-short-desc">
<%= product.description %> <%= product.description %>
......
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-md-9 col-md-push-3 create-product form-section"> <div class="col-md-12 create-product form-section">
<h1 class="h2 heading-primary font-weight-normal"> <h1 class="h2 heading-primary font-weight-normal">
Edit Product #<%= @product.id %> Edit Product #<%= @product.id %>
(<%= link_to 'Delete', @product, method: :delete, data: { confirm: 'Are your sure?' } %>) (<%= link_to 'Delete', @product, method: :delete, data: { confirm: 'Are your sure?' } %>)
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
<div class="featured-box featured-box-primary featured-box-flat featured-box-text-left mt-md"> <div class="featured-box featured-box-primary featured-box-flat featured-box-text-left mt-md">
<div class="box-content"> <div class="box-content">
<p><%= link_to 'Back to product', product_path %></p>
<%= render 'form' %> <%= render 'form' %>
</div> </div>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment