spree_elta_courier 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.md +10 -0
- data/README.md +75 -0
- data/Rakefile +21 -0
- data/app/assets/config/spree_elta_courier_manifest.js +3 -0
- data/app/assets/images/integration_icons/elta-courier-logo.png +0 -0
- data/app/controllers/spree/admin/elta_courier_controller.rb +91 -0
- data/app/javascript/spree_elta_courier/application.js +12 -0
- data/app/lib/elta_courier/soap_client.rb +72 -0
- data/app/models/spree/integrations/elta_courier.rb +25 -0
- data/app/models/spree/order_decorator.rb +13 -0
- data/app/models/spree/shipment_decorator.rb +13 -0
- data/app/services/spree_elta_courier/create_voucher.rb +42 -0
- data/app/services/spree_elta_courier/print_vouchers.rb +35 -0
- data/app/views/spree/admin/integrations/forms/_elta_courier.html.erb +16 -0
- data/app/views/spree_elta_courier/_head.html.erb +1 -0
- data/app/views/spree_elta_courier/_order_dropdown_options.html.erb +19 -0
- data/config/importmap.rb +6 -0
- data/config/initializers/spree.rb +9 -0
- data/config/locales/el.yml +18 -0
- data/config/locales/en.yml +18 -0
- data/config/routes.rb +6 -0
- data/lib/generators/spree_elta_courier/install/install_generator.rb +20 -0
- data/lib/spree_elta_courier/configuration.rb +13 -0
- data/lib/spree_elta_courier/engine.rb +39 -0
- data/lib/spree_elta_courier/factories.rb +3 -0
- data/lib/spree_elta_courier/testing_support/factories/elta_courier_integration.rb +10 -0
- data/lib/spree_elta_courier/version.rb +7 -0
- data/lib/spree_elta_courier/wsdl/CREATEAWB02.wsdl +107 -0
- data/lib/spree_elta_courier/wsdl/ELTACOURIERPOSTSIDETA.wsdl +125 -0
- data/lib/spree_elta_courier/wsdl/GETPUDODETAILS.wsdl +81 -0
- data/lib/spree_elta_courier/wsdl/PELB64VG.wsdl +60 -0
- data/lib/spree_elta_courier/wsdl/PELTT03.wsdl +75 -0
- data/lib/spree_elta_courier.rb +11 -0
- metadata +190 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: '0138c167e19a827d9eda2caef4333702930eb2d1f436b6a7f9755bb83b9a79d6'
|
|
4
|
+
data.tar.gz: 6aaf7177fb8045fb654cb47282a148baab634bb6d541a8731561bd52dcbf252d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: eaa5dfcba4320663fd8f21880aaa667e754fc5e56ebcbb242a430a77eafda2df4a75afc83dfa0a5ce83085ddfb23dddc32a57cc189c1cde146c02d51c7cca29d
|
|
7
|
+
data.tar.gz: 8bef0689177ce154d5c51aeda6f245349707632258e09596572cf019d468d70df14f99db56d41788ce4c2ba4eac414ab9734c5c33b7a6b049dee8a4dca643806
|
data/LICENSE.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 OlympusOne
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
10
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Spree Elta Courier
|
|
2
|
+
|
|
3
|
+
This is a Elta Courier extension for [Spree Commerce](https://spreecommerce.org), an open source e-commerce platform built with Ruby on Rails. Adds the ability to manage Elta Courier vouchers to Spree stores.
|
|
4
|
+
|
|
5
|
+
[](https://badge.fury.io/rb/spree_elta_courier)
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
1. Add this extension to your Gemfile with this line:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
bundle add spree_elta_courier
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
2. Run the install generator
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
bundle exec rails g spree_elta_courier:install
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
3. Restart your server
|
|
22
|
+
|
|
23
|
+
If your server was running, restart it so that it can find the assets properly.
|
|
24
|
+
|
|
25
|
+
## Developing
|
|
26
|
+
|
|
27
|
+
1. Create a dummy app
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
bundle update
|
|
31
|
+
bundle exec rake test_app
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
2. Add your new code
|
|
35
|
+
3. Run tests
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
bundle exec rspec
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
When testing your applications integration with this extension you may use it's factories.
|
|
42
|
+
Simply add this require statement to your spec_helper:
|
|
43
|
+
|
|
44
|
+
```ruby
|
|
45
|
+
require 'spree_elta_courier/factories'
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Testing
|
|
49
|
+
|
|
50
|
+
By running the Spree test_app rake task, we can generate a barebones Spree application within our spec directory to run our tests against.
|
|
51
|
+
|
|
52
|
+
We can do this with the following command from the root directory of our extension:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
bundle exec rake test_app
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
After this command completes, you should be able to run `rspec`.
|
|
59
|
+
|
|
60
|
+
## Releasing a new version
|
|
61
|
+
|
|
62
|
+
```shell
|
|
63
|
+
bundle exec gem bump -p -t
|
|
64
|
+
bundle exec gem release
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
For more options please see [gem-release README](https://github.com/svenfuchs/gem-release)
|
|
68
|
+
|
|
69
|
+
## Contributing
|
|
70
|
+
|
|
71
|
+
If you'd like to contribute, please take a look at the
|
|
72
|
+
[instructions](CONTRIBUTING.md) for installing dependencies and crafting a good
|
|
73
|
+
pull request.
|
|
74
|
+
|
|
75
|
+
Copyright (c) 2025 OlympusOne, released under the MIT
|
data/Rakefile
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'bundler'
|
|
2
|
+
Bundler::GemHelper.install_tasks
|
|
3
|
+
|
|
4
|
+
require 'rspec/core/rake_task'
|
|
5
|
+
require 'spree/testing_support/extension_rake'
|
|
6
|
+
|
|
7
|
+
RSpec::Core::RakeTask.new
|
|
8
|
+
|
|
9
|
+
task :default do
|
|
10
|
+
if Dir['spec/dummy'].empty?
|
|
11
|
+
Rake::Task[:test_app].invoke
|
|
12
|
+
Dir.chdir('../../')
|
|
13
|
+
end
|
|
14
|
+
Rake::Task[:spec].invoke
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
desc 'Generates a dummy app for testing'
|
|
18
|
+
task :test_app do
|
|
19
|
+
ENV['LIB_NAME'] = 'spree_elta_courier'
|
|
20
|
+
Rake::Task['extension:test_app'].invoke
|
|
21
|
+
end
|
|
Binary file
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
require 'combine_pdf'
|
|
2
|
+
|
|
3
|
+
module Spree
|
|
4
|
+
module Admin
|
|
5
|
+
class EltaCourierController < Spree::Admin::BaseController
|
|
6
|
+
include Spree::Admin::OrdersFiltersHelper
|
|
7
|
+
|
|
8
|
+
def create
|
|
9
|
+
begin
|
|
10
|
+
load_order
|
|
11
|
+
|
|
12
|
+
@order.shipments.each do |shipment|
|
|
13
|
+
next unless shipment.can_create_voucher?
|
|
14
|
+
|
|
15
|
+
result = SpreeEltaCourier::CreateVoucher.new(shipment).call
|
|
16
|
+
|
|
17
|
+
shipment.update(
|
|
18
|
+
tracking: result[:vg_code]
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
flash[:success] = Spree.t('admin.integrations.elta_courier.voucher_successfully_created')
|
|
23
|
+
redirect_to spree.admin_order_path(@order)
|
|
24
|
+
rescue ActiveRecord::RecordNotFound
|
|
25
|
+
order_not_found
|
|
26
|
+
rescue StandardError => e
|
|
27
|
+
Rails.logger.error "Elta Courier Error: #{e.message}"
|
|
28
|
+
|
|
29
|
+
flash[:error] = Spree.t('admin.integrations.elta_courier.voucher_creation_failed')
|
|
30
|
+
redirect_to spree.admin_order_path(@order)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def print
|
|
35
|
+
begin
|
|
36
|
+
load_order
|
|
37
|
+
|
|
38
|
+
voucher_numbers = @order.shipments.select(&:can_print_voucher?)
|
|
39
|
+
.map(&:tracking).compact
|
|
40
|
+
|
|
41
|
+
if voucher_numbers.empty?
|
|
42
|
+
raise StandardError, Spree.t('admin.integrations.elta_courier.voucher_print_failed')
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
decoded_pdfs = voucher_numbers.map do |number|
|
|
46
|
+
voucher = SpreeEltaCourier::PrintVouchers.new(number).call
|
|
47
|
+
|
|
48
|
+
Base64.decode64(voucher[:b64_string])
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
merged_bytes =
|
|
52
|
+
if decoded_pdfs.size == 1
|
|
53
|
+
decoded_pdfs.first
|
|
54
|
+
else
|
|
55
|
+
combined = CombinePDF.new
|
|
56
|
+
decoded_pdfs.each { |bytes| combined << CombinePDF.parse(bytes) }
|
|
57
|
+
combined.to_pdf
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
send_data merged_bytes,
|
|
61
|
+
filename: "#{@order.number}.pdf",
|
|
62
|
+
type: 'application/pdf',
|
|
63
|
+
disposition: 'inline'
|
|
64
|
+
rescue ActiveRecord::RecordNotFound
|
|
65
|
+
render json: {
|
|
66
|
+
error: flash_message_for(Spree::Order.new, :not_found)
|
|
67
|
+
}, status: 404
|
|
68
|
+
rescue StandardError => e
|
|
69
|
+
Rails.logger.error "Elta Courier Error: #{e.message}"
|
|
70
|
+
|
|
71
|
+
render json: {
|
|
72
|
+
error: Spree.t('admin.integrations.elta_courier.voucher_print_failed')
|
|
73
|
+
}, status: 400
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
private
|
|
78
|
+
|
|
79
|
+
def load_order
|
|
80
|
+
@order = current_store.orders.find(params[:order_id])
|
|
81
|
+
authorize! action, @order
|
|
82
|
+
@order
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def order_not_found
|
|
86
|
+
flash[:error] = flash_message_for(Spree::Order.new, :not_found)
|
|
87
|
+
redirect_to spree.admin_orders_path
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import '@hotwired/turbo-rails'
|
|
2
|
+
import { Application } from '@hotwired/stimulus'
|
|
3
|
+
|
|
4
|
+
let application
|
|
5
|
+
|
|
6
|
+
if (typeof window.Stimulus === "undefined") {
|
|
7
|
+
application = Application.start()
|
|
8
|
+
application.debug = false
|
|
9
|
+
window.Stimulus = application
|
|
10
|
+
} else {
|
|
11
|
+
application = window.Stimulus
|
|
12
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
require 'savon'
|
|
2
|
+
|
|
3
|
+
module EltaCourier
|
|
4
|
+
class SoapClient
|
|
5
|
+
include Spree::IntegrationsConcern
|
|
6
|
+
|
|
7
|
+
SERVICE_WSDL_FILES = {
|
|
8
|
+
create: 'CREATEAWB02.wsdl',
|
|
9
|
+
print: 'PELB64VG.wsdl',
|
|
10
|
+
track: 'PELTT03.wsdl',
|
|
11
|
+
pudo: 'GETPUDODETAILS.wsdl'
|
|
12
|
+
}.freeze
|
|
13
|
+
|
|
14
|
+
attr_reader :client
|
|
15
|
+
|
|
16
|
+
def initialize(service)
|
|
17
|
+
integration = store_integration('elta_courier')
|
|
18
|
+
raise 'Integration not found' unless integration
|
|
19
|
+
|
|
20
|
+
wsdl_url = integration.preferred_wsdl_url
|
|
21
|
+
raise 'WSDL URL is required' unless wsdl_url
|
|
22
|
+
|
|
23
|
+
wsdl_source = resolve_wsdl(service)
|
|
24
|
+
|
|
25
|
+
@customer_code = integration.preferred_customer_code
|
|
26
|
+
@user_code = integration.preferred_user_code
|
|
27
|
+
@password = integration.preferred_password
|
|
28
|
+
|
|
29
|
+
@client = Savon.client(
|
|
30
|
+
wsdl: wsdl_source,
|
|
31
|
+
endpoint: wsdl_url,
|
|
32
|
+
convert_request_keys_to: :none
|
|
33
|
+
)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def call(method, message = {})
|
|
37
|
+
begin
|
|
38
|
+
response = client.call(
|
|
39
|
+
method,
|
|
40
|
+
message: default_auth_params.merge(message)
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
response.body.dig(:"#{method}_response")
|
|
44
|
+
rescue Savon::SOAPFault => e
|
|
45
|
+
raise SoapError, "SOAP Fault: #{e.message}"
|
|
46
|
+
rescue Savon::HTTPError => e
|
|
47
|
+
raise SoapError, "HTTP Error: #{e.message}"
|
|
48
|
+
rescue Savon::UnknownOperationError
|
|
49
|
+
raise SoapError, "Unknown SOAP method: #{method}"
|
|
50
|
+
rescue Savon::Error => e
|
|
51
|
+
raise SoapError, "SOAP call failed: #{e.message}"
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def default_auth_params
|
|
56
|
+
{
|
|
57
|
+
'pel_apost_code' => @customer_code,
|
|
58
|
+
'pel_user_code' => @user_code,
|
|
59
|
+
'pel_user_pass' => @password
|
|
60
|
+
}.compact
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def resolve_wsdl(service)
|
|
64
|
+
filename = SERVICE_WSDL_FILES[service]
|
|
65
|
+
raise ArgumentError, "Unknown ELTA service: #{service}" unless filename
|
|
66
|
+
|
|
67
|
+
SpreeEltaCourier::Engine.root.join('lib', 'spree_elta_courier', 'wsdl', filename).to_s
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
class SoapError < StandardError; end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Integrations
|
|
3
|
+
class EltaCourier < Spree::Integration
|
|
4
|
+
preference :wsdl_url, :string
|
|
5
|
+
preference :customer_code, :string
|
|
6
|
+
preference :user_code, :string
|
|
7
|
+
preference :password, :string
|
|
8
|
+
preference :paper_size, :string, default: "1"
|
|
9
|
+
|
|
10
|
+
validates :preferred_wsdl_url, presence: true
|
|
11
|
+
validates :preferred_customer_code, presence: true
|
|
12
|
+
validates :preferred_user_code, presence: true
|
|
13
|
+
validates :preferred_password, presence: true
|
|
14
|
+
validates :preferred_paper_size, presence: true, inclusion: { in: %w[0 1] }
|
|
15
|
+
|
|
16
|
+
def self.integration_group
|
|
17
|
+
'shipping'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.icon_path
|
|
21
|
+
'integration_icons/elta-courier-logo.png'
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module SpreeEltaCourier
|
|
2
|
+
class CreateVoucher
|
|
3
|
+
attr_reader :order, :shipment, :client
|
|
4
|
+
|
|
5
|
+
def initialize(shipment)
|
|
6
|
+
@order = shipment.order
|
|
7
|
+
@shipment = shipment
|
|
8
|
+
|
|
9
|
+
@client = EltaCourier::SoapClient.new(:create)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def call
|
|
13
|
+
address = shipment.address
|
|
14
|
+
cod_payment = order.payment_method&.cod_payment?
|
|
15
|
+
|
|
16
|
+
record = {
|
|
17
|
+
'pel_paral_name' => address.full_name,
|
|
18
|
+
'pel_paral_address' => address.address1,
|
|
19
|
+
'pel_paral_area' => address.city,
|
|
20
|
+
'pel_paral_tk' => address.zipcode.gsub(/\s+/, ''),
|
|
21
|
+
'pel_paral_thl_1' => address.phone,
|
|
22
|
+
'pel_baros' => shipment.item_weight.to_f,
|
|
23
|
+
'pel_temaxia' => 1,
|
|
24
|
+
'pel_paral_sxolia' => order.special_instructions,
|
|
25
|
+
'pel_ant_poso' => cod_payment ? shipment.final_price_with_items.to_f : 0,
|
|
26
|
+
'pel_ref_no' => shipment.number,
|
|
27
|
+
'sideta_eidos' => 2 # 1=Documents, 2=Parcel
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
result = client.call(
|
|
31
|
+
:read,
|
|
32
|
+
record
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
return result if result[:st_flag].to_i.zero?
|
|
36
|
+
|
|
37
|
+
raise VoucherError, "Failed to create voucher: #{result[:st_title]}" if result[:st_flag].to_i != 0
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
class VoucherError < StandardError; end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module SpreeEltaCourier
|
|
2
|
+
class PrintVouchers
|
|
3
|
+
include Spree::IntegrationsConcern
|
|
4
|
+
|
|
5
|
+
attr_reader :vg_code, :client
|
|
6
|
+
|
|
7
|
+
def initialize(vg_code)
|
|
8
|
+
@vg_code = vg_code
|
|
9
|
+
|
|
10
|
+
@client = EltaCourier::SoapClient.new(:print)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def call
|
|
14
|
+
integration = store_integration('elta_courier')
|
|
15
|
+
|
|
16
|
+
raise 'Integration not found' unless integration
|
|
17
|
+
|
|
18
|
+
preferred_paper_size = integration.preferred_paper_size
|
|
19
|
+
|
|
20
|
+
record = {
|
|
21
|
+
'vg_code' => vg_code,
|
|
22
|
+
'paper_size' => preferred_paper_size
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
result = client.call(
|
|
26
|
+
:read,
|
|
27
|
+
record
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
return result if result[:st_flag].to_i.zero?
|
|
31
|
+
|
|
32
|
+
raise VoucherError, "Failed to print voucher: #{result[:st_title]}" if result[:st_flag].to_i != 0
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<div class="col-12 col-md-6 p-0">
|
|
2
|
+
<div class="card mb-4">
|
|
3
|
+
<div class="card-body">
|
|
4
|
+
<%= preference_field(@integration, form, 'wsdl_url', i18n_scope: 'admin.integrations.elta_courier') %>
|
|
5
|
+
<%= preference_field(@integration, form, 'customer_code', i18n_scope: 'admin.integrations.elta_courier') %>
|
|
6
|
+
<%= preference_field(@integration, form, 'user_code', i18n_scope: 'admin.integrations.elta_courier') %>
|
|
7
|
+
<%= preference_field(@integration, form, 'password', i18n_scope: 'admin.integrations.elta_courier') %>
|
|
8
|
+
|
|
9
|
+
<div class="form-group">
|
|
10
|
+
<%= form.label :preferred_paper_size, Spree.t('admin.integrations.elta_courier.preferred_paper_size') %>
|
|
11
|
+
<%= form.select :preferred_paper_size, options_for_select([['A4', '0'], ['A6', '1']], @integration.preferred_paper_size), {}, { class: 'custom-select', data: { action: 'auto-submit#submit' } } %>
|
|
12
|
+
<%= form.error_message_on :preferred_paper_size %>
|
|
13
|
+
</div>
|
|
14
|
+
</div>
|
|
15
|
+
</div>
|
|
16
|
+
</div>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= javascript_import_module_tag 'application-spree-elta-courier' %>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<% if store_integration('elta_courier').present? %>
|
|
2
|
+
<% if @order.can_create_voucher? %>
|
|
3
|
+
<%= link_to_with_icon 'package',
|
|
4
|
+
Spree.t('admin.integrations.elta_courier.create_voucher'),
|
|
5
|
+
spree.admin_elta_courier_create_path(@order.id),
|
|
6
|
+
class: 'btn text-left dropdown-item',
|
|
7
|
+
data: { turbo_method: :post, turbo_confirm: Spree.t(:are_you_sure) }
|
|
8
|
+
%>
|
|
9
|
+
<% end %>
|
|
10
|
+
|
|
11
|
+
<% if @order.can_print_voucher? %>
|
|
12
|
+
<%= link_to_with_icon 'printer',
|
|
13
|
+
Spree.t('admin.integrations.elta_courier.print_voucher'),
|
|
14
|
+
spree.admin_elta_courier_print_path(@order.id),
|
|
15
|
+
class: 'btn text-left dropdown-item',
|
|
16
|
+
target: '_blank'
|
|
17
|
+
%>
|
|
18
|
+
<% end %>
|
|
19
|
+
<% end %>
|
data/config/importmap.rb
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
pin 'application-spree-elta-courier', to: 'spree_elta_courier/application.js', preload: false
|
|
2
|
+
|
|
3
|
+
pin_all_from SpreeEltaCourier::Engine.root.join('app/javascript/spree_elta_courier/controllers'),
|
|
4
|
+
under: 'spree_elta_courier/controllers',
|
|
5
|
+
to: 'spree_elta_courier/controllers',
|
|
6
|
+
preload: 'application-spree-elta-courier'
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Rails.application.config.after_initialize do
|
|
2
|
+
Rails.application.config.spree.integrations << Spree::Integrations::EltaCourier
|
|
3
|
+
|
|
4
|
+
if Rails.application.config.respond_to?(:spree_admin)
|
|
5
|
+
Rails.application.config.spree_admin.head_partials << 'spree_elta_courier/head'
|
|
6
|
+
|
|
7
|
+
Rails.application.config.spree_admin.order_page_dropdown_partials << 'spree_elta_courier/order_dropdown_options'
|
|
8
|
+
end
|
|
9
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
el:
|
|
3
|
+
spree:
|
|
4
|
+
admin:
|
|
5
|
+
integrations:
|
|
6
|
+
elta_courier:
|
|
7
|
+
title: ΕΛΤΑ Courier
|
|
8
|
+
description: Διασύνδεση με τις υπηρεσίες της ΕΛΤΑ Courier
|
|
9
|
+
preferred_wsdl_url: WSDL URL
|
|
10
|
+
preferred_customer_code: Customer Code
|
|
11
|
+
preferred_user_code: User Code
|
|
12
|
+
preferred_password: Password
|
|
13
|
+
preferred_paper_size: Μέγεθος Χαρτιού
|
|
14
|
+
create_voucher: Δημιουργία Voucher
|
|
15
|
+
print_voucher: Εκτύπωση Voucher
|
|
16
|
+
voucher_successfully_created: Voucher δημιουργήθηκε επιτυχώς
|
|
17
|
+
voucher_creation_failed: Αποτυχία δημιουργίας Voucher
|
|
18
|
+
voucher_print_failed: Αποτυχία εκτύπωσης Voucher
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
en:
|
|
3
|
+
spree:
|
|
4
|
+
admin:
|
|
5
|
+
integrations:
|
|
6
|
+
elta_courier:
|
|
7
|
+
title: ΕΛΤΑ Courier
|
|
8
|
+
description: Elta Courier is a shipping integration for Greece
|
|
9
|
+
preferred_wsdl_url: WSDL URL
|
|
10
|
+
preferred_customer_code: Customer Code
|
|
11
|
+
preferred_user_code: User Code
|
|
12
|
+
preferred_password: Password
|
|
13
|
+
preferred_paper_size: Paper Size
|
|
14
|
+
create_voucher: Create Voucher
|
|
15
|
+
print_voucher: Print Voucher
|
|
16
|
+
voucher_successfully_created: Voucher successfully created
|
|
17
|
+
voucher_creation_failed: Voucher creation failed
|
|
18
|
+
voucher_print: Voucher printing failed
|
data/config/routes.rb
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
Spree::Core::Engine.add_routes do
|
|
2
|
+
namespace :admin, path: Spree.admin_path do
|
|
3
|
+
post 'elta_courier/:order_id/create', to: 'elta_courier#create', as: :elta_courier_create
|
|
4
|
+
get 'elta_courier/:order_id/print', to: 'elta_courier#print', as: :elta_courier_print
|
|
5
|
+
end
|
|
6
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module SpreeEltaCourier
|
|
2
|
+
module Generators
|
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
|
4
|
+
class_option :migrate, type: :boolean, default: true
|
|
5
|
+
|
|
6
|
+
def add_migrations
|
|
7
|
+
run 'bundle exec rake railties:install:migrations FROM=spree_elta_courier'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def run_migrations
|
|
11
|
+
run_migrations = options[:migrate] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
|
|
12
|
+
if run_migrations
|
|
13
|
+
run 'bin/rails db:migrate'
|
|
14
|
+
else
|
|
15
|
+
puts 'Skipping rails db:migrate, don\'t forget to run it!'
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module SpreeEltaCourier
|
|
2
|
+
class Configuration < Spree::Preferences::Configuration
|
|
3
|
+
|
|
4
|
+
# Some example preferences are shown below, for more information visit:
|
|
5
|
+
# https://docs.spreecommerce.org/developer/contributing/creating-an-extension
|
|
6
|
+
|
|
7
|
+
# preference :enabled, :boolean, default: true
|
|
8
|
+
# preference :dark_chocolate, :boolean, default: true
|
|
9
|
+
# preference :color, :string, default: 'Red'
|
|
10
|
+
# preference :favorite_number, :integer
|
|
11
|
+
# preference :supported_locales, :array, default: [:en]
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module SpreeEltaCourier
|
|
2
|
+
class Engine < Rails::Engine
|
|
3
|
+
require 'spree/core'
|
|
4
|
+
isolate_namespace Spree
|
|
5
|
+
engine_name 'spree_elta_courier'
|
|
6
|
+
|
|
7
|
+
# use rspec for tests
|
|
8
|
+
config.generators do |g|
|
|
9
|
+
g.test_framework :rspec
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
initializer 'spree_elta_courier.environment', before: :load_config_initializers do |_app|
|
|
13
|
+
SpreeEltaCourier::Config = SpreeEltaCourier::Configuration.new
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
initializer 'spree_elta_courier.assets' do |app|
|
|
17
|
+
app.config.assets.paths << root.join('app/javascript')
|
|
18
|
+
app.config.assets.precompile += %w[spree_elta_courier_manifest]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
initializer 'spree_elta_courier.importmap', after: 'spree.admin.importmap' do |app|
|
|
22
|
+
app.config.spree_admin.importmap.draw(root.join('config/importmap.rb'))
|
|
23
|
+
|
|
24
|
+
app.config.spree_admin.cache_sweepers << root.join('app/javascript')
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
initializer 'spree_elta_courier.cache_sweeper', before: 'spree.admin.importmap.cache_sweeper' do |app|
|
|
28
|
+
app.config.spree_admin.cache_sweepers << root.join('app/javascript')
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.activate
|
|
32
|
+
Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
|
|
33
|
+
Rails.configuration.cache_classes ? require(c) : load(c)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
config.to_prepare(&method(:activate).to_proc)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
FactoryBot.define do
|
|
2
|
+
factory :elta_courier_integration, class: Spree::Integrations::EltaCourier do
|
|
3
|
+
active { true }
|
|
4
|
+
preferred_wsdl_url { ENV['ELTA_COURIER_WSDL_URL'] }
|
|
5
|
+
preferred_customer_code { ENV['ELTA_COURIER_CUSTOMER_CODE'] }
|
|
6
|
+
preferred_username { ENV['ELTA_COURIER_USERNAME'] }
|
|
7
|
+
preferred_password { ENV['ELTA_COURIER_PASSWORD'] }
|
|
8
|
+
store { Spree::Store.default }
|
|
9
|
+
end
|
|
10
|
+
end
|