radiant-shop-extension 0.11.6 → 0.90.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (227) hide show
  1. data/HISTORY.md +21 -3
  2. data/LICENSE +42 -0
  3. data/README.md +62 -25
  4. data/Rakefile +4 -5
  5. data/VERSION +1 -1
  6. data/app/controllers/admin/shop/categories_controller.rb +1 -0
  7. data/app/controllers/admin/shop/orders_controller.rb +1 -1
  8. data/app/controllers/admin/shop/products_controller.rb +18 -7
  9. data/app/helpers/shop_helper.rb +8 -0
  10. data/app/models/form_address.rb +5 -5
  11. data/app/models/form_checkout.rb +25 -17
  12. data/app/models/form_line_item.rb +1 -1
  13. data/app/models/shop_category.rb +22 -7
  14. data/app/models/shop_customer.rb +1 -1
  15. data/app/models/shop_line_item.rb +26 -26
  16. data/app/models/shop_order.rb +0 -2
  17. data/app/models/shop_product.rb +15 -18
  18. data/app/views/.DS_Store +0 -0
  19. data/app/views/admin/shop/categories/edit/meta/_status.html.haml +3 -0
  20. data/app/views/admin/shop/products/edit/_foot.html.haml +1 -8
  21. data/app/views/admin/shop/products/edit/meta/_layout.html.haml +6 -0
  22. data/app/views/admin/shop/products/edit/meta/_status.html.haml +3 -0
  23. data/app/views/admin/shop/products/index/_product.html.haml +1 -1
  24. data/config/locales/en.yml +8 -7
  25. data/config/routes.rb +4 -16
  26. data/db/migrate/20101011063133_setup_shop.rb +94 -0
  27. data/db/seeds/forms.rb +113 -154
  28. data/db/seeds/layouts.rb +67 -103
  29. data/db/seeds/pages.rb +101 -0
  30. data/db/seeds/products.rb +29 -0
  31. data/db/seeds/snippets.rb +36 -21
  32. data/lib/shop/controllers/application_controller.rb +5 -3
  33. data/lib/shop/models/form_extension.rb +1 -2
  34. data/lib/shop/models/page.rb +0 -1
  35. data/lib/shop/models/user.rb +0 -1
  36. data/lib/shop/tags/card.rb +8 -2
  37. data/lib/shop/tags/cart.rb +5 -1
  38. data/lib/shop/tags/helpers.rb +35 -60
  39. data/lib/shop/tags/item.rb +2 -16
  40. data/lib/shop/tags/product.rb +7 -0
  41. data/lib/tasks/shop_extension_tasks.rake +9 -4
  42. data/public/javascripts/admin/extensions/shop/products/edit.js +0 -25
  43. data/radiant-shop-extension.gemspec +25 -201
  44. data/shop_extension.rb +18 -19
  45. data/spec/datasets/forms.rb +25 -28
  46. data/spec/datasets/shop_categories.rb +2 -2
  47. data/spec/datasets/shop_config.rb +24 -0
  48. data/spec/datasets/shop_customers.rb +1 -0
  49. data/spec/datasets/shop_line_items.rb +21 -3
  50. data/spec/datasets/shop_products.rb +4 -1
  51. data/spec/datasets/tags.rb +19 -0
  52. data/spec/lib/shop/models/page_spec.rb +1 -1
  53. data/spec/lib/shop/tags/card_spec.rb +30 -4
  54. data/spec/lib/shop/tags/cart_spec.rb +29 -12
  55. data/spec/lib/shop/tags/helpers_spec.rb +45 -66
  56. data/spec/lib/shop/tags/item_spec.rb +6 -10
  57. data/spec/lib/shop/tags/product_spec.rb +27 -2
  58. data/spec/models/form_address_spec.rb +9 -8
  59. data/spec/models/form_checkout_spec.rb +28 -22
  60. data/spec/models/shop_category_spec.rb +2 -10
  61. data/spec/models/shop_line_item_spec.rb +71 -34
  62. data/spec/models/shop_order_spec.rb +5 -5
  63. data/spec/models/shop_product_attachment_spec.rb +1 -0
  64. data/spec/models/shop_product_spec.rb +4 -47
  65. data/spec/spec.opts +3 -5
  66. metadata +60 -248
  67. data/Gemfile +0 -26
  68. data/Gemfile.lock +0 -75
  69. data/MIT-LICENSE +0 -20
  70. data/app/controllers/admin/shop/discounts/discountables_controller.rb +0 -44
  71. data/app/controllers/admin/shop/discounts_controller.rb +0 -64
  72. data/app/controllers/admin/shop/packages/packings_controller.rb +0 -90
  73. data/app/controllers/admin/shop/packages_controller.rb +0 -63
  74. data/app/controllers/admin/shop/products/variant_templates_controller.rb +0 -27
  75. data/app/controllers/admin/shop/products/variants_controller.rb +0 -60
  76. data/app/controllers/admin/shop/variants_controller.rb +0 -48
  77. data/app/models/form_discount.rb +0 -39
  78. data/app/models/shop_discount.rb +0 -37
  79. data/app/models/shop_discountable.rb +0 -64
  80. data/app/models/shop_group.rb +0 -15
  81. data/app/models/shop_grouping.rb +0 -6
  82. data/app/models/shop_package.rb +0 -74
  83. data/app/models/shop_packing.rb +0 -22
  84. data/app/models/shop_product_variant.rb +0 -34
  85. data/app/models/shop_variant.rb +0 -23
  86. data/app/views/admin/pages/_shop_category.html.haml +0 -4
  87. data/app/views/admin/pages/_shop_product.html.haml +0 -4
  88. data/app/views/admin/shop/discounts/edit/_foot.html.haml +0 -16
  89. data/app/views/admin/shop/discounts/edit/_form.html.haml +0 -15
  90. data/app/views/admin/shop/discounts/edit/_head.html.haml +0 -4
  91. data/app/views/admin/shop/discounts/edit/_inputs.html.haml +0 -2
  92. data/app/views/admin/shop/discounts/edit/_meta.html.haml +0 -8
  93. data/app/views/admin/shop/discounts/edit/_parts.html.haml +0 -9
  94. data/app/views/admin/shop/discounts/edit/_popups.html.haml +0 -4
  95. data/app/views/admin/shop/discounts/edit/buttons/_browse_categories.html.haml +0 -1
  96. data/app/views/admin/shop/discounts/edit/buttons/_browse_products.html.haml +0 -1
  97. data/app/views/admin/shop/discounts/edit/inputs/_amount.html.haml +0 -3
  98. data/app/views/admin/shop/discounts/edit/inputs/_code.html.haml +0 -3
  99. data/app/views/admin/shop/discounts/edit/inputs/_name.html.haml +0 -3
  100. data/app/views/admin/shop/discounts/edit/meta/_finish.html.haml +0 -5
  101. data/app/views/admin/shop/discounts/edit/meta/_start.html.haml +0 -5
  102. data/app/views/admin/shop/discounts/edit/parts/_categories.html.haml +0 -3
  103. data/app/views/admin/shop/discounts/edit/parts/_products.html.haml +0 -3
  104. data/app/views/admin/shop/discounts/edit/popups/_browse_categories.html.haml +0 -6
  105. data/app/views/admin/shop/discounts/edit/popups/_browse_products.html.haml +0 -6
  106. data/app/views/admin/shop/discounts/edit/shared/_category.html.haml +0 -11
  107. data/app/views/admin/shop/discounts/edit/shared/_product.html.haml +0 -12
  108. data/app/views/admin/shop/discounts/edit.html.haml +0 -11
  109. data/app/views/admin/shop/discounts/index/_discount.html.haml +0 -13
  110. data/app/views/admin/shop/discounts/index/_foot.html.haml +0 -5
  111. data/app/views/admin/shop/discounts/index/_head.html.haml +0 -2
  112. data/app/views/admin/shop/discounts/index/buttons/_new_discount.html.haml +0 -1
  113. data/app/views/admin/shop/discounts/index.html.haml +0 -13
  114. data/app/views/admin/shop/discounts/new.html.haml +0 -11
  115. data/app/views/admin/shop/discounts/remove.html.haml +0 -12
  116. data/app/views/admin/shop/packages/edit/_foot.html.haml +0 -17
  117. data/app/views/admin/shop/packages/edit/_form.html.haml +0 -15
  118. data/app/views/admin/shop/packages/edit/_head.html.haml +0 -4
  119. data/app/views/admin/shop/packages/edit/_inputs.html.haml +0 -2
  120. data/app/views/admin/shop/packages/edit/_meta.html.haml +0 -8
  121. data/app/views/admin/shop/packages/edit/_parts.html.haml +0 -9
  122. data/app/views/admin/shop/packages/edit/_popups.html.haml +0 -4
  123. data/app/views/admin/shop/packages/edit/buttons/_browse_products.html.haml +0 -1
  124. data/app/views/admin/shop/packages/edit/inputs/_name.html.haml +0 -3
  125. data/app/views/admin/shop/packages/edit/inputs/_price.html.haml +0 -3
  126. data/app/views/admin/shop/packages/edit/meta/_sku.html.haml +0 -5
  127. data/app/views/admin/shop/packages/edit/parts/_description.html.haml +0 -1
  128. data/app/views/admin/shop/packages/edit/parts/_products.html.haml +0 -3
  129. data/app/views/admin/shop/packages/edit/popups/_browse_products.html.haml +0 -7
  130. data/app/views/admin/shop/packages/edit/shared/_product.html.haml +0 -8
  131. data/app/views/admin/shop/packages/edit.html.haml +0 -11
  132. data/app/views/admin/shop/packages/index/_foot.html.haml +0 -8
  133. data/app/views/admin/shop/packages/index/_head.html.haml +0 -2
  134. data/app/views/admin/shop/packages/index/_package.html.haml +0 -9
  135. data/app/views/admin/shop/packages/index/buttons/_new_package.html.haml +0 -1
  136. data/app/views/admin/shop/packages/index.html.haml +0 -13
  137. data/app/views/admin/shop/packages/new.html.haml +0 -11
  138. data/app/views/admin/shop/packages/remove.html.haml +0 -12
  139. data/app/views/admin/shop/products/edit/buttons/_browse_templates.html.haml +0 -1
  140. data/app/views/admin/shop/products/edit/buttons/_new_variant.html.haml +0 -1
  141. data/app/views/admin/shop/products/edit/parts/_variants.html.haml +0 -3
  142. data/app/views/admin/shop/products/edit/popups/_browse_templates.html.haml +0 -6
  143. data/app/views/admin/shop/products/edit/popups/_new_variant.html.haml +0 -16
  144. data/app/views/admin/shop/products/edit/shared/_template.html.haml +0 -6
  145. data/app/views/admin/shop/products/edit/shared/_variant.html.haml +0 -10
  146. data/app/views/admin/shop/products/index/buttons/_variants.html.haml +0 -1
  147. data/app/views/admin/shop/variants/edit/_foot.html.haml +0 -9
  148. data/app/views/admin/shop/variants/edit/_form.html.haml +0 -13
  149. data/app/views/admin/shop/variants/edit/_head.html.haml +0 -4
  150. data/app/views/admin/shop/variants/edit/_inputs.html.haml +0 -2
  151. data/app/views/admin/shop/variants/edit/_meta.html.haml +0 -8
  152. data/app/views/admin/shop/variants/edit/_parts.html.haml +0 -9
  153. data/app/views/admin/shop/variants/edit/_popups.html.haml +0 -4
  154. data/app/views/admin/shop/variants/edit/inputs/_name.html.haml +0 -3
  155. data/app/views/admin/shop/variants/edit/inputs/_options.html.haml +0 -3
  156. data/app/views/admin/shop/variants/edit.html.haml +0 -11
  157. data/app/views/admin/shop/variants/index/_foot.html.haml +0 -5
  158. data/app/views/admin/shop/variants/index/_head.html.haml +0 -2
  159. data/app/views/admin/shop/variants/index/_variant.html.haml +0 -9
  160. data/app/views/admin/shop/variants/index/buttons/_add_variant.html.haml +0 -1
  161. data/app/views/admin/shop/variants/index/buttons/_categories.html.haml +0 -1
  162. data/app/views/admin/shop/variants/index.html.haml +0 -13
  163. data/app/views/admin/shop/variants/new.html.haml +0 -11
  164. data/app/views/admin/shop/variants/remove.html.haml +0 -12
  165. data/app/views/shop/categories/show.html.haml +0 -1
  166. data/app/views/shop/orders/show.html.haml +0 -1
  167. data/app/views/shop/products/index.html.haml +0 -1
  168. data/app/views/shop/products/show.html.haml +0 -1
  169. data/cucumber.yml +0 -1
  170. data/db/migrate/20100311053701_initial.rb +0 -153
  171. data/db/migrate/20100927041219_remove_payment_methods.rb +0 -16
  172. data/db/migrate/20100927041624_change_payments_add_gateway.rb +0 -11
  173. data/db/migrate/20100927140446_change_payment_add_card_type_card_number.rb +0 -11
  174. data/db/migrate/20100929011106_fix_relationship_foreign_keys.rb +0 -101
  175. data/db/migrate/20100929011607_drop_shop_addressables.rb +0 -25
  176. data/db/migrate/20100929030510_create_shop_groups.rb +0 -19
  177. data/db/migrate/20100929080301_shop_groups_change_add_description.rb +0 -11
  178. data/db/migrate/20100929081200_create_variants.rb +0 -20
  179. data/db/migrate/20100929143531_change_variants_add_updated_by.rb +0 -25
  180. data/db/migrate/20100929145641_change_created_by_to_id.rb +0 -75
  181. data/db/migrate/20100929235221_change_category_add_variant_id.rb +0 -9
  182. data/db/migrate/20100930235221_create_packages.rb +0 -31
  183. data/db/migrate/20101005231713_create_page_ids.rb +0 -11
  184. data/db/migrate/20101006051214_create_pages_for_products_and_categories.rb +0 -73
  185. data/db/migrate/20101007111845_add_default_position_to_attachment.rb +0 -9
  186. data/db/migrate/20101010071143_create_discounts.rb +0 -29
  187. data/db/migrate/20101010072225_modify_categories_remove_variant.rb +0 -9
  188. data/db/migrate/20101010130034_change_discountables_add_observer.rb +0 -15
  189. data/db/migrate/20101011063133_change_orders_set_limits_to_null.rb +0 -11
  190. data/features/support/env.rb +0 -16
  191. data/features/support/paths.rb +0 -14
  192. data/lib/shop/interface/packages.rb +0 -34
  193. data/lib/shop/interface/variants.rb +0 -34
  194. data/lib/shop/tags/package.rb +0 -95
  195. data/lib/shop/tags/product_variant.rb +0 -52
  196. data/lib/shop/tags/responses.rb +0 -34
  197. data/mockups/balsamiq/products-retro_fun_tshirt-more.bmml +0 -0
  198. data/mockups/balsamiq/products-retro_fun_tshirt.bmml +0 -0
  199. data/mockups/discounts/new-edit.bmml +0 -492
  200. data/public/javascripts/admin/extensions/shop/discounts/edit.js +0 -76
  201. data/public/javascripts/admin/extensions/shop/packages/edit.js +0 -109
  202. data/public/stylesheets/sass/admin/extensions/shop/discounts/edit.sass +0 -125
  203. data/public/stylesheets/sass/admin/extensions/shop/packages/edit.sass +0 -162
  204. data/spec/controllers/admin/shop/discounts/discountables_controller_spec.rb +0 -73
  205. data/spec/controllers/admin/shop/discounts_controller_spec.rb +0 -81
  206. data/spec/controllers/admin/shop/packages/packings_controller_spec.rb +0 -188
  207. data/spec/controllers/admin/shop/packages_controller_spec.rb +0 -32
  208. data/spec/controllers/admin/shop/products/variant_templates_controller_spec.rb +0 -53
  209. data/spec/controllers/admin/shop/products/variants_controller_spec.rb +0 -116
  210. data/spec/controllers/admin/shop/variants_controller_spec.rb +0 -67
  211. data/spec/datasets/shop_discountables.rb +0 -22
  212. data/spec/datasets/shop_discounts.rb +0 -29
  213. data/spec/datasets/shop_groups.rb +0 -15
  214. data/spec/datasets/shop_packages.rb +0 -25
  215. data/spec/datasets/shop_product_variants.rb +0 -22
  216. data/spec/datasets/shop_variants.rb +0 -17
  217. data/spec/lib/shop/tags/package_spec.rb +0 -342
  218. data/spec/lib/shop/tags/product_variant_spec.rb +0 -175
  219. data/spec/lib/shop/tags/responses_spec.rb +0 -129
  220. data/spec/models/form_discount_spec.rb +0 -63
  221. data/spec/models/shop_discount_spec.rb +0 -130
  222. data/spec/models/shop_discountable_spec.rb +0 -114
  223. data/spec/models/shop_group_spec.rb +0 -38
  224. data/spec/models/shop_package_spec.rb +0 -117
  225. data/spec/models/shop_packing_spec.rb +0 -67
  226. data/spec/models/shop_product_variant_spec.rb +0 -92
  227. data/spec/models/shop_variant_spec.rb +0 -32
