radiant-shop-extension 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (272) hide show
  1. data/README.md +5 -1
  2. data/VERSION +1 -1
  3. data/app/controllers/admin/shop/categories_controller.rb +32 -65
  4. data/app/controllers/admin/shop/customers_controller.rb +8 -7
  5. data/app/controllers/admin/shop/orders_controller.rb +37 -159
  6. data/app/controllers/admin/shop/packages/packings_controller.rb +90 -0
  7. data/app/controllers/admin/shop/packages_controller.rb +65 -0
  8. data/app/controllers/admin/shop/products/images_controller.rb +5 -8
  9. data/app/controllers/admin/shop/products/variant_templates_controller.rb +27 -0
  10. data/app/controllers/admin/shop/products/variants_controller.rb +60 -0
  11. data/app/controllers/admin/shop/products_controller.rb +67 -64
  12. data/app/controllers/admin/shop/variants_controller.rb +49 -0
  13. data/app/helpers/shop_helper.rb +5 -0
  14. data/app/models/form_address.rb +144 -0
  15. data/app/models/form_checkout.rb +200 -307
  16. data/app/models/form_line_item.rb +60 -0
  17. data/app/models/shop_address.rb +2 -2
  18. data/app/models/shop_category.rb +48 -51
  19. data/app/models/shop_customer.rb +25 -5
  20. data/app/models/shop_group.rb +15 -0
  21. data/app/models/shop_grouping.rb +6 -0
  22. data/app/models/shop_line_item.rb +7 -6
  23. data/app/models/shop_order.rb +44 -16
  24. data/app/models/shop_package.rb +74 -0
  25. data/app/models/shop_packing.rb +22 -0
  26. data/app/models/shop_page.rb +7 -0
  27. data/app/models/shop_payment.rb +5 -1
  28. data/app/models/shop_product.rb +86 -48
  29. data/app/models/shop_product_attachment.rb +5 -2
  30. data/app/models/shop_product_variant.rb +31 -0
  31. data/app/models/shop_variant.rb +25 -0
  32. data/app/views/admin/shop/categories/edit.html.haml +9 -10
  33. data/app/views/admin/shop/categories/edit/_foot.html.haml +9 -0
  34. data/app/views/admin/shop/categories/edit/_form.html.haml +14 -0
  35. data/app/views/admin/shop/categories/edit/_head.html.haml +4 -2
  36. data/app/views/admin/shop/categories/edit/_inputs.html.haml +2 -0
  37. data/app/views/admin/shop/categories/edit/_meta.html.haml +8 -7
  38. data/app/views/admin/shop/categories/edit/_parts.html.haml +9 -0
  39. data/app/views/admin/shop/categories/edit/_popups.html.haml +4 -0
  40. data/app/views/admin/shop/categories/edit/inputs/_name.html.haml +4 -0
  41. data/app/views/admin/shop/categories/edit/meta/_handle.html.haml +6 -5
  42. data/app/views/admin/shop/categories/edit/meta/_layouts.html.haml +6 -5
  43. data/app/views/admin/shop/categories/edit/meta/_page.html.haml +3 -0
  44. data/app/views/admin/shop/categories/edit/parts/_description.html.haml +4 -1
  45. data/app/views/admin/shop/categories/index/_category.html.haml +11 -10
  46. data/app/views/admin/shop/categories/new.html.haml +10 -9
  47. data/app/views/admin/shop/customers/edit.html.haml +8 -10
  48. data/app/views/admin/shop/customers/edit/_foot.html.haml +9 -0
  49. data/app/views/admin/shop/customers/edit/_form.html.haml +13 -0
  50. data/app/views/admin/shop/customers/edit/_head.html.haml +4 -2
  51. data/app/views/admin/shop/customers/edit/_inputs.html.haml +2 -0
  52. data/app/views/admin/shop/customers/edit/_parts.html.haml +9 -4
  53. data/app/views/admin/shop/customers/edit/inputs/_email.html.haml +3 -0
  54. data/app/views/admin/shop/customers/edit/inputs/_name.html.haml +3 -0
  55. data/app/views/admin/shop/customers/edit/parts/_orders.html.haml +10 -6
  56. data/app/views/admin/shop/customers/index.html.haml +4 -1
  57. data/app/views/admin/shop/customers/index/_customer.html.haml +3 -3
  58. data/app/views/admin/shop/customers/index/_foot.html.haml +4 -0
  59. data/app/views/admin/shop/customers/index/_head.html.haml +4 -0
  60. data/app/views/admin/shop/customers/new.html.haml +9 -9
  61. data/app/views/admin/shop/orders/edit.html.haml +11 -0
  62. data/app/views/admin/shop/orders/edit/_foot.html.haml +9 -0
  63. data/app/views/admin/shop/orders/edit/_form.html.haml +13 -0
  64. data/app/views/admin/shop/orders/edit/_head.html.haml +4 -0
  65. data/app/views/admin/shop/orders/edit/_inputs.html.haml +2 -0
  66. data/app/views/admin/shop/orders/edit/_meta.html.haml +8 -0
  67. data/app/views/admin/shop/orders/edit/_parts.html.haml +9 -0
  68. data/app/views/admin/shop/orders/edit/_popups.html.haml +4 -0
  69. data/app/views/admin/shop/orders/edit/parts/_address.html.haml +7 -0
  70. data/app/views/admin/shop/orders/edit/parts/_addresses.html.haml +9 -0
  71. data/app/views/admin/shop/orders/edit/parts/_customer.html.haml +3 -0
  72. data/app/views/admin/shop/orders/edit/parts/_items.html.haml +8 -0
  73. data/app/views/admin/shop/orders/index.html.haml +10 -30
  74. data/app/views/admin/shop/orders/index/_foot.html.haml +3 -0
  75. data/app/views/admin/shop/orders/index/_head.html.haml +4 -0
  76. data/app/views/admin/shop/orders/index/_order.html.haml +13 -0
  77. data/app/views/admin/shop/orders/index/buttons/_all.html.haml +1 -0
  78. data/app/views/admin/shop/orders/index/buttons/_new.html.haml +1 -0
  79. data/app/views/admin/shop/orders/index/buttons/_paid.html.haml +1 -0
  80. data/app/views/admin/shop/orders/index/buttons/_shipped.html.haml +1 -0
  81. data/app/views/admin/shop/packages/edit.html.haml +11 -0
  82. data/app/views/admin/shop/packages/edit/_foot.html.haml +17 -0
  83. data/app/views/admin/shop/packages/edit/_form.html.haml +15 -0
  84. data/app/views/admin/shop/packages/edit/_head.html.haml +4 -0
  85. data/app/views/admin/shop/packages/edit/_inputs.html.haml +2 -0
  86. data/app/views/admin/shop/packages/edit/_meta.html.haml +8 -0
  87. data/app/views/admin/shop/packages/edit/_parts.html.haml +9 -0
  88. data/app/views/admin/shop/packages/edit/_popups.html.haml +4 -0
  89. data/app/views/admin/shop/packages/edit/buttons/_browse_products.html.haml +1 -0
  90. data/app/views/admin/shop/packages/edit/inputs/_name.html.haml +3 -0
  91. data/app/views/admin/shop/packages/edit/inputs/_price.html.haml +3 -0
  92. data/app/views/admin/shop/packages/edit/meta/_sku.html.haml +5 -0
  93. data/app/views/admin/shop/packages/edit/parts/_description.html.haml +1 -0
  94. data/app/views/admin/shop/packages/edit/parts/_products.html.haml +3 -0
  95. data/app/views/admin/shop/packages/edit/popups/_browse_products.html.haml +7 -0
  96. data/app/views/admin/shop/packages/edit/shared/_product.html.haml +8 -0
  97. data/app/views/admin/shop/packages/index.html.haml +13 -0
  98. data/app/views/admin/shop/packages/index/_foot.html.haml +7 -0
  99. data/app/views/admin/shop/packages/index/_head.html.haml +4 -0
  100. data/app/views/admin/shop/packages/index/_package.html.haml +9 -0
  101. data/app/views/admin/shop/packages/new.html.haml +11 -0
  102. data/app/views/admin/shop/packages/remove.html.haml +12 -0
  103. data/app/views/admin/shop/products/edit.html.haml +9 -12
  104. data/app/views/admin/shop/products/edit/_foot.html.haml +19 -0
  105. data/app/views/admin/shop/products/edit/_form.html.haml +15 -0
  106. data/app/views/admin/shop/products/edit/_head.html.haml +4 -2
  107. data/app/views/admin/shop/products/edit/_inputs.html.haml +2 -0
  108. data/app/views/admin/shop/products/edit/_meta.html.haml +8 -8
  109. data/app/views/admin/shop/products/edit/_parts.html.haml +9 -0
  110. data/app/views/admin/shop/products/edit/_popups.html.haml +4 -0
  111. data/app/views/admin/shop/products/edit/buttons/_browse_images.html.haml +1 -1
  112. data/app/views/admin/shop/products/edit/buttons/_browse_templates.html.haml +1 -0
  113. data/app/views/admin/shop/products/edit/buttons/_new_image.html.haml +1 -1
  114. data/app/views/admin/shop/products/edit/buttons/_new_variant.html.haml +1 -0
  115. data/app/views/admin/shop/products/edit/inputs/_name.html.haml +4 -0
  116. data/app/views/admin/shop/products/edit/inputs/_price.html.haml +3 -0
  117. data/app/views/admin/shop/products/edit/meta/_category.html.haml +6 -5
  118. data/app/views/admin/shop/products/edit/meta/_page.html.haml +2 -0
  119. data/app/views/admin/shop/products/edit/meta/_sku.html.haml +6 -5
  120. data/app/views/admin/shop/products/edit/parts/_customers.html.haml +5 -0
  121. data/app/views/admin/shop/products/edit/parts/_description.html.haml +4 -1
  122. data/app/views/admin/shop/products/edit/parts/_images.html.haml +1 -1
  123. data/app/views/admin/shop/products/edit/parts/_variants.html.haml +3 -0
  124. data/app/views/admin/shop/products/edit/popups/_browse_images.html.haml +1 -1
  125. data/app/views/admin/shop/products/edit/popups/_browse_templates.html.haml +6 -0
  126. data/app/views/admin/shop/products/edit/popups/_new_image.html.haml +4 -4
  127. data/app/views/admin/shop/products/edit/popups/_new_variant.html.haml +16 -0
  128. data/app/views/admin/shop/products/edit/{_image.html.haml → shared/_image.html.haml} +0 -0
  129. data/app/views/admin/shop/products/edit/shared/_template.html.haml +6 -0
  130. data/app/views/admin/shop/products/edit/shared/_variant.html.haml +10 -0
  131. data/app/views/admin/shop/products/index.html.haml +6 -3
  132. data/app/views/admin/shop/products/index/_foot.html.haml +10 -0
  133. data/app/views/admin/shop/products/index/_head.html.haml +4 -0
  134. data/app/views/admin/shop/products/index/_product.html.haml +18 -10
  135. data/app/views/admin/shop/products/index/buttons/_discounts.html.haml +1 -0
  136. data/app/views/admin/shop/products/index/buttons/_packages.html.haml +1 -0
  137. data/app/views/admin/shop/products/index/buttons/_variants.html.haml +1 -0
  138. data/app/views/admin/shop/products/new.html.haml +10 -9
  139. data/app/views/admin/shop/variants/edit.html.haml +11 -0
  140. data/app/views/admin/shop/variants/edit/_foot.html.haml +9 -0
  141. data/app/views/admin/shop/variants/edit/_form.html.haml +13 -0
  142. data/app/views/admin/shop/variants/edit/_head.html.haml +4 -0
  143. data/app/views/admin/shop/variants/edit/_inputs.html.haml +2 -0
  144. data/app/views/admin/shop/variants/edit/_meta.html.haml +8 -0
  145. data/app/views/admin/shop/variants/edit/_parts.html.haml +9 -0
  146. data/app/views/admin/shop/variants/edit/_popups.html.haml +4 -0
  147. data/app/views/admin/shop/variants/edit/inputs/_name.html.haml +3 -0
  148. data/app/views/admin/shop/variants/edit/inputs/_options.html.haml +3 -0
  149. data/app/views/admin/shop/variants/index.html.haml +13 -0
  150. data/app/views/admin/shop/variants/index/_foot.html.haml +4 -0
  151. data/app/views/admin/shop/variants/index/_head.html.haml +4 -0
  152. data/app/views/admin/shop/variants/index/_variant.html.haml +9 -0
  153. data/app/views/admin/shop/variants/new.html.haml +11 -0
  154. data/app/views/admin/shop/variants/remove.html.haml +12 -0
  155. data/config/locales/en.yml +8 -1
  156. data/config/routes.rb +11 -22
  157. data/db/migrate/20100929011106_fix_relationship_foreign_keys.rb +101 -0
  158. data/db/migrate/20100929011607_drop_shop_addressables.rb +25 -0
  159. data/db/migrate/20100929030510_create_shop_groups.rb +19 -0
  160. data/db/migrate/20100929080301_shop_groups_change_add_description.rb +11 -0
  161. data/db/migrate/20100929081200_create_variants.rb +20 -0
  162. data/db/migrate/20100929143531_change_variants_add_updated_by.rb +25 -0
  163. data/db/migrate/20100929145641_change_created_by_to_id.rb +75 -0
  164. data/db/migrate/20100929235221_change_category_add_variant_id.rb +9 -0
  165. data/db/migrate/20100930235221_create_packages.rb +31 -0
  166. data/db/migrate/20101005231713_create_page_ids.rb +11 -0
  167. data/db/migrate/20101006051214_create_pages_for_products_and_categories.rb +73 -0
  168. data/db/migrate/20101007111845_add_default_position_to_attachment.rb +9 -0
  169. data/lib/shop/controllers/application_controller.rb +1 -1
  170. data/lib/shop/interface/categories.rb +29 -0
  171. data/lib/shop/interface/customers.rb +15 -15
  172. data/lib/shop/interface/orders.rb +34 -0
  173. data/lib/shop/interface/packages.rb +34 -0
  174. data/lib/shop/interface/products.rb +18 -31
  175. data/lib/shop/interface/variants.rb +34 -0
  176. data/lib/shop/models/form_extension.rb +23 -0
  177. data/lib/shop/models/page.rb +3 -2
  178. data/lib/shop/tags/address.rb +3 -3
  179. data/lib/shop/tags/cart.rb +12 -16
  180. data/lib/shop/tags/category.rb +4 -6
  181. data/lib/shop/tags/helpers.rb +131 -30
  182. data/lib/shop/tags/item.rb +16 -33
  183. data/lib/shop/tags/package.rb +95 -0
  184. data/lib/shop/tags/product.rb +11 -16
  185. data/lib/shop/tags/product_variant.rb +52 -0
  186. data/mockups/discounts/new-edit.bmml +492 -0
  187. data/public/javascripts/admin/extensions/shop/edit.js +20 -0
  188. data/public/javascripts/admin/extensions/shop/packages/edit.js +109 -0
  189. data/public/javascripts/admin/extensions/shop/products/edit.js +64 -65
  190. data/public/javascripts/admin/extensions/shop/products/index.js +31 -36
  191. data/public/stylesheets/sass/admin/extensions/shop/edit.sass +58 -11
  192. data/public/stylesheets/sass/admin/extensions/shop/index.sass +104 -53
  193. data/public/stylesheets/sass/admin/extensions/shop/packages/edit.sass +162 -0
  194. data/public/stylesheets/sass/admin/extensions/shop/products/edit.sass +115 -36
  195. data/public/stylesheets/sass/admin/extensions/shop/products/index.sass +12 -20
  196. data/radiant-shop-extension.gemspec +182 -38
  197. data/shop_extension.rb +29 -25
  198. data/spec/controllers/admin/shop/categories_controller_spec.rb +76 -191
  199. data/spec/controllers/admin/shop/customers_controller_spec.rb +67 -0
  200. data/spec/controllers/admin/shop/orders_controller_spec.rb +85 -0
  201. data/spec/controllers/admin/shop/packages/packings_controller_spec.rb +188 -0
  202. data/spec/controllers/admin/shop/packages_controller_spec.rb +32 -0
  203. data/spec/controllers/admin/shop/products/images_controller_spec.rb +10 -15
  204. data/spec/controllers/admin/shop/products/variant_templates_controller_spec.rb +53 -0
  205. data/spec/controllers/admin/shop/products/variants_controller_spec.rb +116 -0
  206. data/spec/controllers/admin/shop/products_controller_spec.rb +80 -148
  207. data/spec/controllers/admin/shop/variants_controller_spec.rb +67 -0
  208. data/spec/datasets/forms.rb +23 -8
  209. data/spec/datasets/shop_addresses.rb +1 -4
  210. data/spec/datasets/shop_categories.rb +25 -4
  211. data/spec/datasets/shop_groups.rb +15 -0
  212. data/spec/datasets/shop_line_items.rb +4 -3
  213. data/spec/datasets/shop_orders.rb +6 -15
  214. data/spec/datasets/shop_packages.rb +25 -0
  215. data/spec/datasets/shop_payments.rb +12 -0
  216. data/spec/datasets/{images.rb → shop_product_attachments.rb} +9 -1
  217. data/spec/datasets/shop_product_variants.rb +22 -0
  218. data/spec/datasets/shop_products.rb +28 -18
  219. data/spec/datasets/shop_variants.rb +17 -0
  220. data/spec/lib/shop/models/image_spec.rb +4 -4
  221. data/spec/lib/shop/tags/address_spec.rb +3 -3
  222. data/spec/lib/shop/tags/cart_spec.rb +32 -43
  223. data/spec/lib/shop/tags/category_spec.rb +58 -93
  224. data/spec/lib/shop/tags/helpers_spec.rb +162 -69
  225. data/spec/lib/shop/tags/item_spec.rb +116 -158
  226. data/spec/lib/shop/tags/package_spec.rb +342 -0
  227. data/spec/lib/shop/tags/product_spec.rb +29 -26
  228. data/spec/lib/shop/tags/product_variant_spec.rb +175 -0
  229. data/spec/models/form_address_spec.rb +166 -0
  230. data/spec/models/form_checkout_spec.rb +27 -157
  231. data/spec/models/shop_address_spec.rb +81 -0
  232. data/spec/models/shop_category_spec.rb +114 -31
  233. data/spec/models/shop_customer_spec.rb +105 -0
  234. data/spec/models/shop_group_spec.rb +38 -0
  235. data/spec/models/shop_line_item_spec.rb +5 -5
  236. data/spec/models/shop_order_spec.rb +89 -83
  237. data/spec/models/shop_package_spec.rb +117 -0
  238. data/spec/models/shop_packing_spec.rb +67 -0
  239. data/spec/models/shop_payment_spec.rb +19 -0
  240. data/spec/models/shop_product_attachment_spec.rb +4 -3
  241. data/spec/models/shop_product_spec.rb +171 -92
  242. data/spec/models/shop_product_variant_spec.rb +92 -0
  243. data/spec/models/shop_variant_spec.rb +47 -0
  244. metadata +183 -39
  245. data/app/controllers/shop/categories_controller.rb +0 -45
  246. data/app/controllers/shop/line_items_controller.rb +0 -165
  247. data/app/controllers/shop/orders_controller.rb +0 -16
  248. data/app/controllers/shop/products_controller.rb +0 -48
  249. data/app/models/shop_addressable.rb +0 -11
  250. data/app/views/admin/shop/categories/edit/_fields.html.haml +0 -28
  251. data/app/views/admin/shop/categories/edit/_part.html.haml +0 -3
  252. data/app/views/admin/shop/categories/edit/_popup.html.haml +0 -3
  253. data/app/views/admin/shop/customers/edit/_fields.html.haml +0 -33
  254. data/app/views/admin/shop/customers/index/_bottom.html.haml +0 -4
  255. data/app/views/admin/shop/products/edit/_fields.html.haml +0 -38
  256. data/app/views/admin/shop/products/edit/_part.html.haml +0 -3
  257. data/app/views/admin/shop/products/edit/_popup.html.haml +0 -3
  258. data/app/views/admin/shop/products/index/_bottom.html.haml +0 -5
  259. data/spec/controllers/shop/categories_controller_spec.rb +0 -42
  260. data/spec/controllers/shop/line_items_controller_spec.rb +0 -256
  261. data/spec/controllers/shop/orders_controller_specs.rb +0 -37
  262. data/spec/controllers/shop/products_controller_spec.rb +0 -51
  263. data/vendor/plugins/json_fields/.gitignore +0 -3
  264. data/vendor/plugins/json_fields/MIT-LICENSE +0 -20
  265. data/vendor/plugins/json_fields/README.rdoc +0 -65
  266. data/vendor/plugins/json_fields/Rakefile +0 -55
  267. data/vendor/plugins/json_fields/init.rb +0 -2
  268. data/vendor/plugins/json_fields/lib/json_fields.rb +0 -99
  269. data/vendor/plugins/json_fields/spec/lib/json_fields_spec.rb +0 -124
  270. data/vendor/plugins/json_fields/spec/spec.opts +0 -6
  271. data/vendor/plugins/json_fields/spec/spec_helper.rb +0 -29
  272. data/vendor/plugins/json_fields/spec/test_models.rb +0 -12
