Skip to content

Commit

Permalink
rails g synergy:install works
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Pirozhkov committed Apr 14, 2012
1 parent c38d1f7 commit dc77711
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 91 deletions.
90 changes: 1 addition & 89 deletions lib/spree/synergy.rb
@@ -1,89 +1 @@
# coding: utf-8
# require 'spree_core'
# require 'spree_auth'
# require 'spree_api'
# require 'spree_dash'
# require 'spree_promo'
# require 'spree_i18n'
# require 'russian'
# require 'ru_propisju'

require 'ext/number_helper'

module Spree
module Synergy
class Engine < Rails::Engine
engine_name 'synergy'

config.autoload_paths += %W(#{config.root}/lib)

def self.activate
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
Rails.env.production? ? require(c) : load(c)
end

Time::DATE_FORMATS[:default] = "%d.%m.%Y - %H:%M"
Date::DATE_FORMATS[:default] = "%d.%m.%Y"

Time.zone = "Moscow"
I18n.default_locale = :ru

if Spree::Config.instance
Spree::Config.set(:default_locale => :ru)
Spree::Config.set(:default_country_id => 168)
Spree::Config.set(:allow_ssl_in_production => false)
Spree::Config.set(:disable_bill_address => true)
Spree::Config.set(:admin_interface_logo => "admin/logo.png")
checkout_zone = Zone.first
Spree::Config.set(:checkout_zone => checkout_zone.name) if checkout_zone
# store email address
Spree::Config.set(:store_email => 'test@site.ru') unless Spree::Config[:store_email]
# store phone
Spree::Config.set(:store_phone => '+7 (495) 1234567') unless Spree::Config[:store_phone]
# store address
#Spree::Config.set(:store_address => 'Somewhere st. Nowhere')
end

::ADDRESS_FIELDS.clear << ["lastname", "firstname", "secondname", "country", "state", "city", "zipcode", "address1", "phone"]
::ADDRESS_FIELDS.flatten!

String.class_eval do
def to_url
self.parameterize
end
end


# добавить событие для перехода от шага доставки к шагу подтверждения, минуя шаг оплаты
confirm_event = StateMachine::Event.new(Order.state_machine, :confirm_without_payment)
confirm_event.transition :to => 'confirm'
Order.state_machine.events << confirm_event

# переопределение события :next для отображения шага подтверждения в любом случае
next_event = StateMachine::Event.new(Order.state_machine, :next)
next_event.transition :from => 'cart', :to => 'address'
next_event.transition :from => 'address', :to => 'delivery'
next_event.transition :from => 'delivery', :to => 'payment'
next_event.transition :from => 'payment', :to => 'confirm'
next_event.transition :from => 'confirm', :to => 'complete'
Order.state_machine.events << next_event
end

config.to_prepare &method(:activate).to_proc

initializer "spree.register.calculators" do |app|
app.config.spree.calculators.shipping_methods = [
Spree::Calculator::Juridical
]
end

initializer "spree.register.payment_methods" do |app|
app.config.spree.payment_methods = [
Spree::Gateway::Bogus,
Spree::PaymentMethod::SberBankInvoice,
Spree::PaymentMethod::JuridicalInvoice
]
end
end
end
end
require 'spree/synergy/engine'
75 changes: 75 additions & 0 deletions lib/spree/synergy/engine.rb
@@ -0,0 +1,75 @@
# coding: utf-8

# require 'spree_core'
# require 'spree_auth'
# require 'spree_api'
# require 'spree_dash'
# require 'spree_promo'
# require 'spree_i18n'
# require 'russian'
# require 'ru_propisju'

require 'ext/number_helper'

module Spree
module Synergy
class Engine < Rails::Engine
engine_name 'synergy'

config.autoload_paths += %W(#{config.root}/lib)

def self.activate
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
Rails.env.production? ? require(c) : load(c)
end

Time::DATE_FORMATS[:default] = "%d.%m.%Y - %H:%M"
Date::DATE_FORMATS[:default] = "%d.%m.%Y"

Time.zone = "Europe/Moscow"
I18n.default_locale = :ru

Spree::Config.set(:default_locale => :ru)
Spree::Config.set(:default_country_id => 168)
# Spree::Config.set(:allow_ssl_in_production => false)
# Spree::Config.set(:disable_bill_address => true)
# Spree::Config.set(:admin_interface_logo => "admin/logo.png")
# checkout_zone = Zone.first
# Spree::Config.set(:checkout_zone => checkout_zone.name) if checkout_zone

# ::ADDRESS_FIELDS.clear << ["lastname", "firstname", "secondname", "country", "state", "city", "zipcode", "address1", "phone"]
# ::ADDRESS_FIELDS.flatten!

# # добавить событие для перехода от шага доставки к шагу подтверждения, минуя шаг оплаты
# confirm_event = StateMachine::Event.new(Order.state_machine, :confirm_without_payment)
# confirm_event.transition :to => 'confirm'
# Order.state_machine.events << confirm_event

# # переопределение события :next для отображения шага подтверждения в любом случае
# next_event = StateMachine::Event.new(Order.state_machine, :next)
# next_event.transition :from => 'cart', :to => 'address'
# next_event.transition :from => 'address', :to => 'delivery'
# next_event.transition :from => 'delivery', :to => 'payment'
# next_event.transition :from => 'payment', :to => 'confirm'
# next_event.transition :from => 'confirm', :to => 'complete'
# Order.state_machine.events << next_event
end

config.to_prepare &method(:activate).to_proc

initializer "spree.register.calculators" do |app|
app.config.spree.calculators.shipping_methods = [
Spree::Calculator::Juridical
]
end

initializer "spree.register.payment_methods" do |app|
app.config.spree.payment_methods = [
Spree::Gateway::Bogus,
Spree::PaymentMethod::SberBankInvoice,
Spree::PaymentMethod::JuridicalInvoice
]
end
end
end
end
6 changes: 6 additions & 0 deletions lib/spree/synergy_configuration.rb
Expand Up @@ -18,4 +18,10 @@ class SynergyConfiguration < Preferences::Configuration
preference :director, :string
preference :accountant, :string
end

AppConfiguration.class_eval do
preference :store_email, :string, :default => 'test@site.ru'
preference :store_phone, :string, :default => '+7 (495) 1234567'
preference :store_address, :string, :default => 'Somewhere st. Nowhere'
end
end
2 changes: 2 additions & 0 deletions lib/synergy.rb
@@ -0,0 +1,2 @@
require 'spree_core'
require 'spree/synergy'
4 changes: 2 additions & 2 deletions synergy.gemspec
Expand Up @@ -15,10 +15,10 @@ Gem::Specification.new do |s|
s.require_path = 'lib'
s.requirements << 'none'

s.add_dependency('synergy_russian', '0.2.8')
s.add_dependency 'synergy_russian', '0.2.8'
#s.add_dependency('json', '>= 1.5')
#s.add_dependency('nokogiri', '~> 1.5')
s.add_dependency('spree', '~> 1.0')
s.add_dependency 'spree', '~> 1.0'
#s.add_dependency('spree_static_content', '~> 0.70.0')
#s.add_dependency('spree_editor', '~> 1.0')
#s.add_dependency('spree_robokassa', '~> 0.50.2')
Expand Down

0 comments on commit dc77711

Please sign in to comment.