data/db/seeds/layouts.rb CHANGED
@@ -1,111 +1,75 @@
1
- Layout.create({
2
- :name => 'Application',
3
- :content => <<-CONTENT
4
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
5
- <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
6
- <head>
7
- <title><r:title /></title>
8
- </head>
9
- <body>
10
- <r:snippet name='CartOverview' />
11
- <r:content_for_layout />
12
- </body>
13
- </html>
14
- CONTENT
15
- })
16
-
17
- Layout.create({
18
- :name => Radiant::Config['shop.product_layout'],
19
- :content => <<-CONTENT
20
- <r:inside_layout name='Application'>
1
+ #---------------------------------------------------#
2
+ # Product Layout
3
+ #---------------------------------------------------#
4
+ product = Layout.new
5
+ product.name = Radiant::Config['shop.layout_product']
6
+ product.content = <<-CONTENT
7
+ <!DOCTYPE html>
8
+ <html>
21
9
  <r:shop:product>
22
- <div id="shop_product_<r:sku />" class="shop_product">
23
- <h2><r:title /></h2>
24
- <h3><r:price /></h3>
25
- <dl id="shop_product_details">
26
- <dd>Description</dt>
27
- <dd class="body"><r:description /></dd>
28
- <dd>Add To Cart</dt>
29
- <dd class="add"><r:form name="AddCartItem" /></dd>
30
- </dl>
31
- <r:if_images>
32
- <ul id="shop_product_images">
33
- <r:images:each>
34
- <li class="shop_product_image" id="shop_product_image_<r:sku />">
35
- <a href="<r:image style='normal' />" title="<r:title />"">
36
- <img id="shop_product_image_<r:position />" class="shop_product_image" src="<r:image style='thumbnail'/>" alt="<r:title />" />
37
- </a>
38
- </li>
39
- </r:images:each>
40
- </ul>
41
- </r:if_images>
42
- <r:unless_images>
43
- <p class="error" id="shop_no_product_images_error">We don't have any images for this product yet.</p>
44
- </r:unless_images>
45
- </div>
10
+ <head>
11
+ <title>Product - <r:name /></title>
12
+ </head>
13
+ <body>
14
+
15
+ <r:snippet name='CartOverview' />
16
+
17
+ <div id="product_<r:slug />" class="product" data-id="<r:id />">
18
+ <h2><r:title /></h2>
19
+ <h3><r:price /></h3>
20
+ <dl id="product_details">
21
+ <dt class="description">Description</dt>
22
+ <dd class="description"><r:description /></dd>
23
+ <dt class="add_product">Add To Cart</dt>
24
+ <dd class="add_product"><r:form name="CartAddProduct" /></dd>
25
+ </dl>
26
+ </div>
27
+ </body>
46
28
  </r:shop:product>
47
- </r:inside_layout>
29
+ </html>
48
30
  CONTENT
49
- })
31
+ product.save
50
32
 