@@ -0,0 +1,22 @@
1
+ class ShopPacking < ActiveRecord::Base
2
+
3
+ default_scope :order => 'shop_packings.position ASC'
4
+
5
+ belongs_to :package, :class_name => 'ShopPackage', :foreign_key => :package_id
6
+ belongs_to :product, :class_name => 'ShopProduct', :foreign_key => :product_id
7
+
8
+ before_validation :set_quantity
9
+
10
+ validates_uniqueness_of :product_id, :scope => :package_id
11
+
12
+ def value
13
+ self.product.price.to_f * self.quantity
14
+ end
15
+
16
+ private
17
+
18
+ def set_quantity
19
+ self.quantity = [1,self.quantity].max
20
+ end
21
+
22
+ end
@@ -0,0 +1,7 @@
1
+ class ShopPage < Page
2
+
3
+ def cache?
4
+ return false
5
+ end
6
+
7
+ end
@@ -1,5 +1,9 @@
1
1
  class ShopPayment < ActiveRecord::Base
2
2
 
3
- belongs_to :order, :class_name => 'ShopOrder', :foreign_key => :shop_order_id
3
+ belongs_to :order, :class_name => 'ShopOrder'
4
+
5
+ validates_presence_of :amount
6
+ validates_presence_of :card_type
7
+ validates_presence_of :card_number
4
8
 
