-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrussian_adaptation_extension.rb
103 lines (84 loc) · 3.13 KB
/
russian_adaptation_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# encoding: utf-8
# Uncomment this if you reference any of your controllers in activate
# require_dependency 'application'
class RussianAdaptationExtension < Spree::Extension
version "0.2"
description "Adapts Spree to the Russian reality."
url "http://github.com/romul/spree-russian-adaptation"
# Please use russian_adaptation/config/routes.rb instead for extension routes.
def self.require_gems(config)
config.gem 'russian', :lib => 'russian', :source => 'http://gemcutter.org'
config.gem 'prawn'
end
def activate
Time::DATE_FORMATS[:date_time24] = "%d.%m.%Y - %H:%M"
Time::DATE_FORMATS[:short_date] = "%d.%m.%Y"
require "active_merchant/billing/gateways/robo_kassa"
Gateway::RoboKassa.register
# replace .to_url method provided by stringx gem by .parameterize provided by russian gem
String.class_eval do
def to_url
self.parameterize
end
end
OrdersController.class_eval do
def sberbank_billing
if (@order.shipping_method.name =~ /предопл/ && can_access?)
render :layout => false
else
flash[:notice] = 'Счёт не найден.'
redirect_to root_path
end
end
end
Gateway.class_eval do
def self.current
self.first :conditions => ["environment = ? AND active = ?", RAILS_ENV, true]
end
end
Checkout.class_eval do
validation_group :address, :fields=> [
"ship_address.firstname", "ship_address.lastname", "ship_address.phone",
"ship_address.zipcode", "ship_address.state", "ship_address.lastname",
"ship_address.address1", "ship_address.city", "ship_address.statename",
"ship_address.zipcode", "ship_address.secondname"]
def bill_address
ship_address || Address.default
end
end
Checkout.state_machines[:state] =
StateMachine::Machine.new(Checkout, :initial => 'address') do
after_transition :to => 'complete', :do => :complete_order
event :next do
transition :to => 'delivery', :from => 'address'
transition :to => 'complete', :from => 'delivery'
end
end
ActionView::Helpers::NumberHelper.module_eval do
def number_to_currency(number, options = {})
rub = number.to_i
kop = ((number - rub)*100).round.to_i
if (kop > 0)
"#{rub} #{RUSSIAN_CONFIG['country']['currency']} #{'%.2d' % kop} коп.".mb_chars
else
"#{rub} #{RUSSIAN_CONFIG['country']['currency']}".mb_chars
end
end
end
Admin::BaseHelper.module_eval do
def text_area(object_name, method, options = {})
begin
ckeditor_textarea(object_name, method, :width => '100%', :height => '350px')
rescue
super
end
end
end
Admin::OrdersController.class_eval do
show.success.wants.pdf { render :layout => false, :template => 'admin/orders/show.pdf.prawn'}
end
AppConfiguration.class_eval do
preference :print_invoice_logo_path, :string, :default => '/images/admin/bg/spree_50.png'
end
end
end