radiant-shop-extension 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. data/.gitignore +6 -0
  2. data/Gemfile +26 -0
  3. data/Gemfile.lock +75 -0
  4. data/HISTORY.md +77 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.md +26 -0
  7. data/Rakefile +141 -0
  8. data/VERSION +1 -0
  9. data/app/.DS_Store +0 -0
  10. data/app/controllers/admin/shop/categories_controller.rb +206 -0
  11. data/app/controllers/admin/shop/customers_controller.rb +137 -0
  12. data/app/controllers/admin/shop/orders_controller.rb +171 -0
  13. data/app/controllers/admin/shop/products/images_controller.rb +144 -0
  14. data/app/controllers/admin/shop/products_controller.rb +217 -0
  15. data/app/controllers/admin/shops_controller.rb +9 -0
  16. data/app/controllers/shop/categories_controller.rb +49 -0
  17. data/app/controllers/shop/line_items_controller.rb +165 -0
  18. data/app/controllers/shop/orders_controller.rb +16 -0
  19. data/app/controllers/shop/products_controller.rb +48 -0
  20. data/app/models/form_checkout.rb +245 -0
  21. data/app/models/shop_address.rb +13 -0
  22. data/app/models/shop_addressable.rb +11 -0
  23. data/app/models/shop_category.rb +85 -0
  24. data/app/models/shop_category_page.rb +7 -0
  25. data/app/models/shop_customer.rb +27 -0
  26. data/app/models/shop_line_item.rb +32 -0
  27. data/app/models/shop_order.rb +108 -0
  28. data/app/models/shop_payment.rb +6 -0
  29. data/app/models/shop_payment_method.rb +5 -0
  30. data/app/models/shop_product.rb +87 -0
  31. data/app/models/shop_product_attachment.rb +30 -0
  32. data/app/models/shop_product_page.rb +7 -0
  33. data/app/views/.DS_Store +0 -0
  34. data/app/views/admin/.DS_Store +0 -0
  35. data/app/views/admin/pages/_shop_category.html.haml +4 -0
  36. data/app/views/admin/pages/_shop_product.html.haml +4 -0
  37. data/app/views/admin/shop/categories/edit.html.haml +12 -0
  38. data/app/views/admin/shop/categories/edit/_fields.html.haml +28 -0
  39. data/app/views/admin/shop/categories/edit/_head.html.haml +2 -0
  40. data/app/views/admin/shop/categories/edit/_meta.html.haml +7 -0
  41. data/app/views/admin/shop/categories/edit/_part.html.haml +3 -0
  42. data/app/views/admin/shop/categories/edit/_popup.html.haml +3 -0
  43. data/app/views/admin/shop/categories/edit/meta/_handle.html.haml +5 -0
  44. data/app/views/admin/shop/categories/edit/meta/_layouts.html.haml +10 -0
  45. data/app/views/admin/shop/categories/edit/parts/_description.html.haml +1 -0
  46. data/app/views/admin/shop/categories/index/_category.html.haml +16 -0
  47. data/app/views/admin/shop/categories/new.html.haml +10 -0
  48. data/app/views/admin/shop/categories/remove.html.haml +12 -0
  49. data/app/views/admin/shop/customers/index.html.haml +36 -0
  50. data/app/views/admin/shop/orders/index.html.haml +33 -0
  51. data/app/views/admin/shop/products/edit.html.haml +14 -0
  52. data/app/views/admin/shop/products/edit/_fields.html.haml +38 -0
  53. data/app/views/admin/shop/products/edit/_head.html.haml +2 -0
  54. data/app/views/admin/shop/products/edit/_image.html.haml +12 -0
  55. data/app/views/admin/shop/products/edit/_meta.html.haml +8 -0
  56. data/app/views/admin/shop/products/edit/_part.html.haml +3 -0
  57. data/app/views/admin/shop/products/edit/_popup.html.haml +3 -0
  58. data/app/views/admin/shop/products/edit/buttons/_browse_images.html.haml +1 -0
  59. data/app/views/admin/shop/products/edit/buttons/_new_image.html.haml +1 -0
  60. data/app/views/admin/shop/products/edit/meta/_category.html.haml +5 -0
  61. data/app/views/admin/shop/products/edit/meta/_sku.html.haml +5 -0
  62. data/app/views/admin/shop/products/edit/parts/_description.html.haml +1 -0
  63. data/app/views/admin/shop/products/edit/parts/_images.html.haml +5 -0
  64. data/app/views/admin/shop/products/edit/popups/_browse_images.html.haml +6 -0
  65. data/app/views/admin/shop/products/edit/popups/_new_image.html.haml +18 -0
  66. data/app/views/admin/shop/products/index.html.haml +10 -0
  67. data/app/views/admin/shop/products/index/_bottom.html.haml +5 -0
  68. data/app/views/admin/shop/products/index/_product.html.haml +13 -0
  69. data/app/views/admin/shop/products/new.html.haml +10 -0
  70. data/app/views/admin/shop/products/remove.html.haml +12 -0
  71. data/app/views/shop/categories/show.html.haml +1 -0
  72. data/app/views/shop/orders/show.html.haml +1 -0
  73. data/app/views/shop/products/index.html.haml +1 -0
  74. data/app/views/shop/products/show.html.haml +1 -0
  75. data/config/locales/en.yml +50 -0
  76. data/config/routes.rb +38 -0
  77. data/config/shop_cart.yml +16 -0
  78. data/cucumber.yml +1 -0
  79. data/db/migrate/20100311053701_initial.rb +153 -0
  80. data/db/migrate/20100520033059_create_layouts.rb +119 -0
  81. data/db/migrate/20100903122123_create_forms.rb +44 -0
  82. data/db/migrate/20100908063639_create_snippets.rb +22 -0
  83. data/features/support/env.rb +16 -0
  84. data/features/support/paths.rb +14 -0
  85. data/lib/shop/controllers/application_controller.rb +39 -0
  86. data/lib/shop/controllers/site_controller.rb +12 -0
  87. data/lib/shop/interface/products.rb +49 -0
  88. data/lib/shop/models/image.rb +14 -0
  89. data/lib/shop/models/page.rb +14 -0
  90. data/lib/shop/tags/address.rb +40 -0
  91. data/lib/shop/tags/cart.rb +49 -0
  92. data/lib/shop/tags/category.rb +83 -0
  93. data/lib/shop/tags/core.rb +12 -0
  94. data/lib/shop/tags/helpers.rb +142 -0
  95. data/lib/shop/tags/item.rb +109 -0
  96. data/lib/shop/tags/product.rb +109 -0
  97. data/lib/shop/tags/responses.rb +34 -0
  98. data/lib/tasks/shop_extension_tasks.rake +54 -0
  99. data/mockups/balsamiq/products-retro_fun_tshirt-more.bmml +0 -0
  100. data/mockups/balsamiq/products-retro_fun_tshirt.bmml +0 -0
  101. data/public/images/admin/extensions/shop/products/sort.png +0 -0
  102. data/public/javascripts/admin/extensions/shop/products/edit.js +115 -0
  103. data/public/javascripts/admin/extensions/shop/products/index.js +65 -0
  104. data/public/stylesheets/sass/admin/extensions/shop/edit.sass +86 -0
  105. data/public/stylesheets/sass/admin/extensions/shop/products/edit.sass +158 -0
  106. data/public/stylesheets/sass/admin/extensions/shop/products/index.sass +129 -0
  107. data/radiant-shop-extension.gemspec +245 -0
  108. data/shop_extension.rb +62 -0
  109. data/spec/controllers/admin/shop/categories_controller_spec.rb +443 -0
  110. data/spec/controllers/admin/shop/products/images_controller_spec.rb +477 -0
  111. data/spec/controllers/admin/shop/products_controller_spec.rb +394 -0
  112. data/spec/controllers/admin/shops_controller_spec.rb +19 -0
  113. data/spec/controllers/shop/categories_controller_spec.rb +42 -0
  114. data/spec/controllers/shop/line_items_controller_spec.rb +256 -0
  115. data/spec/controllers/shop/orders_controller_specs.rb +37 -0
  116. data/spec/controllers/shop/products_controller_spec.rb +51 -0
  117. data/spec/datasets/forms.rb +153 -0
  118. data/spec/datasets/images.rb +13 -0
  119. data/spec/datasets/shop_addresses.rb +27 -0
  120. data/spec/datasets/shop_categories.rb +13 -0
  121. data/spec/datasets/shop_line_items.rb +9 -0
  122. data/spec/datasets/shop_orders.rb +21 -0
  123. data/spec/datasets/shop_products.rb +34 -0
  124. data/spec/helpers/nested_tag_helper.rb +33 -0
  125. data/spec/lib/shop/models/image_spec.rb +28 -0
  126. data/spec/lib/shop/models/page_spec.rb +38 -0
  127. data/spec/lib/shop/tags/address_spec.rb +196 -0
  128. data/spec/lib/shop/tags/cart_spec.rb +169 -0
  129. data/spec/lib/shop/tags/category_spec.rb +201 -0
  130. data/spec/lib/shop/tags/core_spec.rb +16 -0
  131. data/spec/lib/shop/tags/helpers_spec.rb +381 -0
  132. data/spec/lib/shop/tags/item_spec.rb +313 -0
  133. data/spec/lib/shop/tags/product_spec.rb +334 -0
  134. data/spec/matchers/comparison.rb +72 -0
  135. data/spec/matchers/render_matcher.rb +33 -0
  136. data/spec/models/form_checkout_spec.rb +376 -0
  137. data/spec/models/shop_category_page_spec.rb +10 -0
  138. data/spec/models/shop_category_spec.rb +58 -0
  139. data/spec/models/shop_line_item_spec.rb +42 -0
  140. data/spec/models/shop_order_spec.rb +228 -0
  141. data/spec/models/shop_product_attachment_spec.rb +72 -0
  142. data/spec/models/shop_product_page_spec.rb +10 -0
  143. data/spec/models/shop_product_spec.rb +135 -0
  144. data/spec/spec.opts +6 -0
  145. data/spec/spec_helper.rb +22 -0
  146. data/vendor/plugins/acts_as_list/README +23 -0
  147. data/vendor/plugins/acts_as_list/init.rb +3 -0
  148. data/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb +256 -0
  149. data/vendor/plugins/acts_as_list/test/list_test.rb +332 -0
  150. data/vendor/plugins/json_fields/.gitignore +3 -0
  151. data/vendor/plugins/json_fields/MIT-LICENSE +20 -0
  152. data/vendor/plugins/json_fields/README.rdoc +65 -0
  153. data/vendor/plugins/json_fields/Rakefile +55 -0
  154. data/vendor/plugins/json_fields/init.rb +2 -0
  155. data/vendor/plugins/json_fields/lib/json_fields.rb +99 -0
  156. data/vendor/plugins/json_fields/spec/lib/json_fields_spec.rb +124 -0
  157. data/vendor/plugins/json_fields/spec/spec.opts +6 -0
  158. data/vendor/plugins/json_fields/spec/spec_helper.rb +29 -0
  159. data/vendor/plugins/json_fields/spec/test_models.rb +12 -0
  160. metadata +324 -0