5
9
  end
@@ -1,86 +1,124 @@
1
1
  class ShopProduct < ActiveRecord::Base
2
2
 
3
+ default_scope :joins => :page, :order => 'pages.position ASC'
4
+
5
+ belongs_to :page, :dependent => :destroy
3
6
  belongs_to :created_by, :class_name => 'User'
4
7
  belongs_to :updated_by, :class_name => 'User'
5
- belongs_to :category, :class_name => 'ShopCategory', :foreign_key => :shop_category_id
6
8
 
7
- has_many :line_items, :class_name => 'ShopLineItem', :as => :item, :dependent => :destroy
8
- has_many :orders, :class_name => 'ShopOrder', :through => :line_items
9
- has_many :attachments, :class_name => 'ShopProductAttachment'
10
- has_many :images, :through => :attachments, :uniq => true
9
+ has_many :line_items, :class_name => 'ShopLineItem', :foreign_key => :item_id, :dependent => :destroy
10
+ has_many :orders, :class_name => 'ShopOrder', :through => :line_items, :uniq => true
11
+ has_many :attachments, :class_name => 'ShopProductAttachment', :foreign_key => :product_id
12
+ has_many :images, :class_name => 'Image', :through => :attachments, :uniq => true
13
+ has_many :packings, :class_name => 'ShopPacking', :foreign_key => :product_id
14
+ has_many :packages, :class_name => 'ShopPackage', :foreign_key => :package_id, :through => :packings, :source => :package
15
+ has_many :related, :class_name => 'ShopProduct', :through => :packings, :source => :product, :uniq => true
16
+ has_many :variants, :class_name => 'ShopProductVariant', :foreign_key => :product_id, :dependent => :destroy
11
17
 
