spree_active_sale 1.0.6 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/README.md +198 -56
  2. data/app/controllers/spree/admin/active_sale_events_controller.rb +52 -0
  3. data/app/controllers/spree/admin/active_sales_controller.rb +25 -0
  4. data/app/controllers/spree/admin/sale_images_controller.rb +33 -0
  5. data/app/controllers/spree/checkout_controller_decorator.rb +6 -0
  6. data/app/controllers/spree/home_controller_decorator.rb +10 -0
  7. data/app/controllers/spree/orders_controller_decorator.rb +6 -0
  8. data/app/controllers/{products_controller_decorator.rb → spree/products_controller_decorator.rb} +5 -1
  9. data/app/controllers/spree/store_controller_decorator.rb +11 -0
  10. data/app/controllers/{taxons_controller_decorator.rb → spree/taxons_controller_decorator.rb} +1 -1
  11. data/app/helpers/spree/active_sale_events_helper.rb +46 -0
  12. data/app/helpers/spree/active_sales_helper.rb +4 -0
  13. data/app/models/spree/active_sale.rb +12 -6
  14. data/app/models/spree/active_sale_configuration.rb +13 -0
  15. data/app/models/spree/active_sale_event.rb +58 -0
  16. data/app/models/spree/line_item_decorator.rb +6 -0
  17. data/app/models/spree/order_decorator.rb +6 -0
  18. data/app/models/spree/product_decorator.rb +14 -3
  19. data/app/models/spree/sale_event.rb +86 -0
  20. data/app/models/spree/sale_image.rb +51 -0
  21. data/app/models/spree/taxon_decorator.rb +11 -2
  22. data/app/models/spree/variant_decorator.rb +2 -2
  23. data/app/overrides/admin_active_sales_tab.rb +6 -0
  24. data/app/views/spree/admin/active_sale_events/_form.html.erb +136 -0
  25. data/app/views/spree/admin/active_sale_events/edit.html.erb +17 -0
  26. data/app/views/spree/admin/active_sale_events/index.html.erb +12 -0
  27. data/app/views/spree/admin/active_sale_events/new.html.erb +15 -0
  28. data/app/views/spree/admin/active_sales/_form.html.erb +35 -0
  29. data/app/views/spree/admin/active_sales/edit.html.erb +17 -0
  30. data/app/views/spree/admin/active_sales/index.html.erb +57 -0
  31. data/app/views/spree/admin/active_sales/new.html.erb +15 -0
  32. data/app/views/spree/admin/sale_images/_form.html.erb +18 -0
  33. data/app/views/spree/admin/sale_images/edit.html.erb +24 -0
  34. data/app/views/spree/admin/sale_images/new.html.erb +19 -0
  35. data/app/views/spree/admin/shared/_list_events.html.erb +32 -0
  36. data/app/views/spree/admin/shared/_sale_images.html.erb +41 -0
  37. data/app/views/spree/admin/shared/_translations.html.erb +57 -0
  38. data/app/views/spree/home/index.html.erb +4 -0
  39. data/app/views/spree/shared/_sale_events.html.erb +28 -0
  40. data/config/locales/active_sales_en.yml +74 -0
  41. data/config/locales/active_sales_es.yml +74 -0
  42. data/config/routes.rb +12 -0
  43. data/db/migrate/20130404062459_create_sale_events.rb +70 -0
  44. data/db/migrate/20130411091742_add_discount_to_sale_events.rb +5 -0
  45. data/lib/generators/spree_active_sale/assets/assets_generator.rb +37 -0
  46. data/lib/generators/spree_active_sale/templates/README.md +3 -0
  47. data/lib/spree_active_sale/engine.rb +7 -0
  48. data/lib/tasks/spree_active_sale.rake +14 -6
  49. metadata +46 -11
  50. data/app/assets/javascripts/admin/spree_active_sale.js +0 -1
  51. data/app/assets/javascripts/store/spree_active_sale.js +0 -1
  52. data/app/assets/stylesheets/admin/spree_active_sale.css +0 -3
  53. data/app/assets/stylesheets/store/spree_active_sale.css +0 -3
  54. data/app/models/spree/active_sale/event.rb +0 -57
  55. data/config/locales/en.yml +0 -12
data/README.md CHANGED
@@ -1,80 +1,224 @@
1
- Welcome to Spree Active Sale
2
- ============================
1
+ # Welcome to Spree Active Sale
3
2
 