51
- Layout.create({
52
- :name => Radiant::Config['shop.category_layout'],
53
- :content => <<-CONTENT
54
- <r:inside_layout name='Application'>
33
+ #---------------------------------------------------#
34
+ # Category Layout
35
+ #---------------------------------------------------#
36
+ category = Layout.new
37
+ category.name = Radiant::Config['shop.layout_category']
38
+ category.content = <<-CONTENT
39
+ <!DOCTYPE html>
40
+ <html>
55
41
  <r:shop:category>
56
- <div id="shop_category_<r:handle />" class="shop_category">
57
- <h2 class="shop_category_title"><r:title /></h2>
58
- <div id="shop_category_description">
59
- <h3>Description</h3>
60
- <div class="body"><r:description /></div>
42
+ <head>
43
+ <title>Product - <r:name /></title>
44
+ </head>
45
+ <body>
46
+
47
+ <r:snippet name='CartOverview' />
48
+
49
+ <div id="category_<r:slug />" class="category" data-id="<r:id />">
50
+ <h2><r:title /></h2>
51
+ <dl id="description_details">
52
+ <dt class="description">Description</dt>
53
+ <dd class="description"><r:description /></dd>
54
+ </div>
55
+ <r:products>
56
+ <r:if_products>
57
+ <ul class="category_products">
58
+ <r:each:product>
59
+ <li class="product" id="product_<r:sku />" data-id="<r:id />"
60
+ <h3><r:link /></h3>
61
+ <h4><r:price /></h4>
62
+ </li>
63
+ </r:each:product>
64
+ </ul>
65
+ </r:if_products>
66
+ <r:unless_products>
67
+ <p class="error" id="shop_no_products_error">We don't have any products available here yet.</p>
68
+ </r:unless_products>
69
+ </r:products>
61
70
  </div>
62
- <r:if_products>
63
- <ul class="shop_products" id="shop_products_<r:handle/>" >
64
- <r:products:each:product>
65
- <li class="shop_product" id="shop_product_<r:sku />">
66
- <r:image position='1'>
67
- <r:link><img src="<r:url style='preview' />" alt="<r:handle />" class="shop_product_image" /></r:link>
68
- </r:image>
69
- <h3 class="shop_product_name"><r:link><r:name /> <small><r:price /></small></r:link></h3>
70
- <div class="shop_product_description"><r:description /></div>
71
- </li>
72
- </r:products:each:product>
73
- </ul>
74
- </r:if_products>
75
- <r:unless_products>
76
- <p class="error" id="shop_no_products_error">We don't have any products available here yet.</p>
77
- </r:unless_products>
78
- </div>
71
+ </body>
79
72
  </r:shop:category>
80
- </r:inside_layout>
81
- CONTENT
82
- })
83
-
84
- Layout.create({
85
- :name => Radiant::Config['shop.order_layout'],
86
- :content => <<-CONTENT
87
- <r:inside_layout name='Application'>
88
- <r:shop:cart>
89
- <r:if_items>
90
- <ol class="items">
91
- <r:items:each>
92
- <r:item>
93
- <li class="item" id="item_<r:id />">
94
- <span class="quantity"><r:quantity /></span>
95
- <span class="name"><r:link><r:name /></r:link></name></span>
96
- <span class="update"><r:form name="UpdateCartItem" /></span>
97
- <span class="price"><r:price /></span>
98
- <span class="remove"><r:remove /></span>
99
- </li>
100
- </r:item>
101
- </r:items:each>
102
- </ol>
103
- <span class="total"><r:price /></span>
104
- </r:if_items>
105
- <r:unless_items>
106
- <p>Your cart is currently empty</p>
107
- </r:unless_items>
108
- </r:shop:cart>
109
- </r:inside_layout>
73
+ </html>
110
74
  CONTENT
111
- })
75
+ category.save
data/db/seeds/pages.rb ADDED
@@ -0,0 +1,101 @@
1
+ unless Page.first
2
+ Radiant::Config['defaults.page.status'] = 'Published'
3
+
4
+ home = Page.new
5
+ home.title = 'Shop'
6
+ home.slug = '/'
7
+ home.breadcrumb = 'shop'
8
+ home.class_name = 'ShopPage'
9
+ home.status_id = 100
10
+ home.parts = [
11
+ PagePart.create({
12
+ :name => 'body',
13
+ :filter_id => 'Textile',
14
+ :content => <<-CONTENT
15
+ "category":/category
16
+
17
+ "product":/category/product
18
+
19
+ <r:shop:cart:if_cart:items:if_items>"checkout":/cart</r:shop:cart:if_cart:items:if_items>
20
+ CONTENT
21
+ })
22
+ ]
23
+ home.save
24
+ end
25
+
26
+ Radiant::Config['shop.root_page_id'] = Page.first.id
27
+
28
+ cart = Page.new
29
+ cart.title = 'Cart'
30
+ cart.slug = 'cart'
31
+ cart.breadcrumb = 'cart'
32
+ cart.parent = Page.first
33
+ cart.class_name = 'ShopPage'
34
+ cart.status_id = 100
35
+ cart.parts = [
36
+ PagePart.create({
37
+ :name => 'body',
38
+ :content => "<r:snippet name='Cart' />"
39
+ })
40
+ ]
41
+ cart.save
42
+
43
+ address = Page.new
44
+ address.title = 'Address'
45
+ address.slug = 'address'
46
+ address.breadcrumb = 'address'
47
+ address.parent = cart
48
+ address.class_name = 'ShopPage'
49
+ address.status_id = 100
50
+ address.parts = [
51
+ PagePart.create({
52
+ :name => 'body',
53
+ :content => "<r:form name='CartAddress' />"
54
+ })
55
+ ]
56
+ address.save
57
+
58
+ payment = Page.new
59
+ payment.title = 'Payment'
60
+ payment.slug = 'payment'
61
+ payment.breadcrumb = 'payment'
62
+ payment.parent = cart
63
+ payment.class_name = 'ShopPage'
64
+ payment.status_id = 100
65
+ payment.parts = [
66
+ PagePart.create({
67
+ :name => 'body',
68
+ :content => "<r:form name='CartPayment' />"
69
+ })
70
+ ]
71
+ payment.save
72
+
73
+ payment = Page.new
74
+ payment.title = 'Thanks'
75
+ payment.slug = 'thanks'
76
+ payment.breadcrumb = 'thanks'
77
+ payment.parent = cart
78
+ payment.class_name = 'ShopPage'
79
+ payment.status_id = 100
80
+ payment.parts = [
81
+ PagePart.create({
82
+ :name => 'body',
83
+ :filter_id => 'Textile',
84
+ :content => <<-CONTENT
85
+ <r:shop:cart:if_cart:payment:if_paid>
86
+
87
+ h2. Thank You
88
+
89
+ Your payment for <r:shop:cart:price /> has been received from your **<r:response:get name="card[type]" /> card**.
90
+
91
+ If you have any queries please contact us and quote order number **#<r:cart:id />**.
92
+
93
+ <r:forget />
94
+
95
+ "home":/
96
+
97
+ </r:shop:cart:if_cart:payment:if_paid>
98
+ CONTENT
99
+ })
100
+ ]
101
+ payment.save
@@ -0,0 +1,29 @@
1
+ category = ShopCategory.create({
2
+ :page_attributes => {
3
+ :title => 'Category',
4
+ :slug => 'category',
5
+ :parent => Page.first,
6
+ :layout => Layout.find_by_name(Radiant::Config['shop.layout_category']),
7
+ :status_id => 100,
8
+ :parts_attributes => [{
9
+ :name => 'description',
10
+ :content => 'I am a category'
11
+ }]
12
+ }
13
+ })
14
+
15
+ product = ShopProduct.create({
16
+ :price => 10.00,
17
+ :page_attributes => {
18
+ :title => 'Product',
19
+ :parent => category.page,
20
+ :slug => 'product',
21
+ :layout => Layout.find_by_name(Radiant::Config['shop.layout_product']),
22
+ :status_id => 100,
23
+ :parts_attributes => [{
24
+ :name => 'description',
25
+ :content => 'I am a product'
26
+ }]
27
+ }
28
+ })
29
+
data/db/seeds/snippets.rb CHANGED
@@ -1,23 +1,38 @@
1
- Snippet.create({
2
- :name => 'CartOverview',
3
- :content => <<-BEGIN
1
+ #---------------------------------------------------#
2
+ # CartOverview Snippet
3
+ #---------------------------------------------------#
4
+ overview = Snippet.new
5
+ overview.name = 'CartOverview'
6
+ overview.content = <<-CONTENT
7
+ <r:shop:cart:if_cart:items:if_items>
8
+ <dl id="cart_overview">
9
+ <dt class="price">Price</dt>
10
+ <dd class="price"><r:price /></dd>
11
+ <dt class="total">Quantity</dt>
12
+ <dd class="total"><r:quantity /></dd>
13
+ <dt><a href="/cart" title="View Cart">View Cart</a></dt>
14
+ </dl>
15
+ </r:shop:cart:if_cart:items:if_items>
16
+ CONTENT
17
+ overview.save
18
+
19
+ #---------------------------------------------------#
20
+ # Cart Snippet
21
+ #---------------------------------------------------#
22
+ cart = Snippet.new
23
+ cart.name = 'Cart'
24
+ cart.content = <<-CONTENT
4
25
  <r:shop:cart>
5
- <r:if_items>
6
- <span class="quantity"><r:quantity /></span>
7
- <span class="price"><r:price /></span>
8
- <r:link>checkout</r:link>
9
- </r:if_items>
10
- <r:unless_items>
11
- <p>Your cart is empty</p>
12
- </r:unless_items>
26
+ <ol id="cart">
27
+ <r:items:each:item>
28
+ <li class="item">
29
+ <span class="quantity"><r:quantity /></span>
30
+ <span class="price"><r:price /></span>
31
+ <span class="name"><r:name /></span>
32
+ </li>
33
+ </r:items:each:item>
34
+ </ol>
35
+ <a href="/cart/address" title="Checkout">Checkout</a>
13
36
  </r:shop:cart>
14
- BEGIN
15
- })
16
-
17
- PaymentResponse
18
-
19
- <r:response:checkout:payment:unless_success>
20
- <p>We couldn't process your payment: <strong><r:response:get name="results[checkout][payment][message]" /></strong></p>
21
- </r:response:checkout:payment:unless_success>
22
-
23
- <r:response:clear />
37
+ CONTENT
38
+ cart.save
@@ -6,14 +6,16 @@ module Shop
6
6
  base.class_eval do