@@ -0,0 +1,217 @@
1
+ class Admin::Shop::ProductsController < Admin::ResourceController
2
+
3
+ model_class ShopProduct
4
+
5
+ before_filter :config_global
6
+ before_filter :config_new, :only => [ :new, :create ]
7
+ before_filter :config_edit, :only => [ :edit, :update ]
8
+ before_filter :assets_global
9
+ before_filter :assets_index, :only => [ :index ]
10
+ before_filter :assets_edit, :only => [ :edit, :update ]
11
+
12
+ before_filter :set_category, :only => [ :new ]
13
+
14
+ # GET /admin/shop/products
15
+ # GET /admin/shop/products.js
16
+ # GET /admin/shop/products.json AJAX and HTML
17
+ #----------------------------------------------------------------------------
18
+ def index
19
+ @shop_categories = ShopCategory.all
20
+ @shop_products = ShopProduct.search(params[:search])
21
+
22
+ respond_to do |format|
23
+ format.html { render :index }
24
+ format.js { render :partial => '/admin/shop/products/index/product', :collection => @shop_products }
25
+ format.json { render :json => @shop_products.to_json(ShopProduct.params) }
26
+ end
27
+ end
28
+
29
+ # PUT /admin/shop/products/sort
30
+ # PUT /admin/shop/products/sort.js
31
+ # PUT /admin/shop/products/sort.json AJAX and HTML
32
+ #----------------------------------------------------------------------------
33
+ def sort
34
+ notice = 'Products successfully sorted.'
35
+ error = 'Could not sort Products.'
36
+
37
+ begin
38
+ @shop_category = ShopCategory.find(params[:category_id])
39
+ @shop_products = CGI::parse(params[:products])["shop_category_#{params[:category_id]}_products[]"]
40
+
41
+ @shop_products.each_with_index do |id, index|
42
+ ShopProduct.find(id).update_attributes!({
43
+ :position => index+1,
44
+ :shop_category_id => @shop_category.id
45
+ })
46
+ end
47
+
48
+ respond_to do |format|
49
+ format.html {
50
+ flash[:notice] = notice
51
+ redirect_to admin_shop_products_path
52
+ }
53
+ format.js { render :text => notice, :status => :ok }
54
+ format.json { render :json => { :notice => notice }, :status => :ok }
55
+ end
56
+ rescue
57
+ respond_to do |format|
58
+ format.html {
59
+ flash[:error] = error
60
+ redirect_to admin_shop_products_path
61
+ }
62
+ format.js { render :text => error, :status => :unprocessable_entity }
63
+ format.json { render :json => { :error => error }, :status => :unprocessable_entity }
64
+ end
65
+ end
66
+ end
67
+
68
+ # POST /admin/shop/products
69
+ # POST /admin/shop/products.js
70
+ # POST /admin/shop/products.json AJAX and HTML
71
+ #----------------------------------------------------------------------------
72
+ def create
73
+ notice = 'Product created successfully.'
74
+ error = 'Could not create Product.'
75
+
76
+ @shop_product.attributes = params[:shop_product]
77
+
78
+ begin
79
+ @shop_product.save!
80
+
81
+ respond_to do |format|
82
+ format.html {
83
+ flash[:notice] = notice
84
+ redirect_to edit_admin_shop_product_path(@shop_product) if params[:continue]
85
+ redirect_to admin_shop_products_path unless params[:continue]
86
+ }
87
+ format.js { render :partial => '/admin/shop/products/index/product', :locals => { :excerpt => @shop_product } }
88
+ format.json { render :json => @shop_product.to_json(ShopProduct.params) }
89
+ end
90
+ rescue
91
+ respond_to do |format|
92
+ format.html {
93
+ flash[:error] = error
94
+ render :new
95
+ }
96
+ format.js { render :text => error, :status => :unprocessable_entity }
97
+ format.json { render :json => { :error => error }, :status => :unprocessable_entity }
98
+ end
99
+ end
100
+ end
101
+
102
+ # PUT /admin/shop/products/1
103
+ # PUT /admin/shop/products/1.js
104
+ # PUT /admin/shop/products/1.xml
105
+ # PUT /admin/shop/products/1.json AJAX and HTML
106
+ #----------------------------------------------------------------------------
107
+ def update
108
+ notice = 'Product updated successfully.'
109
+ error = 'Could not update Product.'
110
+
111
+ begin
112
+ @shop_product.update_attributes!(params[:shop_product])
113
+
114
+ respond_to do |format|
115
+ format.html {
116
+ flash[:notice] = notice
117
+ redirect_to edit_admin_shop_product_path(@shop_product) if params[:continue]
118
+ redirect_to admin_shop_products_path unless params[:continue]
119
+ }
120
+ format.js { render :partial => '/admin/shop/products/index/product', :locals => { :product => @shop_product } }
121
+ format.json { render :json => @shop_product.to_json(ShopProduct.params) }
122
+ end
123
+ rescue
124
+ respond_to do |format|
125
+ format.html {
126
+ flash[:error] = error
127
+ render :edit
128
+ }
129
+ format.js { render :text => error, :status => :unprocessable_entity }
130
+ format.json { render :json => { :error => error }, :status => :unprocessable_entity }
131
+ end
132
+ end
133
+ end
134
+
135
+ # DELETE /admin/shop/products/1
136
+ # DELETE /admin/shop/products/1.js
137
+ # DELETE /admin/shop/products/1.xml
138
+ # DELETE /admin/shop/products/1.json AJAX and HTML
139
+ #----------------------------------------------------------------------------
140
+ def destroy
141
+ notice = 'Product deleted successfully.'
142
+ error = 'Could not delete Product.'
143
+
144
+ begin
145
+ @shop_product.destroy
146
+
147
+ respond_to do |format|
148
+ format.html {
149
+ flash[:notice] = notice
150
+ redirect_to admin_shop_products_path
151
+ }
152
+ format.js { render :text => notice, :status => :ok }
153
+ format.json { render :json => { :notice => notice }, :status => :ok }
154
+ end
155
+ rescue
156
+ respond_to do |format|
157
+ format.html {
158
+ flash[:error] = error
159
+ render :remove
160
+ }
161
+ format.js { render :text => error, :status => :unprocessable_entity }
162
+ format.json { render :json => { :error => error }, :status => :unprocessable_entity }
163
+ end
164
+ end
165
+ end
166
+
167
+ private
168
+
169
+ def config_global
170
+ @meta ||= []
171
+ @buttons ||= []
172
+ @parts ||= []
173
+ @popups ||= []
174
+ end
175
+
176
+ def config_new
177
+ @meta << 'category'
178
+ @meta << 'sku'
179
+
180
+ @parts << 'description'
181
+ end
182
+
183
+ def config_edit
184
+ @meta << 'category'
185
+ @meta << 'sku'
186
+
187
+ @parts << 'description'
188
+ @parts << 'images'
189
+
190
+ @buttons << 'browse_images'
191
+ @buttons << 'new_image'
192
+
193
+ @popups << 'browse_images'
194
+ @popups << 'new_image'
195
+ end
196
+
197
+ def assets_global
198
+ include_stylesheet 'admin/extensions/shop/edit'
199
+ end
200
+
201
+ def assets_index
202
+ include_javascript 'admin/dragdrop'
203
+ include_javascript 'admin/extensions/shop/products/index'
204
+ include_stylesheet 'admin/extensions/shop/products/index'
205
+ end
206
+
207
+ def assets_edit
208
+ include_javascript 'admin/dragdrop'
209
+ include_stylesheet 'admin/extensions/shop/products/edit'
210
+ include_javascript 'admin/extensions/shop/products/edit'
211
+ end
212
+
213
+ def set_category
214
+ @shop_product.category = ShopCategory.find(params[:category_id])
215
+ end
216
+
217
+ end
@@ -0,0 +1,9 @@
1
+ class Admin::ShopsController < ApplicationController
2
+
3
+ # GET /admin/shop/products HTML
4
+ #----------------------------------------------------------------------------
5
+ def index
6
+ redirect_to admin_shop_products_path
7
+ end
8
+
9
+ end
@@ -0,0 +1,49 @@
1
+ class Shop::CategoriesController < ApplicationController
2
+
3
+ skip_before_filter :verify_authenticity_token
4
+ no_login_required
5
+
6
+ radiant_layout Radiant::Config['shop.category_layout']
7
+
8
+ rescue_from ActiveRecord::RecordNotFound do |exception|
9
+ render :template => 'site/not_found', :status => :unprocessable_entity
10
+ end
11
+
12
+ # GET /shop/categories/:query
13
+ # GET /shop/categories/:query.js
14
+ # GET /shop/categories/:query.json AJAX and HTML
15
+ #----------------------------------------------------------------------------
16
+ def index
17
+ attr_hash = { :include => :products, :only => ShopCategory.params }
18
+
19
+ @shop_categories = ShopCategory.search(params[:query])
20
+
21
+ respond_to do |format|
22
+ format.html { render }
23
+ format.js { render :partial => '/shop/categories/categories', :collection => @shop_categories }
24
+ format.json { render :json => @shop_categories.to_json(ShopCategory.params) }
25
+ end
26
+ end
27
+
28
+ # GET /shop/:handle
29
+ # GET /shop/:handle.js
30
+ # GET /shop/:handle.json AJAX and HTML
31
+ #----------------------------------------------------------------------------
32
+ def show
33
+ attr_hash = { :include => :products, :only => ShopCategory.params }
34
+
35
+ if @shop_category = ShopCategory.find(:first, :conditions => { :handle => params[:handle] })
36
+ @title = @shop_category.name
37
+ @radiant_layout = @shop_category.layout.name
38
+
39
+ respond_to do |format|
40
+ format.html { render }
41
+ format.js { render :partial => '/shop/categories/category', :locals => { :category => @shop_category } }
42
+ format.json { render :json => @shop_category.to_json(ShopCategory.params) }
43
+ end
44
+ else
45
+ raise ActiveRecord::RecordNotFound
46
+ end
47
+ end
48
+
49
+ end
@@ -0,0 +1,165 @@
1
+ class Shop::LineItemsController < ApplicationController
2
+
3
+ no_login_required
4
+ skip_before_filter :verify_authenticity_token
5
+
6
+ # GET /shop/line_items
7
+ # GET /shop/line_items.js
8
+ # GET /shop/line_items.json AJAX and HTML
9
+ #----------------------------------------------------------------------------
10
+ def index
11
+ attr_hash = {
12
+ :include => :product,
13
+ :only => ShopLineItem.params
14
+ }
15
+
16
+ @shop_line_items = find_or_create_shop_order.line_items.all
17
+
18
+ respond_to do |format|
19
+ format.html { render :index }
20
+ format.js { render :partial => '/shop/line_items/line_item', :collection => @shop_line_items }
21
+ format.json { render :json => @shop_line_items.to_json(attr_hash) }
22
+ end
23
+ end
24
+
25
+ # GET /shop/line_items/1
26
+ # GET /shop/line_items/1.js
27
+ # GET /shop/line_items/1.json AJAX and HTML
28
+ #----------------------------------------------------------------------------
29
+ def show
30
+ attr_hash = {
31
+ :include => :product,
32
+ :only => ShopLineItem.params
33
+ }
34
+
35
+ @shop_line_item = find_or_create_shop_order.line_items.find(params[:id])
36
+
37
+ respond_to do |format|
38
+ format.html { render :show }
39
+ format.js { render :partial => '/shop/line_items/line_item', :locals => { :line_item => @shop_line_item } }
40
+ format.json { render :json => @shop_line_item.to_json(attr_hash) }
41
+ end
42
+ end
43
+
44
+ # POST /shop/line_items/1
45
+ # POST /shop/line_items/1.js
46
+ # POST /shop/line_items/1.xml
47
+ # POST /shop/line_items/1.json AJAX and HTML
48
+ #----------------------------------------------------------------------------
49
+ def create
50
+ notice = 'Item added to Cart.'
51
+ error = 'Could not add Item to Cart.'
52
+
53
+ attr_hash = {
54
+ :include => :item,
55
+ :only => ShopLineItem.params
56
+ }
57
+
58
+ begin
59
+ id = params[:line_item][:item_id]
60
+ type = params[:line_item][:item_type]
61
+ quantity = params[:line_item][:quantity]
62
+
63
+ @shop_line_item = find_or_create_shop_order.add!(id, quantity, type)
64
+
65
+ respond_to do |format|
66
+ format.html {
67
+ flash[:notice] = notice
68
+ redirect_to :back
69
+ }
70
+ format.js { render :partial => '/shop/line_items/line_item', :locals => { :line_item => @shop_line_item } }
71
+ format.json { render :json => @shop_line_item.to_json(attr_hash) }
72
+ end
73
+ rescue Exception => e
74
+ raise e.inspect if RAILS_ENV['development']
75
+
76
+ respond_to do |format|
77
+ format.html {
78
+ flash[:error] = error
79
+ redirect_to :back
80
+ }
81
+ format.js { render :text => error, :status => :unprocessable_entity }
82
+ format.json { render :json => { :error => error }, :status => :unprocessable_entity }
83
+ end
84
+ end
85
+ end
86
+
87
+ # PUT /shop/line_items/1
88
+ # PUT /shop/line_items/1.js
89
+ # PUT /shop/line_items/1.xml
90
+ # PUT /shop/line_items/1.json AJAX and HTML
91
+ #----------------------------------------------------------------------------
92
+ def update
93
+ notice = 'Item updated successfully.'
94
+ error = 'Could not update Item.'
95
+
96
+ attr_hash = {
97
+ :include => :product,
98
+ :only => ShopLineItem.params
99
+ }
100
+
101
+ begin
102
+ id = params[:line_item][:id]
103
+
104
+ quantity = params[:line_item][:quantity] || 1
105
+
106
+ @shop_line_item = find_or_create_shop_order.update!(id, quantity)
107
+
108
+ respond_to do |format|
109
+ format.html {
110
+ flash[:notice] = notice
111
+ redirect_to :back
112
+ }
113
+ format.js { render :partial => '/shop/line_items/line_item', :locals => { :line_item => @shop_line_item } }
114
+ format.json { render :json => @shop_line_item.to_json(attr_hash) }
115
+ end
116
+ rescue Exception => e
117
+ raise e.inspect if RAILS_ENV['development']
118
+
119
+ respond_to do |format|
120
+ format.html {
121
+ flash[:error] = error
122
+ redirect_to :back
123
+ }
124
+ format.js { render :text => error, :status => :unprocessable_entity }
125
+ format.json { render :json => { :error => error }, :status => :unprocessable_entity }
126
+ end
127
+ end
128
+ end
129
+
130
+ # DELETE /shop/line_items/1
131
+ # DELETE /shop/line_items/1.js
132
+ # DELETE /shop/line_items/1.xml
133
+ # DELETE /shop/line_items/1.json AJAX and HTML
134
+ #----------------------------------------------------------------------------
135
+ def destroy
136
+ notice = 'Item removed from Cart.'
137
+ error = 'Could not remove Item from Cart.'
138
+
139
+ begin
140
+ # Expects the product it, not the line item
141
+ find_or_create_shop_order.remove!(params[:id])
142
+
143
+ respond_to do |format|
144
+ format.html {
145
+ flash[:notice] = notice
146
+ redirect_to :back
147
+ }
148
+ format.js { render :text => notice, :status => :ok }
149
+ format.json { render :json => { :notice => notice }, :status => :ok }
150
+ end
151
+ rescue Exception => e
152
+ raise e.inspect if RAILS_ENV['development']
153
+
154
+ respond_to do |format|
155
+ format.html {
156
+ flash[:error] = error
157
+ redirect_to :back
158
+ }
159
+ format.js { render :text => error, :status => :unprocessable_entity }
160
+ format.json { render :json => { :error => error }, :status => :unprocessable_entity }
161
+ end
162
+ end
163
+ end
164
+
165
+ end
@@ -0,0 +1,16 @@
1
+ class Shop::OrdersController < ApplicationController
2
+
3
+ no_login_required
4
+
5
+ def finalize
6
+ @order = current_shop_order
7
+
8
+ if @order.present? and !@order.new?
9
+ request.session[:shop_order] = nil
10
+ redirect_to "/#{Radiant::Config['shop.cart_thanks_path']}"
11
+ else
12
+ redirect_to "/#{Radiant::Config['shop.cart_path']}"
13
+ end
14
+ end
15
+
16
+ end