spree_promo 1.2.5 → 1.3.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/app/assets/javascripts/admin/promotions.js +10 -1
  2. data/app/assets/stylesheets/admin/spree_promo.css +0 -1
  3. data/app/controllers/spree/admin/promotion_actions_controller.rb +2 -2
  4. data/app/controllers/spree/admin/promotion_rules_controller.rb +2 -2
  5. data/app/controllers/spree/checkout_controller_decorator.rb +5 -16
  6. data/app/controllers/spree/orders_controller_decorator.rb +2 -18
  7. data/app/controllers/spree/store_controller_decorator.rb +55 -0
  8. data/app/models/spree/order_decorator.rb +5 -14
  9. data/app/models/spree/order_updater_decorator.rb +14 -0
  10. data/app/models/spree/promotion/actions/create_adjustment.rb +12 -22
  11. data/app/models/spree/promotion/actions/create_line_items.rb +2 -18
  12. data/app/models/spree/promotion/rules/first_order.rb +2 -19
  13. data/app/models/spree/promotion/rules/user_logged_in.rb +8 -1
  14. data/app/models/spree/promotion.rb +6 -6
  15. data/app/models/spree/promotion_action_line_item.rb +2 -0
  16. data/app/overrides/promo_admin_tabs.rb +1 -1
  17. data/app/views/spree/admin/promotion_actions/create.js.erb +6 -3
  18. data/app/views/spree/admin/promotion_actions/destroy.js.erb +1 -2
  19. data/app/views/spree/admin/promotion_rules/create.js.erb +6 -0
  20. data/app/views/spree/admin/promotion_rules/destroy.js.erb +1 -1
  21. data/app/views/spree/admin/promotions/_actions.html.erb +21 -15
  22. data/app/views/spree/admin/promotions/_form.html.erb +55 -51
  23. data/app/views/spree/admin/promotions/_promotion_action.html.erb +5 -5
  24. data/app/views/spree/admin/promotions/_promotion_rule.html.erb +5 -4
  25. data/app/views/spree/admin/promotions/_rules.html.erb +39 -26
  26. data/app/views/spree/admin/promotions/actions/_create_adjustment.html.erb +8 -9
  27. data/app/views/spree/admin/promotions/actions/_create_line_items.html.erb +19 -40
  28. data/app/views/spree/admin/promotions/edit.html.erb +22 -6
  29. data/app/views/spree/admin/promotions/index.html.erb +49 -35
  30. data/app/views/spree/admin/promotions/new.html.erb +13 -3
  31. data/app/views/spree/admin/promotions/rules/_item_total.html.erb +6 -7
  32. data/app/views/spree/admin/promotions/rules/_landing_page.html.erb +5 -8
  33. data/app/views/spree/admin/promotions/rules/_product.html.erb +7 -8
  34. data/app/views/spree/admin/promotions/rules/_user_logged_in.html.erb +0 -3
  35. data/config/locales/en.yml +8 -2
  36. data/config/routes.rb +1 -1
  37. data/db/migrate/20120831092359_spree_promo_one_two.rb +45 -0
  38. data/lib/spree/promo/engine.rb +5 -6
  39. metadata +11 -26
  40. data/app/assets/stylesheets/admin/promotions.css +0 -44
  41. data/db/migrate/20100419190933_rename_coupons_to_promotions.rb +0 -10
  42. data/db/migrate/20100426100726_create_promotion_rules.rb +0 -24
  43. data/db/migrate/20100501084722_match_policy_for_promotions.rb +0 -5
  44. data/db/migrate/20100501095202_create_promotion_rules_users.rb +0 -14
  45. data/db/migrate/20100502163939_name_for_promotions.rb +0 -5
  46. data/db/migrate/20100923095305_update_calculable_type_for_promotions.rb +0 -9
  47. data/db/migrate/20101026184833_migrate_adjustments.rb +0 -9
  48. data/db/migrate/20110331094351_promotion_changes_to_subclass_of_activator.rb +0 -22
  49. data/db/migrate/20110404123358_create_promotion_actions.rb +0 -9
  50. data/db/migrate/20110601202923_create_promotion_action_line_items.rb +0 -10
  51. data/db/migrate/20120119024707_namespace_promo_tables.rb +0 -85
  52. data/db/migrate/20120119024708_create_spree_pending_promotions.rb +0 -11
  53. data/db/migrate/20120119024721_content_visited_event.rb +0 -29
