forked from swistak/spree-promotions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpromotions_extension.rb
59 lines (47 loc) · 2.1 KB
/
promotions_extension.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Uncomment this if you reference any of your controllers in activate
# require_dependency 'application'
class PromotionsExtension < Spree::Extension
version "1.0"
description "Describe your extension here"
url "http://yourwebsite.com/promotions"
# Please use promotions/config/routes.rb instead for extension routes.
# def self.require_gems(config)
# config.gem "gemname-goes-here", :version => '1.2.3'
# end
def activate
base = File.dirname(__FILE__)
Dir.glob(File.join(base, "app/**/*_decorator*.rb")){|c| load(c)}
FileUtils.cp Dir.glob(File.join(base, "public/stylesheets/*.css")), File.join(RAILS_ROOT, "public/stylesheets/")
FileUtils.cp Dir.glob(File.join(base, "public/javascripts/*.js")), File.join(RAILS_ROOT, "public/javascripts")
if ProductPromotion.table_exists?
[Calculator::CheapestFree, Calculator::FreeShipping, Calculator::NAndMoreProducts, Calculator::NoCharge, Calculator::NthFree].each do |calculator|
calculator.register(ProductPromotion)
end
UserPromotion.register_calculator(Calculator::FlatPercentItemTotal)
PromotionOrderObserver.instance
end
::Adjustment
::Credit
::PromotionCredit
::ProductPromotion
# Add your extension tab to the admin.
# Requires that you have defined an admin controller:
# app/controllers/admin/yourextension_controller
# and that you mapped your admin in config/routes
Admin::BaseController.class_eval do
before_filter :add_promotions_tab
def add_promotions_tab
# add_extension_admin_tab takes an array containing the same arguments expected
# by the tab helper method:
# [ :extension_name, { :label => "Your Extension", :route => "/some/non/standard/route" } ]
add_extension_admin_tab([:promotions, :product_promotions, :user_promotions, :coupons]) rescue NameError
end
end
[ProductsController, Spree::BaseController].each{|c| c.helper 'promotions'}
Rails.cache.silence!
# make your helper avaliable in all views
# Spree::BaseController.class_eval do
# helper YourHelper
# end
end
end