12
- default_scope :joins => :category, :order => 'shop_categories.position, shop_products.position ASC'
18
+ before_validation :assign_slug, :assign_breadcrumb
19
+ validates_presence_of :page
13
20
 
14
- before_validation :set_sku, :filter_sku
21
+ validates_numericality_of :price, :greater_than => 0.00, :allow_nil => true, :precisions => 2
15
22
 
16
- validates_presence_of :name, :sku, :category
23
+ accepts_nested_attributes_for :page
24
+ accepts_nested_attributes_for :variants
17
25
 
18
- validates_uniqueness_of :name, :scope => 'shop_category_id'
26
+ # Returns the title of the product's page
27
+ def name; page.title; end
19
28
 
20
- validates_uniqueness_of :sku
29
+ # Returns the url of the page formatted as an sku
30
+ def sku; self.class.to_sku(url) end
21
31
 
22
- validates_numericality_of :price, :greater_than => 0.00, :allow_nil => true, :precisions => 2
32
+ # Returns category through the pages parent
33
+ def category; page.parent.shop_category; end
23
34
 
24
- acts_as_list :scope => :shop_category
35
+ # Returns id of category
36
+ def category_id; category.id; end
25
37
 
26
- def slug
27
- "/#{self.slug_prefix}/#{self.category.handle}/#{self.sku}"
28
- end
38
+ # Returns the content of the product's page's description part
39
+ def description; page.parts.find_by_name('description').content rescue nil; end
29
40
 
