Browse Source

Upgrade the extension to work with Spree 1.2

* Now that we need to pass the shipment..
* We need to copy the shipped_email text..
1-2-stable-sysmocom
Holger Hans Peter Freyther 9 years ago
parent
commit
833e597cda
  1. 1
      app/assets/javascripts/admin/spree_test.js
  2. 1
      app/assets/javascripts/store/spree_test.js
  3. 3
      app/assets/stylesheets/admin/spree_test.css
  4. 3
      app/assets/stylesheets/store/spree_test.css
  5. 3
      app/controllers/admin/dhls_controller.rb
  6. 5
      app/controllers/spree/admin/dhls_controller.rb
  7. 9
      app/controllers/spree/admin/shipments_controller_decorator.rb
  8. 3
      app/controllers/spree/shipping_method_controller_decorator.rb
  9. 20
      app/overrides/dhl_links.rb
  10. 0
      app/views/spree/admin/dhls/_address_label.html.erb
  11. 0
      app/views/spree/admin/dhls/_method_details_form.html.erb
  12. 0
      app/views/spree/admin/dhls/index.html.erb
  13. 0
      app/views/spree/admin/shipments/dhllabel.text.erb
  14. 0
      app/views/spree/shipment_mailer/dhls/_tracking_description.text.erb
  15. 18
      app/views/spree/shipment_mailer/shipped_email.text.erb
  16. 2
      config/routes.rb
  17. 29
      lib/generators/sysmocom_dhl/install/install_generator.rb
  18. 18
      lib/sysmocom_dhl.rb
  19. 22
      lib/sysmocom_dhl/engine.rb
  20. 13
      lib/sysmocom_dhl_hooks.rb
  21. 25
      lib/tasks/install.rake
  22. 1
      lib/tasks/sysmocom_dhl.rake
  23. 6
      sysmocom_dhl.gemspec

1
app/assets/javascripts/admin/spree_test.js

@ -0,0 +1 @@
//= require admin/spree_core

1
app/assets/javascripts/store/spree_test.js

@ -0,0 +1 @@
//= require store/spree_core

3
app/assets/stylesheets/admin/spree_test.css

@ -0,0 +1,3 @@
/*
*= require admin/spree_core
*/

3
app/assets/stylesheets/store/spree_test.css

@ -0,0 +1,3 @@
/*
*= require store/spree_core
*/

3
app/controllers/admin/dhls_controller.rb

@ -1,3 +0,0 @@
class Admin::DhlsController < Admin::BaseController
respond_to :html
end

5
app/controllers/spree/admin/dhls_controller.rb

@ -0,0 +1,5 @@
class Spree::Admin::DhlsController < Spree::Admin::BaseController
respond_to :html
end
puts("LOADED\n");

9
app/controllers/admin/shipments_controller_decorator.rb → app/controllers/spree/admin/shipments_controller_decorator.rb

@ -1,7 +1,6 @@
Admin::ShipmentsController.class_eval do
Spree::Admin::ShipmentsController.class_eval do
def dhllabel
load_shipment
name = '%s_dhllabel.csv' % [@order.number]
name = '%s_dhllabel.csv' % [order.number]
headers["Content-type"] = "text/plain; charset=iso-8859-15"
headers["Cache-Control"] = "no-cache, max-age=0, must-revalidate"
headers["Pragma"] = "no-cache"
@ -9,8 +8,8 @@ Admin::ShipmentsController.class_eval do
headers["Content-Disposition"] = "attachment; filename=\"%s\"" % name
# Try hard to render it as latin1
res = render
res = render :locals => { :shipment => shipment }
response.charset = 'iso-8859-15'
response.body = Iconv.conv('iso-8859-15', 'utf-8', res)
response.body = Iconv.conv('iso-8859-15', 'utf-8', res[0])
end
end

3
app/controllers/spree/shipping_method_controller_decorator.rb

@ -0,0 +1,3 @@
Spree::ShippingMethod.class_eval do
attr_accessible :method_details
end

20
app/overrides/dhl_links.rb

@ -0,0 +1,20 @@
Deface::Override.new(:virtual_path => "spree/layouts/admin",
:name => "dhl_admin_tabs",
:insert_bottom => "[data-hook='admin_tabs'], #admin_tabs[data-hook]",
:text => "<%= tab(:dhls, :url => spree.admin_dhls_path) %>",
:disabled => false,
:original => 'b06db401e133fa2491f542e73196e0bb79a4ca05')
Deface::Override.new(:virtual_path => "spree/admin/shipments/edit",
:name => "dhl_label",
:insert_bottom => "[data-hook='admin_shipment_edit_buttons']",
:partial => 'spree/admin/dhls/address_label',
:original => 'e5254ea08fdafd6dfaf37a2631fdc384f0a4a3ae')
Deface::Override.new(:virtual_path => "spree/admin/shipping_methods/_form",
:name => 'dhl_shipment_method',
:insert_bottom => "[data-hook='admin_shipping_method_form_fields']",
:partial => 'spree/admin/dhls/method_details_form')
# This doesn't work with the shipment mailer..

0
app/views/admin/dhls/_address_label.html.erb → app/views/spree/admin/dhls/_address_label.html.erb