7
7
  def current_shop_order
8
8
  return @current_shop_order if defined?(@current_shop_order)
9
- @current_shop_order = find_shop_order
9
+ @current_shop_order = find_or_create_shop_order if request.session[:shop_order]
10
10
  end
11
11
 
12
12
  def find_shop_order
13
13
  shop_order = nil
14
14
 
15
- if request.session[:shop_order]
15
+ begin
16
16
  shop_order = ShopOrder.find(request.session[:shop_order])
17
+ rescue
18
+ shop_order = nil
17
19
  end
18
20
 
19
21
  shop_order
@@ -22,7 +24,7 @@ module Shop
22
24
  def find_or_create_shop_order
23
25
  shop_order = nil
24
26
 
25
- if find_shop_order and find_shop_order.status != 'paid'
27
+ if find_shop_order
26
28
  shop_order = find_shop_order
27
29
  else
28
30
  shop_order = ShopOrder.create({ :customer_id => (current_user.id rescue nil) })
@@ -24,8 +24,7 @@ module Shop
24
24
  # Returns the current logged in ShopCustomer (if it exists)
25
25
  def current_customer
26
26
  return @shop_customer if @shop_customer.present?
27
- return current_user if current_user.present?
28
- @shop_customer = ShopCustomer.find(current_user.id) rescue nil
27
+ @shop_customer = current_user if current_user.present?
29
28
  end
