9月6日 ORID JDSTORE

9月6日 ORID JDSTORE

0

编程: 169MIN

  1. 结账页面 + 订单页面(60MIN)

1)

total:integer, default: 0

2)

<%= render_cart_total_price %>

3)

def create
  @order = Order.new(order_params)
  @order.user = current_user
  if @order.save
    current_cart.cart_items.each do |cart_item|
      product_list = ProductList.new
      product_list.order = @order
      product_list.product_name = cart_item.product.title
      product_list.product_price = cart_item.product.price
      product_list.quantity = cart_item.quantit
      product_list.save
    end 
  else
    render 'carts/checkout'
  end 
end 
  1. 使用者可以完成付款。(34MIN)
payment_method
def set_payment_with!(method)
  self.update_columns(payment_with: method)
end
def pay!
  self.update_columns(is_paid: true)
end 
  1. 管理者可以更改订单状态(67MIN)
rails g migration add_aasm_state_to_order
def change
  add_columns :orders, :aasm_state, :string, default: "place_ordered"
  add_index :orders, :aasm_state
end 
event :ship do
  transitions from::
end 
<%= render "admin/orders/state_option", order: @order%>
case order.aasm_sate do

4. 使用者可以取消订单 8MIN

if @order.paid? || @order.order_placed?

反思

1. 22MIN + 

R

I

D

0

Comments

comments powered by Disqus