Skip to content

  • Projects
  • Groups
  • Snippets
  • Help
  • This project
    • Loading...
  • Sign in / Register
V
VietTH-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 4
    • Merge Requests 4
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Charts
  • Wiki
    • Wiki
  • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Tran Hoang Viet
  • VietTH-VenShop
  • Merge Requests
  • !9

Merged
Opened Jul 14, 2015 by Tran Hoang Viet@vietth 
  • Report abuse
Report abuse

VietTH: Feature stock management

  • Discussion 9
  • Commits 4
  • Changes
{{ resolvedDiscussionCount }}/{{ discussionCount }} {{ resolvedCountText }} resolved
  • Nguyen Ngoc Lan
    @lannn started a discussion on an old version of the diff Jul 15, 2015
    app/services/order_service.rb
    1 1 class OrderService < BaseService
    2 2  
    3 def create(order_params)
    4 order = current_user.orders.build(order_params)
    5
    6 product_ids = []
    7 quantites = {}
    8 order_params['order_items_attributes'].each do |item|
    9 id = item.last['product_id']
    10 product_ids << id
    11 quantites[id] = item.last['quantity']
    12 end
    3 def add_to_cart product
    • Nguyen Ngoc Lan @lannn commented Jul 15, 2015
      Developer

      @vietth lack of () for argument. It makes recognize argument easier. And this is order service and you put cart functionality in here, is it right place?

      This violates single responsibility

      If you can find out other appropriate place for add_to_cart method, code will be better

      Edited Jul 15, 2015
      @vietth lack of () for argument. It makes recognize argument easier. And this is order service and you put cart functionality in here, is it right place? This violates single responsibility If you can find out other appropriate place for add_to_cart method, code will be better
    Please register or sign in to reply
  • Nguyen Ngoc Lan
    @lannn started a discussion on an old version of the diff Jul 15, 2015
    app/controllers/products_controller.rb
    26 24 end
    27 25  
    28 26 def add_cart
    29 add_to_cart(@product)
    30 redirect_to(@product, notice: 'Product is added to cart.')
    27 result = order_service.add_to_cart(@product)
    • Nguyen Ngoc Lan @lannn commented Jul 15, 2015
      Developer

      @vietth I think method "add_to_cart" should return only true or false

      @vietth I think method "add_to_cart" should return only true or false
    Please register or sign in to reply
  • Nguyen Ngoc Lan
    @lannn started a discussion on an old version of the diff Jul 15, 2015
    app/models/order_item.rb
    1 1 class OrderItem < ActiveRecord::Base
    2 2 belongs_to :order
    3 3 belongs_to :product
    4
    5 before_save :update_product_quantity
    • Nguyen Ngoc Lan @lannn commented Jul 15, 2015
      Developer

      @vietth if order_item is not saved, system still decreases stock

      Edited Jul 15, 2015
      @vietth if order_item is not saved, system still decreases stock
    Please register or sign in to reply
  • Tran Hoang Viet
    @vietth started a discussion on an old version of the diff Jul 15, 2015
    app/services/order_service.rb
    1 1 class OrderService < BaseService
    2 2  
    3 def create(order_params)
    4 order = current_user.orders.build(order_params)
    5
    6 product_ids = []
    7 quantites = {}
    8 order_params['order_items_attributes'].each do |item|
    9 id = item.last['product_id']
    10 product_ids << id
    11 quantites[id] = item.last['quantity']
    12 end
    3 def add_to_cart product
    • Tran Hoang Viet @vietth commented Jul 15, 2015
      Master

      Ok, i'll move add_to_cart to CartService

      Ok, i'll move add_to_cart to CartService
    Please register or sign in to reply
  • Tran Hoang Viet
    @vietth started a discussion on an old version of the diff Jul 15, 2015
    app/models/order_item.rb
    1 1 class OrderItem < ActiveRecord::Base
    2 2 belongs_to :order
    3 3 belongs_to :product
    4
    5 before_save :update_product_quantity
    • Tran Hoang Viet @vietth commented Jul 15, 2015
      Master

      Oh sorry, my mistake. I should use after_save instead.

      Oh sorry, my mistake. I should use after_save instead.
    Please register or sign in to reply
  • Tran Hoang Viet
    @vietth started a discussion on an old version of the diff Jul 15, 2015
    app/controllers/products_controller.rb
    26 24 end
    27 25  
    28 26 def add_cart
    29 add_to_cart(@product)
    30 redirect_to(@product, notice: 'Product is added to cart.')
    27 result = order_service.add_to_cart(@product)
    • Tran Hoang Viet @vietth commented Jul 15, 2015
      Master

      @lannn Currently, 'add_to_cart' and methods in service are returned a hash {status: STATUS}. In cases i have many exception, I can return it with {status: false, error: ERROR_CODE}. Then I can easily control errors which are returned.

      Edited Jul 15, 2015
      @lannn Currently, 'add_to_cart' and methods in service are returned a hash `{status: STATUS}`. In cases i have many exception, I can return it with `{status: false, error: ERROR_CODE}`. Then I can easily control errors which are returned.
    Please register or sign in to reply
  • Nguyen Ngoc Lan
    @lannn started a discussion on an old version of the diff Jul 15, 2015
    app/models/order_item.rb
    1 1 class OrderItem < ActiveRecord::Base
    2 2 belongs_to :order
    3 3 belongs_to :product
    4
    5 before_save :update_product_quantity
    • Nguyen Ngoc Lan @lannn commented Jul 15, 2015
      Developer

      right, @vietth

      right, @vietth
    Please register or sign in to reply
  • Nguyen Ngoc Lan
    @lannn started a discussion on an old version of the diff Jul 15, 2015
    app/services/order_service.rb
    1 1 class OrderService < BaseService
    2 2  
    3 def create(order_params)
    4 order = current_user.orders.build(order_params)
    5
    6 product_ids = []
    7 quantites = {}
    8 order_params['order_items_attributes'].each do |item|
    9 id = item.last['product_id']
    10 product_ids << id
    11 quantites[id] = item.last['quantity']
    12 end
    3 def add_to_cart product
    • Nguyen Ngoc Lan @lannn commented Jul 15, 2015
      Developer

      great, it helps code easy to maitain

      great, it helps code easy to maitain
    Please register or sign in to reply
  • Nguyen Ngoc Lan
    @lannn started a discussion on an old version of the diff Jul 15, 2015
    app/controllers/products_controller.rb
    26 24 end
    27 25  
    28 26 def add_cart
    29 add_to_cart(@product)
    30 redirect_to(@product, notice: 'Product is added to cart.')
    27 result = order_service.add_to_cart(@product)
    • Nguyen Ngoc Lan @lannn commented Jul 15, 2015
      Developer

      You have reason! I agree to return { status: false, error: ERROR_CODE } in service. Please add space after { and before }. It looks more spacious to read code

      You have reason! I agree to return { status: false, error: ERROR_CODE } in service. Please add space after { and before }. It looks more spacious to read code
    Please register or sign in to reply
  • Tran Hoang Viet @vietth

    Added 1 commit:

    • 91759019 - VietTH: Move add_t_cart and update_cart to CartService
    Jul 15, 2015

    Added 1 commit:

    • 91759019 - VietTH: Move add_t_cart and update_cart to CartService
    Added 1 commit: * 91759019 - VietTH: Move add_t_cart and update_cart to CartService
    Toggle commit list
  • Tran Hoang Viet @vietth

    Added 1 commit:

    • d95632a4 - VietTH: Implement validate add_to_cart
    Jul 15, 2015

    Added 1 commit:

    • d95632a4 - VietTH: Implement validate add_to_cart
    Added 1 commit: * d95632a4 - VietTH: Implement validate add_to_cart
    Toggle commit list
  • Tran Hoang Viet @vietth

    Added 1 commit:

    • ceb74a0c - VietTH: Create new product with new attribute :stock
    Jul 15, 2015

    Added 1 commit:

    • ceb74a0c - VietTH: Create new product with new attribute :stock
    Added 1 commit: * ceb74a0c - VietTH: Create new product with new attribute :stock
    Toggle commit list
  • Tran Hoang Viet @vietth

    Status changed to merged

    Jul 16, 2015

    Status changed to merged

    Status changed to merged
    Toggle commit list
  • Tran Hoang Viet @vietth

    mentioned in commit f04cca90

    Jul 16, 2015

    mentioned in commit f04cca90

    mentioned in commit f04cca903a24e89d0d05049ce7ef66b5ccbdfa05
    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
2
2 participants
Reference: vietth/VietTH-VenShop!9