30
29
  end
31
30
  end
@@ -6,7 +6,6 @@ module Shop
6
6
  base.class_eval do
7
7
  has_one :shop_category, :dependent => :delete
8
8
  has_one :shop_product, :dependent => :delete
9
-
10
9
  end
11
10
  end
12
11
 
@@ -9,7 +9,6 @@ module Shop
9
9
  has_many :shippings, :through => :orders
10
10
 
11
11
  accepts_nested_attributes_for :orders, :allow_destroy => true
12
-
13
12
  end
14
13
  end
15
14
 
@@ -2,7 +2,7 @@ module Shop
2
2
  module Tags
3
3
  module Card
4
4
 
5
- TYPES = {
5
+ CARD_TYPES = {
6
6
  'visa' => 'Visa',
7
7
  'mastercard' => 'Master Card',
8
8
  'diners' => 'Diners Club',
@@ -19,7 +19,13 @@ module Shop
19
19
  desc %{ Outputs a list of credit card types }
20
20
  tag 'form:card:type' do |tag|
21
21
  content = %{<select name="card[type]" id="card_type">\n}
22
- TYPES.sort.each do |k, v|
22
+ cards = {}
23
+ cards.merge! CARD_TYPES
24
+
25
+ cards.reject! { |k,v| tag.attr['except'].split(',').include? k } if tag.attr['except'].present?
26
+ cards.reject! { |k,v| !tag.attr['only'].split(',').include? k }if tag.attr['only'].present?
27
+
28
+ cards.sort.each do |k, v|
23
29
  content << %{<option value="#{k}">#{v}</option>\n}
24
30
  end
25
31
  content << %{</select>}
@@ -11,6 +11,10 @@ module Shop
11
11
  tag.expand
12
12
  end
13
13
 
14
+ tag 'shop:cart:forget' do |tag|
15
+ tag.locals.page.request.session[:shop_order] = nil
16
+ end
17
+
14
18
  # Expand if a user has started a cart
15
19
  desc %{ Expand if a user has started a cart }
16
20
  tag 'shop:cart:if_cart' do |tag|
@@ -44,7 +48,7 @@ module Shop
44
48
  # Returns the date of the payment
45
49
  desc %{ Returns the date of the payment }
46
50
  tag 'shop:cart:payment:date' do |tag|
47
- tag.locals.shop_order.payment.created_at.to_s(:long)
51
+ tag.locals.shop_order.payment.created_at.strftime(Radiant::Config['shop.date_format'])
48
52
  end
49
53
 
50
54
  # Display the cart id / status
@@ -112,7 +112,12 @@ module Shop
112
112
  :joins => :page,
113
113
  :conditions => [ "pages.slug = ?", tag.attr['sku'] ]
114
114
  )
115
-
115
+
116
+ elsif tag.attr['position']
117
+ children = tag.locals.shop_category.page.children
118
+ result = children.first(:conditions => { :class_name => 'ShopProductPage', :position => tag.attr['position'].to_i }) || children.first(:conditions => {:class_name => 'ShopProductPage'})
119
+ result = result.shop_product
120
+
116
121
  elsif tag.locals.shop_line_item.present? and tag.locals.shop_line_item.item_type === 'ShopProduct'
117
122
  result = tag.locals.shop_line_item.item
118
123
 
@@ -124,6 +129,20 @@ module Shop
124
129
  result
125
130
  end
126
131
 
132
+ def current_image(tag)
133
+ result = nil
134
+
135
+ if tag.locals.image.present?
136
+ result = tag.locals.image.image rescue tag.locals.image
137
+
138
+ elsif tag.attr['position']
139
+ result = tag.locals.images.find_by_position(tag.attr['position'].to_i)
140
+
141
+ end
142
+
143
+ result
144
+ end
145
+
127
146
  def current_order(tag)
128
147
  result = nil
129
148
 
@@ -136,7 +155,10 @@ module Shop
136
155
  elsif tag.locals.page.request.session[:shop_order].present?
137
156
  session = tag.locals.page.request.session[:shop_order]
138
157
  result = ShopOrder.find(session)
139
-
158
+
159
+ elsif tag.locals.response.present? and tag.locals.response.result[:checkout].present?
160
+ result = ShopOrder.find(tag.locals.response.result[:checkout][:order])
161
+
140
162
  end
141
163
 
142
164
  result
@@ -147,8 +169,6 @@ module Shop
147
169
 
148
170
  if tag.locals.shop_line_items.present?
149
171
  result = tag.locals.shop_line_items
150
- elsif tag.attr['key'] and tag.attr['value']
151
- result = tag.locals.shop_order.line_items.all(:conditions => { tag.attr['key'].downcase.to_sym => tag.attr['value'] })
152
172
  else
153
173
  result = tag.locals.shop_order.line_items
154
174
  end
@@ -193,63 +213,18 @@ module Shop
193
213
  result
194
214
  end
195
215
 
196
- def current_packages(tag)
197
- result = nil
198
-
199
- if tag.locals.shop_product.present?
200
- result = tag.locals.shop_product.packages
201
-
202
- elsif tag.attr['key'] and tag.attr['value']
203
- result = ShopPackage.all(:conditions => { tag.attr['key'].downcase.to_sym => tag.attr['value']})
204
-
205
- else
206
- result = ShopPackage.all
207
-
208
- end
209
-
210
- result
211
- end
212
-
213
- def current_package(tag)
214
- result = nil
215
-
216
- if tag.locals.shop_package.present?
217
- result = tag.locals.shop_package
218
-
219
- elsif tag.attr['key'] and tag.attr['value']
220
- result = ShopPackage.first(:conditions => { tag.attr['key'].downcase.to_sym => tag.attr['value']})
221
-
222
- end
223
-
224
- result
225
- end
226
-
227
- def current_product_variants(tag)
228
- result = nil
229
-
230
- if tag.locals.shop_product.present?
231
- result = tag.locals.shop_product.variants
232
- end
233
-
234
- result
235
- end
236
-
237
- def current_product_variant(tag)
238
- result = nil
239
-
240
- if tag.locals.shop_product_variant.present?
241
- result = tag.locals.shop_product_variant
242
- end
243
-
244
- result
245
- end
246
-
247
216
  def currency(number,attr = {})
248
- number_to_currency(number.to_f,
249
- :precision =>(attr[:precision] || Radiant::Config['shop.price_precision']).to_i,
250
- :unit => attr[:unit] || Radiant::Config['shop.price_unit'],
251
- :separator => attr[:separator] || Radiant::Config['shop.price_separator'],
252
- :delimiter => attr[:delimiter] || Radiant::Config['shop.price_delimiter'])
217
+ precision = attr[:precision].present? ? attr[:precision] : Radiant::Config['shop.price_precision']
218
+ unit = attr[:unit].present? ? attr[:unit] : Radiant::Config['shop.price_unit']
219
+ separator = attr[:separator].present? ? attr[:separator] : Radiant::Config['shop.price_separator']
220
+ delimiter = attr[:delimiter].present? ? attr[:delimiter] : Radiant::Config['shop.price_delimiter']
221
+
222
+ number_to_currency(number.to_f, {
223
+ :precision => precision.to_i,
224
+ :unit => unit,
225
+ :separator => separator,
226
+ :delimiter => delimiter
227
+ })
253
228
  end
254
229
 
255
230
  end
@@ -66,7 +66,7 @@ module Shop
66
66
  end
67
67
  end
68
68
 
69
- [:price, :value, :discounted].each do |symbol|
69
+ [:price].each do |symbol|
70
70
  desc %{ outputs the #{symbol} of the current cart item }
71
71
  tag "shop:cart:item:#{symbol}" do |tag|
72
72
  attr = tag.attr.symbolize_keys
@@ -76,20 +76,6 @@ module Shop
76
76
  end
77
77
  end
78
78
 
79
- desc %{ expands if the item has a discount}
80
- tag "shop:cart:item:if_discounted" do |tag|
81
- item = tag.locals.shop_line_item
82
-
83
- tag.expand if item.price != item.value
84
- end
85
-
86
- desc %{ expands if the item has a discount}
87
- tag "shop:cart:item:unless_discounted" do |tag|
88
- item = tag.locals.shop_line_item
89
-
90
- tag.expand if item.price == item.value
91
- end
92
-
93
79
  desc %{ generates a link to the items generated page }
94
80
  tag 'shop:cart:item:link' do |tag|
95
81
  item = tag.locals.shop_line_item.item
@@ -99,7 +85,7 @@ module Shop
99
85
 
100
86
  text = tag.double? ? tag.expand : item.name
101
87
 
102
- %{<a href="#{item.slug}"#{attributes}>#{text}</a>}
88
+ %{<a href="#{item.url}"#{attributes}>#{text}</a>}
103
89
  end
104
90
 
105
91
  end
@@ -100,6 +100,13 @@ module Shop
100
100
  content
101
101
  end
102
102
 
103
+ desc %{ iterates through each of the products images }
104
+ tag 'shop:product:images:image' do |tag|
105
+ tag.locals.image = Helpers.current_image(tag)
106
+
107
+ tag.expand
108
+ end
109
+
103
110
  end
104
111
  end
105
112
  end