Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Inicio projeto

  • Loading branch information...
commit d52b6689e5a1785350e5c99c8e357d1b76509241 0 parents
vintem authored
2  .bundle/config
@@ -0,0 +1,2 @@
+---
+BUNDLE_DISABLE_SHARED_GEMS: "1"
9 .gitignore
@@ -0,0 +1,9 @@
+\#*
+*~
+.#*
+.DS_Store
+.idea
+.project
+tmp
+nbproject
+*.swp
3  Gemfile
@@ -0,0 +1,3 @@
+source 'http://rubygems.org'
+
+gem 'correios-frete'
33 Gemfile.lock
@@ -0,0 +1,33 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ correios-frete (0.1.0)
+ bundler (~> 1.0.0)
+ jeweler
+ nokogiri
+ rspec
+ sax-machine
+ diff-lcs (1.1.2)
+ git (1.2.5)
+ jeweler (1.6.4)
+ bundler (~> 1.0)
+ git (>= 1.2.5)
+ rake
+ nokogiri (1.5.0)
+ rake (0.9.2)
+ rspec (2.6.0)
+ rspec-core (~> 2.6.0)
+ rspec-expectations (~> 2.6.0)
+ rspec-mocks (~> 2.6.0)
+ rspec-core (2.6.4)
+ rspec-expectations (2.6.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.6.0)
+ sax-machine (0.0.16)
+ nokogiri (> 0.0.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ correios-frete
23 LICENSE
@@ -0,0 +1,23 @@
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of the Rails Dog LLC nor the names of its
+ contributors may be used to endorse or promote products derived from this
+ software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13 README.md
@@ -0,0 +1,13 @@
+SpreeCorreiosShipping
+=====================
+
+Introduction goes here.
+
+
+Example
+=======
+
+Example goes here.
+
+
+Copyright (c) 2011 [name of extension creator], released under the New BSD License
75 Rakefile
@@ -0,0 +1,75 @@
+require 'rubygems'
+require 'rake'
+require 'rake/testtask'
+require 'rake/packagetask'
+require 'rake/gempackagetask'
+
+gemfile = File.expand_path('../spec/test_app/Gemfile', __FILE__)
+if File.exists?(gemfile) && (%w(spec cucumber).include?(ARGV.first.to_s) || ARGV.size == 0)
+ require 'bundler'
+ ENV['BUNDLE_GEMFILE'] = gemfile
+ Bundler.setup
+
+ require 'rspec'
+ require 'rspec/core/rake_task'
+ RSpec::Core::RakeTask.new
+
+ require 'cucumber/rake/task'
+ Cucumber::Rake::Task.new do |t|
+ t.cucumber_opts = %w{--format progress}
+ end
+end
+
+desc "Default Task"
+task :default => [:spec, :cucumber ]
+
+spec = eval(File.read('spree_correios_shipping.gemspec'))
+
+Rake::GemPackageTask.new(spec) do |p|
+ p.gem_spec = spec
+end
+
+desc "Release to gemcutter"
+task :release => :package do
+ require 'rake/gemcutter'
+ Rake::Gemcutter::Tasks.new(spec).define
+ Rake::Task['gem:push'].invoke
+end
+
+desc "Default Task"
+task :default => [ :spec ]
+
+desc "Regenerates a rails 3 app for testing"
+task :test_app do
+ require '../spree/lib/generators/spree/test_app_generator'
+ class SpreeCorreiosShippingTestAppGenerator < Spree::Generators::TestAppGenerator
+
+ def install_gems
+ inside "test_app" do
+ run 'bundle exec rake spree_core:install'
+ run 'bundle exec rake spree_correios_shipping:install'
+ end
+ end
+
+ def migrate_db
+ run_migrations
+ end
+
+ protected
+ def full_path_for_local_gems
+ <<-gems
+gem 'spree_core', :path => \'#{File.join(File.dirname(__FILE__), "../spree/", "core")}\'
+gem 'spree_correios_shipping', :path => \'#{File.dirname(__FILE__)}\'
+ gems
+ end
+
+ end
+ SpreeCorreiosShippingTestAppGenerator.start
+end
+
+namespace :test_app do
+ desc 'Rebuild test and cucumber databases'
+ task :rebuild_dbs do
+ system("cd spec/test_app && bundle exec rake db:drop db:migrate RAILS_ENV=test && rake db:drop db:migrate RAILS_ENV=cucumber")
+ end
+end
9 Versionfile
@@ -0,0 +1,9 @@
+# This file is used to designate compatibilty with different versions of Spree
+# Please see http://spreecommerce.com/documentation/extensions.html#versionfile for details
+
+# Examples
+#
+# "0.50.x" => { :branch => "master" }
+# "0.40.x" => { :tag => "v1.0.0", :version => "1.0.0" }
+
+
42 app/models/sedex_calculator.rb
@@ -0,0 +1,42 @@
+require 'correios-frete'
+
+class SedexCalculator < Calculator
+ preference :zipcode, :string
+ preference :default_weight, :float, :default => 1
+
+ def self.description
+ 'Sedex'
+ end
+
+ def self.register
+ super
+ ShippingMethod.register_calculator(self)
+ end
+
+ def compute(order)
+
+ total_price , total_weight , shipping = 0 , 0 , 0
+
+ order.line_items.each do |item|
+ total_weight += item.quantity * (item.variant.weight || self.preferred_default_weight)
+ total_price += item.price * item.quantity
+ end
+
+ return 0 if total_weight == 0
+
+ logger.debug "------ Calculando sedex----------"
+ logger.debug "Peso total: #{total_weight}"
+ logger.debug "Cep origem: #{preferred_zipcode}"
+ logger.debug "Cep destino: #{order.ship_address.zipcode.to_s}"
+ frete = Correios::Frete.new :cep_origem => preferred_zipcode,
+ :cep_destino => order.ship_address.zipcode.to_s,
+ :peso => total_weight,
+ :comprimento => 30,
+ :largura => 15,
+ :altura => 2
+
+ servico = frete.calcular :sedex
+ servico.valor
+ end
+
+end
3  config/routes.rb
@@ -0,0 +1,3 @@
+Rails.application.routes.draw do
+ # Add your extension routes here
+end
27 lib/spree_correios_shipping.rb
@@ -0,0 +1,27 @@
+require 'spree_core'
+require 'spree_correios_shipping_hooks'
+
+module SpreeCorreiosShipping
+ class Engine < Rails::Engine
+
+ config.autoload_paths += %W(#{config.root}/lib)
+
+ def self.activate
+ Dir.glob(File.join(File.dirname(__FILE__), "../app/models/calculator/**/*.rb")) do |c|
+ Rails.env.production? ? require(c) : load(c)
+ end
+
+ Dir.glob(File.join(File.dirname(__FILE__), "spree/**/*.rb")) do |c|
+ Rails.env.production? ? require(c) : load(c)
+ end
+
+ [SedexCalculator].each(&:register)
+
+ Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
+ Rails.env.production? ? require(c) : load(c)
+ end
+ end
+
+ config.to_prepare &method(:activate).to_proc
+ end
+end
3  lib/spree_correios_shipping_hooks.rb
@@ -0,0 +1,3 @@
+class SpreeCorreiosShippingHooks < Spree::ThemeSupport::HookListener
+ # custom hooks go here
+end
25 lib/tasks/install.rake
@@ -0,0 +1,25 @@
+namespace :spree_correios_shipping do
+ desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
+ task :install do
+ Rake::Task['spree_correios_shipping:install:migrations'].invoke
+ Rake::Task['spree_correios_shipping:install:assets'].invoke
+ end
+
+ namespace :install do
+ desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
+ task :migrations do
+ source = File.join(File.dirname(__FILE__), '..', '..', 'db')
+ destination = File.join(Rails.root, 'db')
+ Spree::FileUtilz.mirror_files(source, destination)
+ end
+
+ desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
+ task :assets do
+ source = File.join(File.dirname(__FILE__), '..', '..', 'public')
+ destination = File.join(Rails.root, 'public')
+ puts "INFO: Mirroring assets from #{source} to #{destination}"
+ Spree::FileUtilz.mirror_files(source, destination)
+ end
+ end
+
+end
1  lib/tasks/spree_correios_shipping.rake
@@ -0,0 +1 @@
+# add custom rake tasks here
30 spec/spec_helper.rb
@@ -0,0 +1,30 @@
+# This file is copied to ~/spec when you run 'ruby script/generate rspec'
+# from the project root directory.
+ENV["RAILS_ENV"] ||= 'test'
+require File.expand_path("../test_app/config/environment", __FILE__)
+require 'rspec/rails'
+
+# Requires supporting files with custom matchers and macros, etc,
+# in ./support/ and its subdirectories.
+Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
+
+RSpec.configure do |config|
+ # == Mock Framework
+ #
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
+ #
+ # config.mock_with :mocha
+ # config.mock_with :flexmock
+ # config.mock_with :rr
+ config.mock_with :rspec
+
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
+
+ #config.include Devise::TestHelpers, :type => :controller
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
+ # examples within a transaction, comment the following line or assign false
+ # instead of true.
+ config.use_transactional_fixtures = true
+end
+
+@configuration ||= AppConfiguration.find_or_create_by_name("Default configuration")
21 spree_correios_shipping.gemspec
@@ -0,0 +1,21 @@
+Gem::Specification.new do |s|
+ s.platform = Gem::Platform::RUBY
+ s.name = 'spree_correios_shipping'
+ s.version = '0.60.1'
+ s.summary = 'Add gem summary here'
+ s.description = 'Add (optional) gem description here'
+ s.required_ruby_version = '>= 1.8.7'
+
+ s.author = 'Thiago Temple'
+ s.email = 'vintem@gmail.com'
+ # s.homepage = 'http://www.rubyonrails.org'
+ # s.rubyforge_project = 'actionmailer'
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.require_path = 'lib'
+ s.requirements << 'none'
+
+ s.add_dependency('spree_core', '>= 0.60.1')
+ s.add_dependency('correios-frete')
+end
Please sign in to comment.
Something went wrong with that request. Please try again.