4
- Spree Active Sale makes it easy to handle flash sale/ daily deals behavior with in a spree application. By this, you can have a variant, product, or group number of products in a taxon, attach that variant, product, or taxon to a sale event with a start and end date for scheduling. So that, your sale event will only be available between the dates given and when the sale is gone(i.e. not live), it will not be accessible at any point till you create a new one or re-schedule the same.
3
+ Spree Active Sale makes it easy to handle flash sale/ daily deals behavior within a spree application. By this, you can have a product, or group number of products in a taxon, attach that product, or taxon to a sale event with a start and end date for scheduling. So that, your sale event will only be available between the dates given and when the sale is gone(i.e. not live), it will not be accessible at any point till you create a new one or reschedule the same.
5
4
 
5
+ > It's all about selling your first product. ~ [Vivek SP](https://twitter.com/viveksp)
6
6
 
7
- FEATURES
8
- ========
7
+ ----------
8
+
9
+ ## FEATURES
9
10
 
10
11
  * Provides a quick implementation of flash sales/ daily deals behavior by a easy scheduler a.k.a *ActiveSale*.
11
- * Supplies methods for class <tt>Spree::ActiveSale::Event</tt> like: <tt>live</tt>, <tt>active</tt>, <tt>live_active</tt>, <tt>hidden</tt>, <tt>live_active_and_hidden</tt>, <tt>upcoming_events</tt>, <tt>starting_today</tt>, <tt>ending_today</tt>.
12
- * <tt>Spree::ActiveSale::Event.live</tt> lists all sale events which are currently and suppose to be running.
13
- * <tt>Spree::ActiveSale::Event.active</tt> lists all sale events which are active, they may or may not be live. You can do <tt>Spree::ActiveSale::Event.active(false)</tt> to list all inactive sale events.
14
- * <tt>Spree::ActiveSale::Event.live_active</tt> lists all sale events which are live and active, which includes hidden sales, too. Doing <tt>Spree::ActiveSale::Event.live_active(false)</tt> will list all sale events which live and not active.
15
- * <tt>Spree::ActiveSale::Event.hidden</tt> lists all sale events which are hidden, they may or may not be live. You can do <tt>Spree::ActiveSale::Event.hidden(false)</tt> to list sale events which are not hidden.
16
- * <tt>Spree::ActiveSale::Event.live_active_and_hidden</tt> lists all sale events which are live, active, and hidden. <tt>Spree::ActiveSale::Event.live_active_and_hidden(:active => false, :hidden => false)</tt> will list inactive and not hidden sale events, you can change values accordingly.
17
- * <tt>Spree::ActiveSale::Event.upcoming_events</tt> lists all scheduled sale events which are going to be live in future.
18
- * <tt>Spree::ActiveSale::Event.starting_today</tt> lists all sale events which are going to or have start today.
19
- * <tt>Spree::ActiveSale::Event.ending_today</tt> lists all sale events which are going to expire today.
20
- * <tt>Spree::ActiveSale::Event.is_live?(instance)</tt> here instance can be an object of "Spree::ActiveSale::Event", "Spree::Variant", "Spree::Product", or "Spree::Taxon" class, which simply says if sale event for that instance is accessible for users or not.
21
-
22
-
23
- [![Dependency Status](https://gemnasium.com/suryart/spree_active_sale.png)](https://gemnasium.com/suryart/spree_active_sale)
24
- [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/suryart/spree_active_sale)
25
- [![Build Status](https://travis-ci.org/suryart/spree_active_sale.png?branch=1-0-5)](https://travis-ci.org/suryart/spree_active_sale)
26
-
27
- INSTALLATION
28
- ============
29
-
30
- In a rails application with Spree installed include the following line in your Gemfile:
31
- * To use the master branch from github:
32
-
33
- `gem 'spree_active_sale' , :git => 'git://github.com/suryart/spree_active_sale.git'`
12
+ * Provides an admin interface for creating/ scheduling, managing, or re-scheduling sale events.
13
+ * Provides a view helper for countdown timer to show sale's ending time, which will be shown to your customers. This eventually makes a sense of urgency in your customers' mind.
14
+ * Supplies methods for class <tt>Spree::ActiveSaleEvent</tt> like: <tt>live</tt>, <tt>active</tt>, <tt>live_active</tt>, <tt>hidden</tt>, <tt>live_active_and_hidden</tt>, <tt>upcoming_events</tt>, <tt>starting_today</tt>, <tt>ending_today</tt>.
15
+
16
+ ## LINKS
17
+
18
+ * Demo application: [Spree Active Sale Demo](https://github.com/suryart/spree_active_sale_demo)
19
+ * Dependency status: [![Dependency Status](https://gemnasium.com/suryart/spree_active_sale.png)](https://gemnasium.com/suryart/spree_active_sale)
20
+ * Code climate: [![Code Climate](https://codeclimate.com/github/suryart/spree_active_sale.png)](https://codeclimate.com/github/suryart/spree_active_sale)
21
+ * Build Status: [![Build Status](https://travis-ci.org/suryart/spree_active_sale.png?branch=v1.3.0)](https://travis-ci.org/suryart/spree_active_sale)
22
+ * Issues: [Project issues](https://github.com/suryart/spree_active_sale/issues)
23
+ * Fork: [Fork this Project](https://github.com/suryart/spree_active_sale/fork_select)
34
24
 
25
+ ## INSTALLATION
35
26
 
36
- * Or get it from rubygems.org:
27
+ ### In a rails application with Spree installed include the following line in your Gemfile:
28
+ * Get the latest greatest from github:
37
29
 
30
+ ```ruby
31
+ gem 'spree_active_sale' , :git => 'git://github.com/suryart/spree_active_sale.git'
32
+ ```
38
33
 
39
- `gem 'spree_active_sale'`
34
+ * Get the 1-3-stable branch for Spree 1.3.x from github:
35
+
36
+ ```ruby
37
+ gem 'spree_active_sale' , :git => 'git://github.com/suryart/spree_active_sale.git', :branch => '1-3-stable'
38
+ ```
39
+
40
+ * Or get it from rubygems.org by mentioning the following line in your Gemfile:
41
+
42
+ ```ruby
43
+ gem 'spree_active_sale', '1.0.6'
44
+ ```
40
45
 
41
- Then run the following commands:
46
+ ### Then run the following commands:
42
47
 
43
48
  $ bundle install
44
- $ rake spree_active_sale:install
49
+ $ rails g spree_active_sale:install
45
50
  $ rake db:migrate
46
51
  $ rails s
47
52
 
53
+ ### Optional commands available:
48
54
 
49
- Example
50
- =======
55
+ $ rails g spree_active_sale:assets ; to copy assets from plugin dir to app's dir
56
+ $ rake spree_active_sale:install ; Copies all migrations and assets to the application
57
+ $ rake spree_active_sale:install:assets ; Copies all assets to the application
58
+ $ rake spree_active_sale:install:migrations ; Copies all migrations to the application
59
+ $ rake db:migrate ; do not forget to run this after copying migrations
51
60
 
52
- * Get a taxon in rails console:
53
-
54
- `taxon = Taxon.last`
61
+ ### Including stylesheet and javascript for admin and store
62
+ If you do not run **rails g spree_active_sale:install** then you must have to add stylesheets and javascripts accordinlgy. As these steps are important because, if you don't follow/ add them. You will not see datetime picker for start and end date in Admin area and countdown timer on the Store page.
55
63
 
56
- * Create and *ActiveSale*:
64
+ ##### Stylesheet usage in Rails >= 3.1(Only supported versions for now)
57
65
 
58
- `active_sale = Spree::ActiveSale.create name: "January 2013 sales"`
59
- output:
66
+ You will have to add stylesheet in the bottom of your **admin/all.css** file as follows -
67
+
68
+ *= require admin/spree_active_sale
60
69
 
61
- `#<Spree::ActiveSale id: 1, name: "January 2013 sales", created_at: "2013-01-20 20:33:57", updated_at: "2013-01-20 20:33:57">`
70
+ Later you will have to add stylesheet in the bottom of your **store/all.css** file as follows -
71
+
72
+ *= require store/spree_active_sale
62
73
 
63
- * Then create an *Event* under this sale by:
74
+ ##### Javascript usage in Rails >= 3.1(Only supported versions for now)
75
+
76
+ You will have to add javascript in the bottom of your **admin/all.js** file as follows -
77
+
78
+ //= require admin/spree_active_sale
79
+
80
+ You will have to add javascript in the bottom of your **store/all.js** file as follows -
64
81
 
65
- `event = taxon.active_sale_event.create name: "January 2013 sales", active_sale_id: active_sale.id, start_date: Time.now, end_date: Time.now+1.day, permalink: taxon.permalink `
82
+ //= require store/spree_active_sale
83
+
84
+ ## Example and usages
85
+
86
+ * For trying to see how this plugin works. You can create an *ActiveSale* and its events by following these commands in your <tt>rails console</tt>:
87
+ ```ruby
88
+ # Get a taxon in rails console:
89
+ taxon = Spree::Taxon.last
90
+
91
+ # Create an ActiveSale
92
+ active_sale = Spree::ActiveSale.create(:name => "January 2013 sales")
93
+
94
+ # Output => => #<Spree::ActiveSale id: 42, name: "January 2013 sales", description: nil,
95
+ # permalink: nil, start_date: nil, end_date: nil, is_active: true, is_hidden: false,
96
+ # is_permanent: false, eventable_id: nil, eventable_type: nil, active_sale_id: nil,
97
+ # created_at: "2013-04-16 07:26:45", updated_at: "2013-04-16 07:26:45",
98
+ # type: "Spree::ActiveSale", parent_id: nil, lft: 5, rgt: 6, position: nil, discount: nil>
66
99
 
67
- * Now try to access this taxon in browser, there should be no other taxon/ product link accessible except the one we've created just now.
68
100
 
101
+ # Then create an Event under this sale by:
102
+ event = taxon.active_sale_events.create(:name => "January 2013 sales",
103
+ :active_sale_id => active_sale.id, :start_date => Time.now,
104
+ :end_date => Time.now+1.day, :permalink => taxon.permalink)
69
105
 
70
- TODOs
71
- =====
106
+ # Now try to access this taxon in web browser.
107
+ # There should be no any other taxon/ product link accessible except
108
+ # the one we've created just now.
109
+ ```
110
+ * When you have enough sale events in your database, you can try these commands as per your requirements :
111
+ ```ruby
112
+ # listing all sale events which are currently and suppose to be running.
113
+ Spree::ActiveSaleEvent.live
114
+
115
+ # listing all sale events which are active, they may or may not be live.
116
+ Spree::ActiveSaleEvent.active
117
+
118
+ # to list all inactive sale events.
119
+ Spree::ActiveSaleEvent.active(false)
120
+
121
+ # listing all sale events which are live and active, which includes hidden sales, too.
122
+ Spree::ActiveSaleEvent.live_active
123
+
124
+ # to list all sale events which live and not active.
125
+ Spree::ActiveSaleEvent.live_active(false)
126
+
127
+ # listing all sale events which are hidden, they may or may not be live.
128
+ Spree::ActiveSaleEvent.hidden
129
+
130
+ # to list sale events which are not hidden.
131
+ Spree::ActiveSaleEvent.hidden(false)
132
+
133
+ # listing all sale events which are live, active, and hidden.
134
+ Spree::ActiveSaleEvent.live_active_and_hidden
135
+
136
+ # to list inactive and not hidden sale events, you can change values accordingly.
137
+ Spree::ActiveSaleEvent.live_active_and_hidden(:active => false, :hidden => false)
138
+
139
+ # listing all scheduled sale events which are going to be live in future.
140
+ Spree::ActiveSaleEvent.upcoming_events
141
+
142
+ # listing all past sale events which ended and not accessible to users.
143
+ Spree::ActiveSaleEvent.past_events
144
+
145
+ # listing all sale events which are going to or have start today.
146
+ Spree::ActiveSaleEvent.starting_today
147
+
148
+ # listing all sale events which are going to expire today.
149
+ Spree::ActiveSaleEvent.ending_today
150
+
151
+ # to check if an active sale event is live?
152
+ active_sale_event = Spree::ActiveSaleEvent.first
153
+ # output => => #<Spree::ActiveSaleEvent id: 1, name: "Event 1", description: "20% Off",
154
+ # permalink: "t/designers/event-1",
155
+ # start_date: "2013-03-22 04:00:03", end_date: "2013-04-25 04:00:00", is_active: true,
156
+ # is_hidden: false, is_permanent: false, eventable_id: 1992,
157
+ # eventable_type: "Spree::Taxon", active_sale_id: 31, created_at: "2013-03-23 08:37:29",
158
+ # updated_at: "2013-04-09 18:55:37", type: "Spree::ActiveSaleEvent", parent_id: nil,
159
+ # lft: nil, rgt: nil, position: nil, discount: nil>
160
+ # Now do:
161
+ active_sale_event.live?
162
+ # output => true
163
+
164
+ # you can also check if that event was live on a particular datetime, for example:
165
+ active_sale_event.live?(Time.zone.now - 1.month)
166
+
167
+ # to check if an active sale event is live and active:
168
+ active_sale_event.live_and_active?
169
+ # output => true
170
+
171
+ # you can check if that event was live and active on a particular datetime by:
172
+ active_sale_event.live_and_active?(Time.zone.now - 1.month)
173
+
174
+ # to check if an instance/ object is live or not?.
175
+ # Here instance can be an object of
176
+ # "Spree::ActiveSaleEvent", "Spree::Variant", "Spree::Product", or "Spree::Taxon" class.
177
+ # Which simply says if sale event for that instance is accessible for users or not.
178
+ Spree::ActiveSaleEvent.is_live?(instance)
179
+ ```
180
+
181
+ ## Overriding countdown timer's layout differently for different events
182
+ There is a view helper which shows the count down timer. This extension uses [jQuery Countdown](http://keith-wood.name/countdown.html) library for countdown timer. View helper available for count down timer is:
183
+
184
+ ```ruby
185
+ <%= sale_event_timer(active_sale_event) %>
186
+ ```
187
+ You can pass a layout(layout is optional. default value is: '{dn} days {hnn}{sep}{mnn}{sep}{snn}' ) according to your requirement like this:
188
+
189
+ ```ruby
190
+ <%= sale_event_timer(active_sale_event, '{dn} days {hnn} hours {sep}{mnn} minutes {sep}{snn} seconds') %>
191
+ ```
192
+
193
+ Please visit [jQuery Countdown](http://keith-wood.name/countdown.html) for more layouts.
194
+
195
+ ## Overriding configuration and preferences
196
+
197
+ You can use put this at the bottom of your **application's app/config/initializers/spree.rb**:
198
+
199
+ ```ruby
200
+ Spree::ActiveSale.config do |config|
201
+ config.admin_active_sales_per_page = 20
202
+ config.active_sales_per_page = 10
203
+ config.admin_active_sale_events_per_page = 30
204
+ config.active_sale_events_per_page = 40
205
+ end
206
+ ```
207
+ Since you can not set boolean values from the block config shown above for assignment(:?=). To override boolean preferences, you can always do this with in the spree config file spree.rb:
208
+
209
+ ```ruby
210
+ Spree::ActiveSaleConfig[:paginate_sale_events_for_admin?] = true
211
+ Spree::ActiveSaleConfig[:paginate_sales_for_admin?] = true
212
+ Spree::ActiveSaleConfig[:paginate_sale_events_for_user?] = true
213
+ Spree::ActiveSaleConfig[:paginate_sales_for_user?] = false
214
+ ```
215
+
216
+ ## TODOs
72
217
 
73
218
  * Improve testing and write more test cases.
74
- * Provide an admin interface for creating/ scheduling, managing, or re-scheduling sales.
219
+ * Enhance the admin interface for active sales and events[U.I. and U.X.].
75
220
 
76
- Testing
77
- -------
221
+ ## Testing
78
222
 
79
223
  Be sure to bundle your dependencies and then create a dummy test app for the specs to run against.
80
224
 
@@ -82,19 +226,17 @@ Be sure to bundle your dependencies and then create a dummy test app for the spe
82
226
  $ bundle exec rake test_app
83
227
  $ bundle exec rspec spec
84
228
 
85
- Contributing
86
- ============
229
+ ## Contributing
87
230
 
88
231
  1. [Fork](https://help.github.com/articles/fork-a-repo) the project
89
232
  2. Make one or more well commented and clean commits to the repository. You can make a new branch here if you are modifying more than one part or feature.
90
- 3. Perform a [pull request](https://help.github.com/articles/using-pull-requests) in github's web interface.
233
+ 3. Add tests for it. This is important so I don’t break it in a future version unintentionally.
234
+ 4. Perform a [pull request](https://help.github.com/articles/using-pull-requests) in github's web interface.
91
235
 
92
- NOTE
93
- ====
236
+ ## NOTE
94
237
 
95
238
  The current version supports Spree 1.3.0 or above. Older versions of Spree are unlikely to work, so attempt at your own risk.
96
239
 
97
240
 
98
- License
99
- ---------
241
+ ## License
100
242
  Copyright (c) 2013 Surya Tripathi, released under the New BSD License
@@ -0,0 +1,52 @@
1
+ module Spree
2
+ module Admin
3
+ class ActiveSaleEventsController < ResourceController
4
+ belongs_to 'spree/active_sale', :find_by => :id
5
+ before_filter :load_active_sale, :only => [:index]
6
+ update.before :get_eventable
7
+
8
+ def show
9
+ redirect_to( :action => :edit )
10
+ end
11
+
12
+ def eventables
13
+ search = params[:eventable_type].constantize.search(:name_cont => params[:name])
14
+ render :json => search.result.map(&:name)
15
+ end
16
+
17
+ protected
18
+
19
+ def collection
20
+ return @collection if @collection.present?
21
+ @search = Spree::ActiveSaleEvent.where(:active_sale_id => params[:active_sale_id]).ransack(params[:q])
22
+ @collection = @search.result.page(params[:page]).per(Spree::ActiveSaleConfig[:admin_active_sale_events_per_page])
23
+ end
24
+
25
+ def load_active_sale
26
+ @active_sale = Spree::ActiveSale.find(params[:active_sale_id])
27
+ end
28
+
29
+ def build_resource
30
+ get_eventable unless params[object_name].nil?
31
+ if parent_data.present?
32
+ parent.send(controller_name).build(params[object_name])
33
+ else
34
+ model_class.new(params[object_name])
35
+ end
36
+ end
37
+
38
+ def get_eventable
39
+ object_name = params[:active_sale_event]
40
+ unless object_name[:eventable_type].nil?
41
+ eventable = "#{object_name[:eventable_type]}".constantize.find_by_name(object_name[:eventable_name])
42
+ object_name.delete(:eventable_name)
43
+ unless eventable.nil?
44
+ object_name.merge!(:eventable_id => eventable.id, :permalink => eventable.permalink)
45
+ else
46
+ object_name.merge!(:eventable_id => nil)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,25 @@
1
+ module Spree
2
+ module Admin
3
+ class ActiveSalesController < ResourceController
4
+
5
+ def index
6
+ respond_with(@collection) do |format|
7
+ format.html
8
+ format.json { render :json => json_data }
9
+ end
10
+ end
11
+
12
+ def show
13
+ redirect_to edit_object_url(@active_sale)
14
+ end
15
+
16
+ protected
17
+
18
+ def collection
19
+ return @collection if @collection.present?
20
+ @search = Spree::ActiveSale.includes(:active_sale_events).ransack(params[:q])
21
+ @collection = @search.result.page(params[:page]).per(Spree::ActiveSaleConfig[:admin_active_sales_per_page])
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,33 @@
1
+ module Spree
2
+ module Admin
3
+ class SaleImagesController < ResourceController
4
+ belongs_to 'spree/active_sale_event', :find_by => :id
5
+ before_filter :load_data
6
+
7
+ create.before :set_viewable
8
+ update.before :set_viewable
9
+ destroy.before :destroy_before
10
+
11
+ private
12
+
13
+ def location_after_save
14
+ edit_admin_active_sale_active_sale_event_url(@active_sale_event.active_sale, @active_sale_event)
15
+ end
16
+
17
+ def load_data
18
+ @active_sale = Spree::ActiveSale.find(params[:active_sale_id])
19
+ @active_sale_event = Spree::ActiveSaleEvent.find(params[:active_sale_event_id])
20
+ end
21
+
22
+ def set_viewable
23
+ @sale_image.viewable_type = 'Spree::ActiveSaleEvent'
24
+ @sale_image.viewable_id = @active_sale_event.id
25
+ end
26
+
27
+ def destroy_before
28
+ @viewable = @sale_image.viewable
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,6 @@
1
+ module Spree
2
+ CheckoutController.class_eval do
3
+ before_filter :check_active_products_in_order
4
+
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ module Spree
2
+ HomeController.class_eval do
3
+
4
+ # List live and active sales on home page
5
+ def index
6
+ @sale_events = Spree::ActiveSaleEvent.live_active
7
+ respond_with(@sale_events)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ module Spree
2
+ OrdersController.class_eval do
3
+ before_filter :check_active_products_in_order
4
+
5
+ end
6
+ end
@@ -2,11 +2,15 @@ module Spree
2
2
  ProductsController.class_eval do
3
3
  HTTP_REFERER_REGEXP = /^https?:\/\/[^\/]+\/t\/([a-z0-9\-\/]+)$/ unless defined? HTTP_REFERER_REGEXP
4
4
 
5
+ def index
6
+ redirect_to root_url, :error => t('spree.active_sale.event.flash.error')
7
+ end
8
+
5
9
  def show
6
10
  @product = Spree::Product.active.find_by_permalink!(params[:id])
7
11
  return unless @product
8
12
 
9
- if Spree::ActiveSale::Event.is_live? @product
13
+ if @product.live?
10
14
  @variants = Spree::Variant.active.includes([:option_values, :images]).where(:product_id => @product.id)
11
15
  @product_properties = Spree::ProductProperty.includes(:property).where(:product_id => @product.id)
12
16