Skip to content

  • Projects
  • Groups
  • Snippets
  • Help
  • This project
    • Loading...
  • Sign in / Register
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 1
    • Merge Requests 1
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Charts
  • Wiki
    • Wiki
  • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Truong Ba Dieu
  • VenShop
  • Merge Requests
  • !2

Closed
Opened Jul 16, 2015 by Truong Ba Dieu@dieutb 
  • Report abuse
Report abuse

Feature buying

×

Check out, review, and merge locally

Step 1. Fetch and check out the branch for this merge request

git fetch origin
git checkout -b feature-buying origin/feature-buying

Step 2. Review the changes locally

Step 3. Merge the branch and fix any conflicts that come up

git checkout feature-item-display
git merge --no-ff feature-buying

Step 4. Push the result of the merge to GitLab

git push origin feature-item-display

Note that pushing to GitLab requires write access to this repository.

Tip: You can also checkout merge requests locally by following these guidelines.

  • Discussion 10
  • Commits 3
  • Changes
{{ resolvedDiscussionCount }}/{{ discussionCount }} {{ resolvedCountText }} resolved
  • Nguyen Ngoc Lan
    @lannn started a discussion on commit f2b33c51 Jul 16, 2015
    app/controllers/orders_controller.rb 0 → 100644
    1 class OrdersController < ApplicationController
    2 before_action :set_order, only: [:show, :edit, :update, :destroy]
    3
    4 def index
    5 @orders = Order.newest.page(params[:page])
    6 end
    7
    8 def show
    9 end
    10
    11 def new
    12 if current_cart.line_items.empty?
    13 redirect_to root_path
    • Nguyen Ngoc Lan @lannn commented Jul 16, 2015
      Master

      @dieutb Action này liên quan đến cart mà ở đây là OrdersController. Để phân nhiệm vụ rõ ràng hơn thì nên di chuyển action này sang CartsController chẳng hạn

      @dieutb Action này liên quan đến cart mà ở đây là OrdersController. Để phân nhiệm vụ rõ ràng hơn thì nên di chuyển action này sang CartsController chẳng hạn
    Please register or sign in to reply
  • Nguyen Ngoc Lan
    @lannn started a discussion on commit f2b33c51 Jul 16, 2015
    app/models/line_item.rb 0 → 100644
    1 class LineItem < ActiveRecord::Base
    2 belongs_to :order
    3 belongs_to :product
    4
    5 validate :check_product_stock
    • Nguyen Ngoc Lan @lannn commented Jul 16, 2015
      Master

      @dieutb Nên có 1 dòng trắng phân tách giữa vùng validations và vùng callbacks

      @dieutb Nên có 1 dòng trắng phân tách giữa vùng validations và vùng callbacks
    Please register or sign in to reply
  • Nguyen Ngoc Lan
    @lannn started a discussion on commit f2b33c51 Jul 16, 2015
    app/models/line_item.rb 0 → 100644
    1 class LineItem < ActiveRecord::Base
    2 belongs_to :order
    3 belongs_to :product
    4
    5 validate :check_product_stock
    6 after_save :trigger_recalculate
    7 before_destroy :trigger_calculate_order
    8
    9 def trigger_recalculate
    • Nguyen Ngoc Lan @lannn commented Jul 16, 2015
      Master

      @dieutb Hàm này có được dùng ở bên ngoài ko?

      Nếu chỉ dùng bên trong class LineItem thì đặt vào vùng private để cho dễ kiểm soát

      @dieutb Hàm này có được dùng ở bên ngoài ko? Nếu chỉ dùng bên trong class LineItem thì đặt vào vùng private để cho dễ kiểm soát
    Please register or sign in to reply
  • Nguyen Ngoc Lan
    @lannn started a discussion on commit f2b33c51 Jul 16, 2015
    app/models/order.rb 0 → 100644
    1 class Order < ActiveRecord::Base
    2 enum state: [:card, :checkout]
    3
    4 has_many :line_items, dependent: :destroy
    5 belongs_to :user
    6
    7 accepts_nested_attributes_for :line_items
    8
    9 def recalculate
    10 count = line_items.sum(:quantity)
    11 total_price = 0
    12 line_items.each do |item|
    • Nguyen Ngoc Lan @lannn commented Jul 16, 2015
      Master

      @dieutb Trong ruby có hàm tính tổng là reduce. Dùng hàm này sẽ giảm được 1 biến tạm thời total_price

      http://ruby-doc.org/core-2.1.0/Enumerable.html#method-i-reduce

      @dieutb Trong ruby có hàm tính tổng là reduce. Dùng hàm này sẽ giảm được 1 biến tạm thời total_price http://ruby-doc.org/core-2.1.0/Enumerable.html#method-i-reduce
    Please register or sign in to reply
  • Nguyen Ngoc Lan
    @lannn started a discussion on commit f2b33c51 Jul 16, 2015
    app/models/order.rb 0 → 100644
    1 class Order < ActiveRecord::Base
    2 enum state: [:card, :checkout]
    3
    4 has_many :line_items, dependent: :destroy
    5 belongs_to :user
    6
    7 accepts_nested_attributes_for :line_items
    8
    9 def recalculate
    10 count = line_items.sum(:quantity)
    11 total_price = 0
    12 line_items.each do |item|
    13 total_price += item.quantity*item.price
    14 end
    15 self.update_columns(item_count: count, item_total: total_price)
    • Nguyen Ngoc Lan @lannn commented Jul 16, 2015
      Master

      @dieutb Vì hàm update_columns skip validations và callbacks nên tốt hơn là dùng hàm update. Trừ khi có mục đích là skip

      Có nhiều chỗ dùng hàm này

      Edited Jul 16, 2015
      @dieutb Vì hàm update_columns skip validations và callbacks nên tốt hơn là dùng hàm update. Trừ khi có mục đích là skip Có nhiều chỗ dùng hàm này
    Please register or sign in to reply
  • Nguyen Ngoc Lan
    @lannn started a discussion on commit f2b33c51 Jul 16, 2015
    app/models/product.rb
    6 6 # default 'public/images/product_default.jpg'
    7 7 end
    8 8  
    9 paginates_per 5
    10
    9 11 validates :pid, :title, :price, :category_id, :image, :stock, :release_date, :public_date, presence: true
    10 12 validates :pid, uniqueness: true
    11 13  
    12 scope :recommend, -> {where(recommend: true)}
    14 scope :recommend, -> { where(recommend: true) }
    13 15  
    14 16 def self.search(params)
    15 params[:per_page] ||= 5
    16 params[:page] ||= 1
    17 Product.order("release_date DESC").page(params[:page])
    • Nguyen Ngoc Lan @lannn commented Jul 16, 2015
      Master

      @dieutb Có thể dùng kiểu param thay cho string: order(release_date: :desc)

      @dieutb Có thể dùng kiểu param thay cho string: order(release_date: :desc)
    Please register or sign in to reply
  • Nguyen Ngoc Lan
    @lannn started a discussion on commit f2b33c51 Jul 16, 2015
    app/services/cart_service.rb 0 → 100644
    1 class CartService
    2
    3 def self.add_product(current_order, params)
    4 params[:quantity] ||= 1
    5 product = Product.find(params[:product_id])
    6 if product.can_buy?(params[:quantity])
    • Nguyen Ngoc Lan @lannn commented Jul 16, 2015
      Master

      @dieutb Liệu có thiếu Cart model trong trường hợp này ko?

      @dieutb Liệu có thiếu Cart model trong trường hợp này ko?
    Please register or sign in to reply
  • Truong Ba Dieu
    @dieutb started a discussion on commit f2b33c51 Jul 16, 2015
    app/models/order.rb 0 → 100644
    1 class Order < ActiveRecord::Base
    2 enum state: [:card, :checkout]
    3
    4 has_many :line_items, dependent: :destroy
    5 belongs_to :user
    6
    7 accepts_nested_attributes_for :line_items
    8
    9 def recalculate
    10 count = line_items.sum(:quantity)
    11 total_price = 0
    12 line_items.each do |item|
    13 total_price += item.quantity*item.price
    14 end
    15 self.update_columns(item_count: count, item_total: total_price)
    • Truong Ba Dieu @dieutb commented Jul 16, 2015
      Master

      Yes. My purpose is skip validate and callback here

      Yes. My purpose is skip validate and callback here
    Please register or sign in to reply
  • Truong Ba Dieu @dieutb

    Added 1 commit:

    • ce5b42b0 - Fix pull request
    Jul 17, 2015

    Added 1 commit:

    • ce5b42b0 - Fix pull request
    Added 1 commit: * ce5b42b0 - Fix pull request
    Toggle commit list
  • Truong Ba Dieu @dieutb

    Added 1 commit:

    • c0dab2d3 - Refactor
    Jul 17, 2015

    Added 1 commit:

    • c0dab2d3 - Refactor
    Added 1 commit: * c0dab2d3 - Refactor
    Toggle commit list
  • Tran Hoang Viet
    @vietth started a discussion on the diff Jul 28, 2015
    app/controllers/application_controller.rb
    4 4 protect_from_forgery with: :exception
    5 5 layout :detect_layout
    6 6  
    7 before_filter :configure_permitted_parameters, if: :devise_controller?
    7 before_action :configure_permitted_parameters, if: :devise_controller?
    8
    9 include OrderHelper
    • Tran Hoang Viet @vietth commented Jul 28, 2015
      Reporter

      include OrderHelper should be placed on top class. It's easier to see

      `include OrderHelper` should be placed on top class. It's easier to see
    Please register or sign in to reply
  • Tran Hoang Viet
    @vietth started a discussion on the diff Jul 28, 2015
    app/controllers/orders_controller.rb 0 → 100644
    1 class OrdersController < ApplicationController
    2 before_action :authenticate_user!
    3 layout "cart"
    4
    5 def update
    6 current_order.update_attributes(update_order_params)
    7 redirect_to cart_path(), notice: "Update cart successfully"
    • Tran Hoang Viet @vietth commented Jul 28, 2015
      Reporter

      Use cart_path if it has no agruments

      Use `cart_path` if it has no agruments
    Please register or sign in to reply
  • Truong Ba Dieu @dieutb

    Status changed to closed

    Jul 31, 2015

    Status changed to closed

    Status changed to closed
    Toggle commit list
  • Write
  • Preview
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 sign in to comment
Nguyen Ngoc Lan
Assignee
Nguyen Ngoc Lan @lannn
Assign to
None
Milestone
None
Assign milestone
Time tracking
1
Labels
Review
Assign labels
  • View labels
3
3 participants
Reference: dieutb/VenShop!2