@@ -1,10 +0,0 @@
1
- class RenameCouponsToPromotions < ActiveRecord::Migration
2
- def up
3
- drop_table :promotions if table_exists?(:promotions)
4
- rename_table :coupons, :promotions
5
- end
6
-
7
- def down
8
- rename_table :promotions, :coupons
9
- end
10
- end
@@ -1,24 +0,0 @@
1
- class CreatePromotionRules < ActiveRecord::Migration
2
- def up
3
- create_table :promotion_rules do |t|
4
- t.references :promotion, :user, :product_group
5
- t.string :type
6
-
7
- t.timestamps
8
- end
9
- add_index :promotion_rules, :product_group_id
10
- add_index :promotion_rules, :user_id
11
-
12
- create_table :products_promotion_rules do |t|
13
- t.integer :product_id, :promotion_rule_id
14
- end
15
- remove_column :products_promotion_rules, :id
16
- add_index :products_promotion_rules, :product_id
17
- add_index :products_promotion_rules, :promotion_rule_id
18
- end
19
-
20
- def down
21
- drop_table :promotion_rules
22
- drop_table :products_promotion_rules
23
- end
24
- end
@@ -1,5 +0,0 @@
1
- class MatchPolicyForPromotions < ActiveRecord::Migration
2
- def change
3
- add_column :promotions, :match_policy, :string, :default => 'all'
4
- end
5
- end
@@ -1,14 +0,0 @@
1
- class CreatePromotionRulesUsers < ActiveRecord::Migration
2
- def up
3
- create_table :promotion_rules_users do |t|
4
- t.integer :user_id, :promotion_rule_id
5
- end
6
- remove_column :promotion_rules_users, :id
7
- add_index :promotion_rules_users, :user_id
8
- add_index :promotion_rules_users, :promotion_rule_id
9
- end
10
-
11
- def down
12
- drop_table :promotion_rules_users
13
- end
14
- end
@@ -1,5 +0,0 @@
1
- class NameForPromotions < ActiveRecord::Migration
2
- def change
3
- add_column :promotions, :name, :string
4
- end
5
- end
@@ -1,9 +0,0 @@
1
- class UpdateCalculableTypeForPromotions < ActiveRecord::Migration
2
- def up
3
- execute "UPDATE spree_calculators SET calculable_type = 'Promotion' WHERE calculable_type = 'Coupon'"
4
- end
5
-
6
- def down
7
- execute "UPDATE spree_calculators SET calculable_type = 'Coupon' WHERE calculable_type = 'Promotion'"
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- class MigrateAdjustments < ActiveRecord::Migration
2
- def up
3
- execute "UPDATE spree_adjustments SET amount = 0.0 WHERE amount IS NULL"
4
- execute "UPDATE spree_adjustments SET mandatory = #{quoted_true} WHERE locked = #{quoted_true}"
5
- end
6
-
7
- def down
8
- end
9
- end
@@ -1,22 +0,0 @@
1
- class PromotionChangesToSubclassOfActivator < ActiveRecord::Migration
2
- def up
3
- drop_table :promotions
4
- rename_column :promotion_rules, :promotion_id, :activator_id
5
- end
6
-
7
- def down
8
- create_table :promotions, :force => true do |t|
9
- t.string :name
10
- t.string :code
11
- t.string :description
12
- t.integer :usage_limit
13
- t.boolean :combine
14
- t.datetime :expires_at
15
- t.datetime :starts_at
16
- t.string :match_policy, :default => 'all'
17
-
18
- t.timestamps
19
- end
20
- rename_column :promotion_rules, :activator_id, :promotion_id
21
- end
22
- end
@@ -1,9 +0,0 @@
1
- class CreatePromotionActions < ActiveRecord::Migration
2
- def change
3
- create_table :promotion_actions do |t|
4
- t.integer :activator_id
5
- t.integer :position
6
- t.string :type
7
- end
8
- end
9
- end
@@ -1,10 +0,0 @@
1
- class CreatePromotionActionLineItems < ActiveRecord::Migration
2
- def change
3
- create_table :promotion_action_line_items do |t|
4
- t.integer :promotion_action_id, :variant_id
5
- t.integer :quantity, :default => 1
6
- t.references :promotion_action
7
- t.references :variant
8
- end
9
- end
10
- end
@@ -1,85 +0,0 @@
1
- require 'spree/core/preference_rescue'
2
-
3
- class NamespacePromoTables < ActiveRecord::Migration
4
-
5
- def concat(str1, str2)
6
- dbtype = Rails.configuration.database_configuration[Rails.env]['adapter'].to_sym
7
-
8
- case dbtype
9
- when :mysql, :mysql2
10
- "CONCAT(#{str1}, #{str2})"
11
- when :sqlserver
12
- "(#{str1} + #{str2})"
13
- else
14
- "(#{str1} || #{str2})"
15
- end
16
- end
17
-
18
- def update_column_data(table_names, column_name)
19
- tables = Array.wrap(table_names)
20
- tables.each do |table|
21
- execute "UPDATE #{table} SET #{column_name} = #{concat("'Spree::'", column_name)}" +
22
- " where #{column_name} NOT LIKE 'Spree::%' AND #{column_name} IS NOT NULL"
23
- end
24
- end
25
-
26
- def replace_column_data(table_names, column_name)
27
- tables = Array.wrap(table_names)
28
- tables.each do |table|
29
- execute "UPDATE #{table} SET #{column_name} = REPLACE(#{column_name}, 'Spree::', '') " +
30
- " where #{column_name} LIKE 'Spree::%'"
31
- end
32
- end
33
-
34
- def self.up
35
- # namespace promo tables
36
- rename_table :promotion_actions, :spree_promotion_actions
37
- rename_table :promotion_rules, :spree_promotion_rules
38
- rename_table :promotion_rules_users, :spree_promotion_rules_users
39
- rename_table :promotion_action_line_items, :spree_promotion_action_line_items
40
- rename_table :products_promotion_rules, :spree_products_promotion_rules
41
-
42
- update_column_data('spree_promotion_actions', 'type')
43
- update_column_data('spree_promotion_rules', 'type')
44
-
45
- # add old promo preferences as columns
46
- add_column :spree_activators, :usage_limit, :integer
47
- add_column :spree_activators, :match_policy, :string, :default => 'all'
48
- add_column :spree_activators, :code, :string
49
- add_column :spree_activators, :advertise, :boolean, :default => false
50
-
51
- Spree::Activator.reset_column_information
52
-
53
- Spree::Preference.where(:owner_type => 'Spree::Activator').each do |preference|
54
- unless Spree::Activator.exists? preference.owner_id
55
- preference.destroy
56
- next
57
- end
58
-
59
- @activator = Spree::Activator.find(preference.owner_id)
60
- @activator.update_attribute(preference.name, preference.raw_value)
61
- preference.destroy
62
- end
63
-
64
- Spree::PreferenceRescue.try
65
-
66
- # This *should* be in the new_preferences migration inside of Core but...
67
- # This is migration needs to have these keys around so that
68
- # we can convert the promotions over correctly.
69
- # So they hang around until we're *finally* done with them, since promo's
70
- # migrations are copied over *after* core, and then we ditch them.
71
- remove_column :spree_preferences, :group_id
72
- remove_column :spree_preferences, :group_type
73
- end
74
-
75
- def self.down
76
- replace_column_data('spree_promotion_actions', 'type')
77
- replace_column_data('spree_promotion_rules', 'type')
78
-
79
- rename_table :spree_promotion_actions, :promotion_actions
80
- rename_table :spree_promotion_rules, :promotion_rules
81
- rename_table :spree_promotion_rules_users, :promotion_rules_users
82
- rename_table :spree_promotion_action_line_items, :promotion_action_line_items
83
- rename_table :spree_products_promotion_rules, :products_promotion_rules
84
- end
85
- end
@@ -1,11 +0,0 @@
1
- class CreateSpreePendingPromotions < ActiveRecord::Migration
2
- def change
3
- create_table :spree_pending_promotions do |t|
4
- t.references :user
5
- t.references :promotion
6
- end
7
-
8
- add_index :spree_pending_promotions, :user_id
9
- add_index :spree_pending_promotions, :promotion_id
10
- end
11
- end
@@ -1,29 +0,0 @@
1
- # LandingPage used to support static pages, we've moved to a static
2
- # event. This adds path to promotions then migrates the old LandingPage rules
3
- class ContentVisitedEvent < ActiveRecord::Migration
4
-
5
- # Removed Class for Migrations
6
- class Spree::Promotion::Rules::LandingPage < Spree::PromotionRule
7
- preference :path, :string
8
- def eligible?(order, options = {})
9
- true
10
- end
11
- end
12
-
13
- def up
14
- add_column :spree_activators, :path, :string
15
-
16
- Spree::Promotion::Rules::LandingPage.all.each do |promotion_rule|
17
- promotion = promotion_rule.promotion
18
- say "migrating #{promotion.name} promotion to use 'spree.content.visited' event"
19
- promotion.event_name = 'spree.content.visited'
20
- promotion.path = promotion_rule.preferred_path
21
- promotion.promotion_rules.delete promotion_rule
22
- promotion.save(:validate => false)
23
- end
24
- end
25
-
26
- def down
27
- remove_column :spree_activators, :path
28
- end
29
- end