who_bought.atom.builder 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. atom_feed do |feed|
  2. feed.title "Who bought #{@product.title}"
  3. latest_order = @product.orders.sort_by(&:updated_at).last
  4. feed.updated( latest_order && latest_order.updated_at )
  5. @product.orders.each do |order|
  6. feed.entry(order) do |entry|
  7. entry.title "Order #{order.id}"
  8. entry.summary type: 'xhtml' do |xhtml|
  9. xhtml.p "Shipped to #{order.address}"
  10. xhtml.table do
  11. xhtml.tr do
  12. xhtml.th 'Product'
  13. xhtml.th 'Quantity'
  14. xhtml.th 'Total Price'
  15. end
  16. order.line_items.each do |item|
  17. xhtml.tr do
  18. xhtml.td item.product.title
  19. xhtml.td item.quantity
  20. xhtml.td number_to_currency item.total_price
  21. end
  22. end
  23. xhtml.tr do
  24. xhtml.th 'total', colspan: 2
  25. xhtml.th number_to_currency \
  26. order.line_items.map(&:total_price).sum
  27. end
  28. end
  29. xhtml.p "Paid by #{order.pay_type}"
  30. end
  31. entry.author do |author|
  32. author.name order.name
  33. author.email order.email
  34. end
  35. end
  36. end
  37. end