30
- def layout
31
- self.category.product_layout
32
- end
41
+ # Returns the url of the page
42
+ def url; page.url; end
33
43
 
34
- def available_images
35
- Image.all - self.images
36
- end
44
+ # Returns the customers of this product
45
+ def customers; line_items.map(&:customer).flatten.compact.uniq; end
46
+
47
+ # Returns an array of customer ids
48
+ def customer_ids; customers.map(&:id); end
49
+
50
+ # Returns an array of image ids
51
+ def image_ids; images.map(&:id); end
52
+
53
+ # Returns images not attached to product
54
+ def available_images; Image.all - images; end
55
+
56
+ # Returns the page slug
57
+ def slug; page.slug; end
58
+
59
+ # Overloads the base to_json to return what we want
60
+ def to_json(*attrs); super self.class.params; end
37
61
 
38
- def slug_prefix
39
- Radiant::Config['shop.url_prefix']
62
+ # Applies an array of variant names as product_variants
63
+ def apply_variant_template(variant)
64
+ result = true
65
+ variant.options.each do |variant|
66
+ variants.new(:name => variant).save! rescue (result = false)
67
+ end
68
+ result
40
69
  end
41
70
 
42
71
  class << self
43
72
 
44
- def search(search)
45
- unless search.blank?
46
- queries = []
47
- queries << 'LOWER(shop_products.name) LIKE (:term)'
48
- queries << 'LOWER(shop_products.sku) LIKE (:term)'
49
- queries << 'LOWER(shop_products.description) LIKE (:term)'
50
-
51
- sql = queries.join(" OR ")
52
- conditions = [sql, {:term => "%#{search.downcase}%" }]
53
- else
54
- conditions = []
55
- end
73
+ # Sorts products within a category
74
+ def sort(category_id, *product_ids)
75
+ parent_id = ShopCategory.find(category_id).page_id
56
76
 
