1. Run InstantRails
2. สร้างหน้าจอ แสดงรายการสินค้าที่ถูกสั่งซื้อ (order)
2.1 แก้ไข admin_controller.rb , เพิ่มเมธอด ship()
2.2 แก้ไข Model ชื่อ order.rb
2.3 สร้าง views ชื่อ ship.rhtml
2.4 สร้าง views ชื่อ _order_line.rhtml
3. ปรับแต่งการแสดงผล
3.1 สร้าง Stylesheet ชื่อ admin.css
3.2 แก้ไข layouts ชื่อ admin.rhtml
4. สร้างการจัดส่งสินค้า
4.1 แก้ไข admin_controller.rb
4.2 แก้ไข Models ชื่อ order.rb
5. แสดงผลลัพธ์
def ship
@pending_orders = Order.pending_shipping
end
1.2 สร้างฟังก์ชั่นดึงข้อมูลจากตาราง Order
def self.pending_shipping
find(:all, :conditions => "shipped_at is null")
end
1.3 สร้างไฟล์แสดงรายการสินค้าที่ถูกสั่งซื้อ
<div class="olheader">Orders To Be Shipped</div> <%= form_tag(:action => "ship") %> <table cellpadding="5" cellspacing="0"> <%= render(:partial => "order_line", :collection => @pending_orders) %> </table> <br /> <input type="submit" value=" SHIP CHECKED ITEMS " /> <%= end_form_tag %> <br />
<tr valign="top">
<td class="olnamebox">
<div class="olname"><%= h(order_line.name) %></div>
<div class="oladdress"><%= h(order_line.address) %></div>
</td>
<td class="olitembox">
<% order_line.line_items.each do |li| %>
<div class="olitem">
<span class="olitemqty"><%= li.quantity %></span>
<span class="olitemtitle"><%= li.product.title %></span>
</div>
<% end %>
</td>
<td>
<%= check_box("to_be_shipped", order_line.id, {}, "yes", "no") %>
</td>
</tr>
1.4 ปรับรูปแบบการแสดงผล
/* order shipping screen */
.olheader {
font: bold large sans-serif;
color: #411;
margin-bottom: 2ex;
}
.olnamebox, .olitembox {
padding-bottom: 3ex;
padding-right: 3em;
border-top: 1px dotted #411;
}
.olname {
font-weight: bold;
}
.oladdress {
font-size: smaller;
white-space: pre;
}
.olitemqty {
font-size: smaller;
font-weight: bold;
}
.olitemqty:after {
content: " x ";
}
.olitemtitle {
font-weight: bold;
}
def ship
count = 0
if things_to_ship = params[:to_be_shipped]
count = do_shipping(things_to_ship)
if count > 0
count_text = pluralize(count, "order")
flash.now[:notice] = "#{count_text} marked as shipped"
end
end
@pending_orders = Order.pending_shipping
end
private
def do_shipping(things_to_ship)
count = 0
things_to_ship.each do |order_id, do_it|
if do_it == "yes"
order = Order.find(order_id)
order.mark_as_shipped
order.save
count += 1
end
end
count
end
def pluralize(count, noun)
case count
when 0: "No #{noun.pluralize}"
when 1: "One #{noun}"
else "#{count} #{noun.pluralize}"
end
end
def mark_as_shipped
self.shipped_at = Time.now
end
if things_to_ship = params[:to_be_shipped]
count = do_shipping(things_to_ship)
if count > 0
count_text = pluralize(count, "order")
flash.now[:notice] = "#{count_text} marked as shipped"
end
@pending_orders = Order.pending_shipping
def do_shipping(things_to_ship)
count = 0
things_to_ship.each do |order_id, do_it|
if do_it == "yes"
order = Order.find(order_id)
order.mark_as_shipped
order.save
count += 1
end
end
count
end
def pluralize(count, noun)
case count
when 0: "No #{noun.pluralize}"
when 1: "One #{noun}"
else "#{count} #{noun.pluralize}"
end
end
| I | Attachment | Action | Size | Date | Who | Comment |
|---|---|---|---|---|---|---|
| | shippingPage.png | manage | 139.9 K | 08 Jun 2007 - 11:21 | UnknownUser | |
| | ecom2_new_product77.png | manage | 83.2 K | 08 Jun 2007 - 11:23 | UnknownUser | |
| | ecom2_new_product78.png | manage | 116.9 K | 08 Jun 2007 - 11:23 | UnknownUser | |
| | ecom2_new_product81.png | manage | 81.6 K | 08 Jun 2007 - 11:23 | UnknownUser | |
| | ecom2_new_product84.png | manage | 17.0 K | 08 Jun 2007 - 11:25 | UnknownUser | |
| | shippingPage2.png | manage | 116.1 K | 08 Jun 2007 - 11:43 | UnknownUser |