0
app/views/admin/dhls/_method_details_form.html.erb → app/views/spree/admin/dhls/_method_details_form.html.erb

0
app/views/admin/dhls/index.html.erb → app/views/spree/admin/dhls/index.html.erb

0
app/views/admin/shipments/dhllabel.text.erb → app/views/spree/admin/shipments/dhllabel.text.erb

0
app/views/shipment_mailer/dhls/_tracking_description.text.erb → app/views/spree/shipment_mailer/dhls/_tracking_description.text.erb

18
app/views/spree/shipment_mailer/shipped_email.text.erb

@ -0,0 +1,18 @@
<%= t('shipment_mailer.shipped_email.dear_customer') %>
<%= t('shipment_mailer.shipped_email.instructions') %>
============================================================
<%= t('shipment_mailer.shipped_email.shipment_summary') %>
============================================================
<% @shipment.manifest.each do |item| %>
<%= item.variant.sku %> <%= item.variant.product.name %> <%= item.variant.options_text %>
<% end %>
============================================================
<%= t('shipment_mailer.shipped_email.track_information', :tracking => @shipment.tracking) if @shipment.tracking %>
<%= render :partial => 'spree/shipment_mailer/dhls/tracking_description' %>
<%= t('shipment_mailer.shipped_email.thanks') %>

2
config/routes.rb

@ -1,4 +1,4 @@
Rails.application.routes.draw do
Spree::Core::Engine.routes.draw do
# Add your extension routes here
namespace :admin do
resources :dhls do

29
lib/generators/sysmocom_dhl/install/install_generator.rb

@ -0,0 +1,29 @@
module SysmocomDhl
module Generators
class InstallGenerator < Rails::Generators::Base
def add_javascripts
append_file 'app/assets/javascripts/store/all.js', "//= require store/sysmocom_dhl\n"
append_file 'app/assets/javascripts/admin/all.js', "//= require admin/sysmocom_dhl\n"
end
def add_stylesheets
inject_into_file 'app/assets/stylesheets/store/all.css', " *= require store/sysmocom_dhl\n", :before => /\*\//, :verbose => true
inject_into_file 'app/assets/stylesheets/admin/all.css', " *= require admin/sysmocom_dhl\n", :before => /\*\//, :verbose => true
end
def add_migrations
run 'bundle exec rake railties:install:migrations FROM=sysmocom_dhl'
end
def run_migrations
res = ask 'Would you like to run the migrations now? [Y/n]'
if res == '' || res.downcase == 'y'
run 'bundle exec rake db:migrate'
else
puts 'Skipping rake db:migrate, don\'t forget to run it!'
end
end
end
end
end

18
lib/sysmocom_dhl.rb

@ -1,17 +1,3 @@
require 'spree_core'
require 'sysmocom_dhl_hooks'
module SysmocomDhl
class Engine < Rails::Engine
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
end
config.to_prepare &method(:activate).to_proc
end
end
require 'sysmocom_dhl/engine'
require 'iconv'

22
lib/sysmocom_dhl/engine.rb

@ -0,0 +1,22 @@
module SpreeTest
class Engine < Rails::Engine
require 'spree/core'
isolate_namespace Spree
engine_name 'sysmocom_dhl'
config.autoload_paths += %W(#{config.root}/lib)
# use rspec for tests
config.generators do |g|
g.test_framework :rspec
end
def self.activate
Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end
end
config.to_prepare &method(:activate).to_proc
end
end

13
lib/sysmocom_dhl_hooks.rb

@ -1,13 +0,0 @@
class SysmocomDhlHooks < Spree::ThemeSupport::HookListener
# custom hooks go here
insert_after :admin_tabs do
"<%= tab(:dhls) %>"
end
# Add the DHL label download
insert_after :admin_shipment_edit_buttons, 'admin/dhls/address_label'
# Add shipment identification..
insert_after :shipment_mailer_shipped_email_tracking, 'shipment_mailer/dhls/tracking_description'
insert_after :admin_shipping_method_form_fields, 'admin/dhls/method_details_form'
end

25
lib/tasks/install.rake

@ -1,25 +0,0 @@
namespace :sysmocom_dhl do
desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
task :install do
Rake::Task['sysmocom_dhl:install:migrations'].invoke
Rake::Task['sysmocom_dhl: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/sysmocom_dhl.rake

@ -1 +0,0 @@
# add custom rake tasks here

6
sysmocom_dhl.gemspec

@ -1,10 +1,10 @@
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = 'sysmocom_dhl'
s.version = '0.60.1'
s.version = '1.2.0'
s.summary = 'sysmocom_dhl shipping helper'
s.description = 'Deal with shipping cost, zones, insurance'
s.required_ruby_version = '>= 1.8.7'
s.required_ruby_version = '>= 1.9.1'
# s.author = 'David Heinemeier Hansson'
# s.email = 'david@loudthinking.com'
@ -16,5 +16,5 @@ Gem::Specification.new do |s|
s.require_path = 'lib'
s.requirements << 'none'
s.add_dependency('spree_core', '>= 0.60.1')
s.add_dependency('spree_core', '>= 1.2.0')
end

Loading…
Cancel
Save