From 003ed11c146dda7111dd91319c031d1ab0eb60b1 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sat, 17 Mar 2012 14:43:08 +0100 Subject: [PATCH] dhllabel: Add support to generate DHL CSV files to be uploaded This allows to download a CSV file that can be uploaded to DHL.de. This should kill the need to copy and paste shipping labels. --- .../admin/shipments_controller_decorator.rb | 11 +++++++++++ app/views/admin/dhls/_address_label.html.erb | 5 +++++ app/views/admin/shipments/dhllabel.text.erb | 2 ++ config/locales/en.yml | 1 + config/routes.rb | 10 ++++++++++ lib/sysmocom_dhl_hooks.rb | 3 +++ 6 files changed, 32 insertions(+) create mode 100644 app/controllers/admin/shipments_controller_decorator.rb create mode 100644 app/views/admin/dhls/_address_label.html.erb create mode 100644 app/views/admin/shipments/dhllabel.text.erb diff --git a/app/controllers/admin/shipments_controller_decorator.rb b/app/controllers/admin/shipments_controller_decorator.rb new file mode 100644 index 0000000..8f863ec --- /dev/null +++ b/app/controllers/admin/shipments_controller_decorator.rb @@ -0,0 +1,11 @@ +Admin::ShipmentsController.class_eval do + def dhllabel + load_shipment + name = '%s_dhllabel.csv' % [@order.number] + headers["Content-type"] = "text/plain" + headers["Cache-Control"] = "no-cache, max-age=0, must-revalidate" + headers["Pragma"] = "no-cache" + headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT" + headers["Content-Disposition"] = "attachment; filename=\"%s\"" % name + end +end diff --git a/app/views/admin/dhls/_address_label.html.erb b/app/views/admin/dhls/_address_label.html.erb new file mode 100644 index 0000000..b190e7e --- /dev/null +++ b/app/views/admin/dhls/_address_label.html.erb @@ -0,0 +1,5 @@ +<% if @shipment.can_ship? %> +
  • + <%= button_link_to t(:dhl_label), dhllabel_admin_order_shipment_url(:format => :txt)%> +
  • +<% end %> diff --git a/app/views/admin/shipments/dhllabel.text.erb b/app/views/admin/shipments/dhllabel.text.erb new file mode 100644 index 0000000..c4e69b1 --- /dev/null +++ b/app/views/admin/shipments/dhllabel.text.erb @@ -0,0 +1,2 @@ +SEND_NAME1,SEND_NAME2,SEND_STREET,SEND_HOUSENUMBER,SEND_PLZ,SEND_CITY,SEND_COUNTRY,RECV_NAME1,RECV_NAME2,RECV_STREET,RECV_HOUSENUMBER,RECV_PLZ,RECV_CITY,RECV_COUNTRY,PRODUCT,COUPON +"sysmocom - s.f.m.c GmbH","Holger Freyther","Schivelbeinerstr.","5","10439","Berlin","DEU","<%= @shipment.address.firstname %> <%= @shipment.address.lastname %>","<%= @shipment.address.address2 %>","<%= @shipment.address.address1 %>","","<%= @shipment.address.zipcode %>","<%= @shipment.address.city %>","<%= @shipment.address.country.iso3 %>","","" diff --git a/config/locales/en.yml b/config/locales/en.yml index 56f6670..38206c1 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,4 +1,5 @@ --- en: dhl: DHL + dhl_label: "DHL Label (CSV)" dhls: DHL diff --git a/config/routes.rb b/config/routes.rb index 056be06..0e02d23 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,7 +4,17 @@ Rails.application.routes.draw do resources :dhls do resources :coupons end + + # Add access to the dhllabel function + resources :orders do + resources :shipments do + member do + get :dhllabel + end + end + end end + match "/admin/dhl" => 'admin/dhls#index', :as => :admin end diff --git a/lib/sysmocom_dhl_hooks.rb b/lib/sysmocom_dhl_hooks.rb index 59a1a74..1327fab 100644 --- a/lib/sysmocom_dhl_hooks.rb +++ b/lib/sysmocom_dhl_hooks.rb @@ -3,4 +3,7 @@ class SysmocomDhlHooks < Spree::ThemeSupport::HookListener insert_after :admin_tabs do "<%= tab(:dhls) %>" end + + # Add the DHL label download + insert_after :admin_shipment_edit_buttons, 'admin/dhls/address_label' end