57
- self.all({ :conditions => conditions })
77
+ product_ids.each_with_index do |id, index|
78
+ ShopProduct.find(id).page.update_attributes!(
79
+ :position => index+1,
80
+ :parent_id => parent_id
81
+ )
82
+ end
58
83
  end
59
84
 
85
+ # Returns attributes attached to the product
60
86
  def attrs
61
- [ :id, :name, :price, :sku, :description, :created_at, :updated_at ]
87
+ [ :id, :price, :page_id, :created_at, :updated_at ]
88
+ end
89
+
90
+ # Returns methods with usefuly information
91
+ def methds
92
+ [ :category_id, :name, :description, :handle, :url, :customer_ids, :image_ids, :created_at, :updated_at ]
62
93
  end
63
94
 
95
+ # Returns a custom hash of attributes on the product
64
96
  def params
65
- {
66
- :include => { :category => { :only => ShopCategory.attrs } },
67
- :only => ShopProduct.attrs
68
- }
97
+ { :only => self.attrs, :methods => self.methds }
98
+ end
99
+
100
+ # Converts a url to a pretty sku and removes the shop prefix /shop/page/category/product page-category-product
101
+ def to_sku(url)
102
+ if url.present?
103
+ url.downcase.strip.gsub(/^\/#{Radiant::Config['shop.root_page_slug']}/,'').gsub(/^(\/*)(.*)(\/)$/,'\2').gsub(/[\s\.:;=+~]+/,'_').gsub(/\//,'-')
104
+ end
69
105
  end
70
106
 
71
107
  end
72
108
 
73
- private
109
+ protected
74
110
 
75
- def set_sku
76
- unless self.name.nil?
77
- self.sku = self.name if self.sku.nil? or self.sku.empty?
111
+ # Assigns a slug to a page if its not set
112
+ def assign_slug
113
+ if page.present?
114
+ self.page.slug = ShopProduct.to_sku(page.slug.present? ? page.slug : page.title)
78
115
  end
79
116
  end
80
117
 
81
- def filter_sku
82
- unless self.name.nil?
83
- self.sku = self.sku.downcase.gsub(/[^-a-z0-9~\s\.:;+=_]/, '').strip.gsub(/[\s\.:;=+~]+/, '_')
118
+ # Assigns a breadcrumb to the page if its not set
119
+ def assign_breadcrumb
120
+ if page.present?
121
+ self.page.breadcrumb = ShopProduct.to_sku(page.breadcrumb.present? ? page.breadcrumb : page.slug)
84
122
  end
85
123
  end
86
124
 
@@ -2,10 +2,13 @@ class ShopProductAttachment < ActiveRecord::Base
2
2
 
3
3
  default_scope :order => 'shop_product_attachments.position ASC'
4
4
 
5
- belongs_to :product, :class_name => 'ShopProduct', :foreign_key => :shop_product_id
5
+ belongs_to :product, :class_name => 'ShopProduct'
6
6
  belongs_to :image
7
7
 
8
- acts_as_list :scope => :shop_product
8
+ belongs_to :created_by, :class_name => 'User'
9
+ belongs_to :updated_by, :class_name => 'User'
10
+
11
+ acts_as_list :scope => :product
9
12
 
10
13
  def url(*params)
11
14
  image.url(*params) rescue nil
@@ -0,0 +1,31 @@
1
+ class ShopProductVariant < ActiveRecord::Base
2
+
3
+ belongs_to :product, :class_name => 'ShopProduct', :foreign_key => :product_id
4
+
5
+ validates_presence_of :product
6
+ validates_presence_of :name
7
+ validates_uniqueness_of :name, :scope => :product_id
8
+
9
+ belongs_to :created_by, :class_name => 'User'
10
+ belongs_to :updated_by, :class_name => 'User'
11
+
12
+ # Returns the price of the variant plus the product price
13
+ def price
14
+ price = product.price
15
+ if read_attribute(:price).present?
16
+ price = read_attribute(:price) + product.price
17
+ end
18
+ price
19
+ end
20
+
21
+ # Returns a mixed sku of product and variant name
22
+ def sku
23
+ %{#{product.sku}-#{ShopProduct.to_sku(name)}}
24
+ end
25
+
26
+ # Returns slug of the product
27
+ def slug
28
+ product.slug
29
+ end
30
+
31
+ end
@@ -0,0 +1,25 @@
1
+ class ShopVariant < ActiveRecord::Base
2
+
3
+ belongs_to :created_by, :class_name => 'User'
4
+ belongs_to :updated_by, :class_name => 'User'
5
+
6
+ has_many :categories, :class_name => 'ShopCategory', :foreign_key => 'variant_id'
7
+
8
+ validates_presence_of :name
9
+ validates_uniqueness_of :name
10
+ validates_presence_of :options_json
11
+
12
+ def options
13
+ options = {}
14
+ if self.options_json.present?
15
+ options = ActiveSupport::JSON.decode(self.options_json)
16
+ options = Forms::Config.deep_symbolize_keys(options)
17
+ end
18
+ options
19
+ end
20
+
21
+ def options=(options)
22
+ self.options_json = ActiveSupport::JSON.encode(options)
23
+ end
24
+
25
+ end
@@ -1,12 +1,11 @@
1
- - @page_title = @shop_category.name + ' - ' + default_page_title
1
+ - @page_title = @shop_category.name
2
2
 
3
3
  - render_region :main do |main|
4
- - main.edit_header do
5
- %h1
6
- = @shop_category.name
7
- = render :partial => 'admin/shop/categories/edit/head'
8
- - main.edit_form do
9
- - form_for :shop_category, @shop_category, :url => admin_shop_category_path(@shop_category), :html => {:method => :put, :multipart => true, :id => 'edit_shop_category', 'data-onsubmit_status'=>"Saving Changes&#8230;"} do |f|
10
- = render :partial => 'admin/shop/categories/edit/fields', :object => f
11
- - main.edit_popups do
12
- = render :partial => 'admin/shop/categories/edit/popup'
4
+ - main.head do
5
+ = render 'admin/shop/categories/edit/head'
6
+
7
+ - main.popups do
8
+ = render 'admin/shop/categories/edit/popups'
9
+
10
+ - main.form do
11
+ = render 'admin/shop/categories/edit/form'
@@ -0,0 +1,9 @@
1
+ - render_region :foot do |foot|
2
+ - foot.buttons do
3
+ %p.buttons
4
+ = save_model_button(@shop_category)
5
+ = save_model_and_continue_editing_button(@shop_category)
6
+ = t('or')
7
+ = link_to t('cancel'), admin_shop_categories_path
8
+ - foot.timestamp do
9
+ = updated_stamp @shop_category
@@ -0,0 +1,14 @@
1
+ - form_for [:admin, @shop_category], :html => {'data-onsubmit_status'=>"Saving Changes&#8230;"} do |f|
2
+
3
+ - render_region :form do |form|
4
+ - form.inputs do
5
+ = render :partial => '/admin/shop/categories/edit/inputs', :locals => { :f => f }
6
+
7
+ - form.meta do
8
+ = render :partial => '/admin/shop/categories/edit/meta', :locals => { :f => f }
9
+
10
+ - form.parts do
11
+ = render :partial => '/admin/shop/categories/edit/parts', :locals => { :f => f }
12
+
13
+ - form.foot do
14
+ = render :partial => 'admin/shop/categories/edit/foot', :locals => { :f => f }
@@ -1,2 +1,4 @@
1
- - @buttons.each do |button|
2
- = render :partial => 'admin/shop/categories/edit/buttons/' + button
1
+ %h1
2
+ = @page_title
3
+ - @buttons.each do |button|
4
+ = render :partial => "admin/shop/categories/edit/buttons/#{button}"
@@ -0,0 +1,2 @@
1
+ - @inputs.each do |input|
2
+ = render :partial => "admin/shop/categories/edit/inputs/#{input}", :locals => { :f => f }
@@ -1,7 +1,8 @@
1
- .drawer
2
- .drawer_contents#attributes
3
- %table.fieldset
4
- - @meta.each do |meta|
5
- = render :partial => 'admin/shop/categories/edit/meta/' + meta, :locals => { :f => fields }
6
- .drawer_handle
7
- %a.toggle{:href=>'#attributes', :rel=>"toggle[attributes]", :class=>"#{(meta_errors? ? 'less' : 'more')}"}= meta_label
1
+ - if @meta.present?
2
+ .drawer
3
+ .drawer_contents#attributes
4
+ %table.fieldset
5
+ - @meta.each do |meta|
6
+ = render :partial => "admin/shop/categories/edit/meta/#{meta}", :locals => { :f => f }
7
+ .drawer_handle
8
+ %a.toggle{:href=>'#attributes', :rel=>"toggle[attributes]", :class=>"#{(meta_errors? ? 'less' : 'more')}"}= meta_label
@@ -0,0 +1,9 @@
1
+ #tab_control
2
+ #tabs.tabs
3
+ #tab_toolbar
4
+ #pages.pages
5
+ = hidden_field_tag 'page_part_index_field' #important
6
+ - @parts.each do |part|
7
+ .page{:id => "category_page_#{part}", 'data-caption'=>h(part)}
8
+ .part{:id => "category_part_#{part}"}
9
+ = render :partial => "admin/shop/categories/edit/parts/#{part}", :locals => { :f => f }
@@ -0,0 +1,4 @@
1
+ #popups
2
+ - @popups.each do |popup|
3
+ .popup{ :id => "#{popup}_popup"}
4
+ = render :partial => "admin/shop/categories/edit/popups/#{popup}"
@@ -0,0 +1,4 @@
1
+ - f.fields_for :page do |pf|
2
+ %p.title
3
+ = pf.label :title, t('name')
4
+ = pf.text_field :title, :class => 'textbox', :maxlenth => 255
@@ -1,5 +1,6 @@
1
- %tr
2
- %th.label
3
- %label{:for=>"shop_category[handle]"}= t('handle')
4
- %td.field
5
- = f.text_field :handle, :class =>'textbox'
1
+ - f.fields_for :page do |pf|
2
+ %tr
3
+ %th.label
4
+ = pf.label :slug, t('handle')
5
+ %td.field
6
+ = pf.text_field :slug, :class =>'textbox'
@@ -1,8 +1,9 @@
1
- %tr
2
- %th.label
3
- %label{:for=>"shop_category[layout]"}= t('custom_layout')
4
- %td.field
5
- = f.collection_select :layout_id, Layout.all, :id, :name
1
+ - f.fields_for :page do |pf|
2
+ %tr
3
+ %th.label
4
+ %label{:for=>"shop_category[layout]"}= t('custom_layout')
5
+ %td.field
6
+ = pf.collection_select :layout_id, Layout.all, :id, :name
6
7
  %tr
7
8
  %th.label
8
9
  %label{:for=>"shop_category[product_layout]"}= t('custom_product_layout')
@@ -0,0 +1,3 @@
1
+ - f.fields_for :page do |pf|
2
+ = pf.hidden_field :parent_id
3
+ = pf.hidden_field :class_name, :value => 'ShopCategoryPage'
@@ -1 +1,4 @@
1
- ~ text_area_tag 'shop_category[description]', @shop_category.description, :class => "textarea large", :style => "width: 100%", :id => "shop_category_#{part.to_slug}_content"
1
+ - f.fields_for :page do |pf|
2
+ - pf.fields_for :parts do |pfp|
3
+ = pfp.hidden_field :name, :value => 'Description'
4
+ ~ pfp.text_area :content, :class => "textarea large", :style => "width: 100%"
@@ -1,16 +1,17 @@
1
- %li.category{:id => "shop_category_#{category.id}", :'data-id' => category.id }
1
+ %li.category{:id => "category_#{category.id}", :'data-id' => category.id }
2
2
  .attributes
3
- %span.handle
4
- - render_region :category_attributes do |region|
5
- - region.category_name do
3
+ - render_region :category do |body|
4
+ - body.move do
5
+ %span.move.attribute
6
+ - body.name do
6
7
  %span.name.attribute= link_to category.name, edit_admin_shop_category_path(category)
7
- - region.category_description do
8
- %span.sku.attribute= category.handle
9
- - region.category_modify do
8
+ - body.handle do
9
+ %span.handle.attribute= category.handle
10
+ - body.modify do
10
11
  .modify
11
12
  %span.add_child= link_to t('add_product'), new_admin_shop_category_product_path(category)
12
13
  %span.remove= link_to t('remove'), remove_admin_shop_category_path(category)
13
- - render_region :category_products do |region|
14
- - region.category_products do
15
- %ul.products{ :id => "shop_category_#{category.id}_products", :'data-id' => category.id }
14
+ - render_region :products do |products|
15
+ - products.body do
16
+ %ul.products{ :id => "category_#{category.id}_products", :'data-id' => category.id }
16
17
  = render :partial => '/admin/shop/products/index/product', :collection => category.products