spree_elta_courier 1.0.1 → 1.1.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 +4 -4
- data/app/assets/config/spree_elta_courier_manifest.js +2 -0
- data/app/controllers/spree/admin/elta_courier_controller.rb +15 -9
- data/app/javascript/spree_elta_courier/application.js +16 -0
- data/app/javascript/spree_elta_courier/controllers/elta_courier_controller.js +30 -0
- data/app/services/spree_elta_courier/create_voucher.rb +7 -5
- data/app/views/spree_elta_courier/_head.html.erb +1 -0
- data/app/views/spree_elta_courier/_order_dropdown_options.html.erb +11 -6
- data/config/importmap.rb +6 -0
- data/config/initializers/spree.rb +1 -0
- data/config/locales/el.yml +2 -0
- data/config/locales/en.yml +2 -0
- data/lib/spree_elta_courier/engine.rb +10 -0
- data/lib/spree_elta_courier/version.rb +1 -1
- metadata +7 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 299aba1d364e609c4578085d0638d4c79ef57e189ab77d50b00b80576120e208
|
|
4
|
+
data.tar.gz: 1baef138576cd3836b195ec0c4fbe91c216eb4eabe083c6e781cd09b2812f4a9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 696c147dbd40e9cb7014756e36c006bf4c7fc92c0c26d46db0c1e809d6e0f6622dae2976714d696f625a4087a6062d668fbd6f2c93992d366f2af898ca3793f7
|
|
7
|
+
data.tar.gz: 03b5341408f149e988b729fa8fdc9581ec71c440ed7a77d281e8a5b7c39bc8be87abce348ce4977cadaeaa6c1a0120dd408a1ec8b32e42bf1929414fcb2be79b
|
|
@@ -9,25 +9,27 @@ module Spree
|
|
|
9
9
|
begin
|
|
10
10
|
load_order
|
|
11
11
|
|
|
12
|
+
num_packages = params[:num_packages].to_i || 1
|
|
13
|
+
|
|
12
14
|
@order.shipments.each do |shipment|
|
|
13
15
|
next unless shipment.can_create_voucher?
|
|
14
16
|
|
|
15
|
-
result = SpreeEltaCourier::CreateVoucher.new(shipment).call
|
|
17
|
+
result = SpreeEltaCourier::CreateVoucher.new(shipment, num_packages).call
|
|
18
|
+
|
|
19
|
+
vg_child = result[:vg_child].compact
|
|
16
20
|
|
|
17
|
-
shipment.
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
shipment.tracking = result[:vg_code]
|
|
22
|
+
shipment.private_metadata['elta_courier.vg_child'] = vg_child
|
|
23
|
+
shipment.save!
|
|
20
24
|
end
|
|
21
25
|
|
|
22
26
|
flash[:success] = Spree.t('admin.integrations.elta_courier.voucher_successfully_created')
|
|
23
|
-
redirect_to spree.admin_order_path(@order)
|
|
24
27
|
rescue ActiveRecord::RecordNotFound
|
|
25
28
|
order_not_found
|
|
26
29
|
rescue StandardError => e
|
|
27
30
|
Rails.logger.error "Elta Courier Error: #{e.message}"
|
|
28
31
|
|
|
29
32
|
flash[:error] = Spree.t('admin.integrations.elta_courier.voucher_creation_failed')
|
|
30
|
-
redirect_to spree.admin_order_path(@order)
|
|
31
33
|
end
|
|
32
34
|
end
|
|
33
35
|
|
|
@@ -35,8 +37,13 @@ module Spree
|
|
|
35
37
|
begin
|
|
36
38
|
load_order
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
shipments = @order.shipments.select(&:can_print_voucher?)
|
|
41
|
+
|
|
42
|
+
voucher_numbers = shipments.flat_map do |shipment|
|
|
43
|
+
vg_child = shipment.private_metadata['elta_courier.vg_child'] || []
|
|
44
|
+
|
|
45
|
+
[shipment.tracking] + vg_child
|
|
46
|
+
end
|
|
40
47
|
|
|
41
48
|
if voucher_numbers.empty?
|
|
42
49
|
raise StandardError, Spree.t('admin.integrations.elta_courier.voucher_print_failed')
|
|
@@ -84,7 +91,6 @@ module Spree
|
|
|
84
91
|
|
|
85
92
|
def order_not_found
|
|
86
93
|
flash[:error] = flash_message_for(Spree::Order.new, :not_found)
|
|
87
|
-
redirect_to spree.admin_orders_path
|
|
88
94
|
end
|
|
89
95
|
end
|
|
90
96
|
end
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
}
|
|
13
|
+
|
|
14
|
+
import EltaCourierController from 'spree_elta_courier/controllers/elta_courier_controller'
|
|
15
|
+
|
|
16
|
+
application.register('elta-courier', EltaCourierController)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Controller } from "@hotwired/stimulus";
|
|
2
|
+
import { post } from "@rails/request.js";
|
|
3
|
+
|
|
4
|
+
export default class extends Controller {
|
|
5
|
+
static values = {
|
|
6
|
+
orderId: Number,
|
|
7
|
+
createVoucherPrompt: String,
|
|
8
|
+
createVoucherError: String,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
async createVoucher(event) {
|
|
12
|
+
event.preventDefault();
|
|
13
|
+
|
|
14
|
+
const packages = window.prompt(this.createVoucherPromptValue, 1);
|
|
15
|
+
|
|
16
|
+
const numPackages = parseInt(packages, 10);
|
|
17
|
+
if (isNaN(numPackages) || numPackages <= 0) {
|
|
18
|
+
alert(this.createVoucherErrorValue);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
await post(`${Spree.adminPath}/elta_courier/${this.orderIdValue}/create`, {
|
|
23
|
+
body: {
|
|
24
|
+
num_packages: numPackages,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
Turbo.visit(window.location.href, { action: "replace" });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
module SpreeEltaCourier
|
|
2
2
|
class CreateVoucher
|
|
3
|
-
attr_reader :
|
|
3
|
+
attr_reader :shipment, :num_packages, :order, :client
|
|
4
4
|
|
|
5
|
-
def initialize(shipment)
|
|
6
|
-
@order = shipment.order
|
|
5
|
+
def initialize(shipment, num_packages = 1)
|
|
7
6
|
@shipment = shipment
|
|
7
|
+
@num_packages = num_packages
|
|
8
|
+
|
|
9
|
+
@order = shipment.order
|
|
8
10
|
|
|
9
11
|
@client = EltaCourier::SoapClient.new(:create)
|
|
10
12
|
end
|
|
@@ -20,8 +22,8 @@ module SpreeEltaCourier
|
|
|
20
22
|
'pel_paral_tk' => address.zipcode.gsub(/\s+/, ''),
|
|
21
23
|
'pel_paral_thl_1' => address.phone,
|
|
22
24
|
'pel_baros' => shipment.item_weight.to_f,
|
|
23
|
-
'pel_temaxia' =>
|
|
24
|
-
'pel_paral_sxolia' =>
|
|
25
|
+
'pel_temaxia' => num_packages,
|
|
26
|
+
'pel_paral_sxolia' => shipment.special_instructions,
|
|
25
27
|
'pel_ant_poso' => cod_payment ? shipment.final_price_with_items.to_f : 0,
|
|
26
28
|
'pel_ref_no' => shipment.number,
|
|
27
29
|
'sideta_eidos' => 2 # 1=Documents, 2=Parcel
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= javascript_import_module_tag 'application-spree-elta-courier' %>
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
<% if store_integration('elta_courier').present? %>
|
|
2
2
|
<% if @order.can_create_voucher? %>
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
data
|
|
8
|
-
|
|
3
|
+
<button
|
|
4
|
+
type="button"
|
|
5
|
+
class='btn text-left dropdown-item'
|
|
6
|
+
data-controller='elta-courier'
|
|
7
|
+
data-action='elta-courier#createVoucher'
|
|
8
|
+
data-elta-courier-order-id-value='<%= @order.id %>'
|
|
9
|
+
data-elta-courier-create-voucher-prompt-value="<%= Spree.t('admin.integrations.elta_courier.create_voucher_prompt') %>"
|
|
10
|
+
data-elta-courier-create-voucher-error-value="<%= Spree.t('admin.integrations.elta_courier.create_voucher_error') %>">
|
|
11
|
+
<%= icon 'package' %>
|
|
12
|
+
<%= Spree.t('admin.integrations.elta_courier.create_voucher') %>
|
|
13
|
+
</button>
|
|
9
14
|
<% end %>
|
|
10
15
|
|
|
11
16
|
<% if @order.can_print_voucher? %>
|
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'
|
|
@@ -2,5 +2,6 @@ Rails.application.config.after_initialize do
|
|
|
2
2
|
Rails.application.config.spree.integrations << Spree::Integrations::EltaCourier
|
|
3
3
|
|
|
4
4
|
# Admin partials
|
|
5
|
+
Rails.application.config.spree_admin.head_partials << 'spree_elta_courier/head'
|
|
5
6
|
Rails.application.config.spree_admin.order_page_dropdown_partials << 'spree_elta_courier/order_dropdown_options'
|
|
6
7
|
end
|
data/config/locales/el.yml
CHANGED
|
@@ -13,6 +13,8 @@ el:
|
|
|
13
13
|
preferred_paper_size: Μέγεθος Χαρτιού
|
|
14
14
|
create_voucher: Δημιουργία Voucher (Elta Courier)
|
|
15
15
|
print_voucher: Εκτύπωση Voucher (Elta Courier)
|
|
16
|
+
create_voucher_prompt: "Εισάγετε αριθμό δεμάτων (ανά Αποστολή):"
|
|
17
|
+
create_voucher_error: Ο αριθμός των δεμάτων πρέπει να είναι θετικός ακέραιος αριθμός.
|
|
16
18
|
voucher_successfully_created: Voucher δημιουργήθηκε επιτυχώς
|
|
17
19
|
voucher_creation_failed: Αποτυχία δημιουργίας Voucher
|
|
18
20
|
voucher_print_failed: Αποτυχία εκτύπωσης Voucher
|
data/config/locales/en.yml
CHANGED
|
@@ -13,6 +13,8 @@ en:
|
|
|
13
13
|
preferred_paper_size: Paper Size
|
|
14
14
|
create_voucher: Create Voucher (Elta Courier)
|
|
15
15
|
print_voucher: Print Voucher (Elta Courier)
|
|
16
|
+
create_voucher_prompt: "Enter the number of package (per Shipment):"
|
|
17
|
+
create_voucher_error: The number of package must be a positive integer number.
|
|
16
18
|
voucher_successfully_created: Voucher successfully created
|
|
17
19
|
voucher_creation_failed: Voucher creation failed
|
|
18
20
|
voucher_print: Voucher printing failed
|
|
@@ -14,9 +14,19 @@ module SpreeEltaCourier
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
initializer 'spree_elta_courier.assets' do |app|
|
|
17
|
+
app.config.assets.paths << root.join('app/javascript')
|
|
17
18
|
app.config.assets.precompile += %w[spree_elta_courier_manifest]
|
|
18
19
|
end
|
|
19
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
|
+
app.config.spree_admin.cache_sweepers << root.join('app/javascript')
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
initializer 'spree_elta_courier.cache_sweeper', before: 'spree.admin.importmap.cache_sweeper' do |app|
|
|
27
|
+
app.config.spree_admin.cache_sweepers << root.join('app/javascript')
|
|
28
|
+
end
|
|
29
|
+
|
|
20
30
|
def self.activate
|
|
21
31
|
Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
|
|
22
32
|
Rails.configuration.cache_classes ? require(c) : load(c)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: spree_elta_courier
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- OlympusOne
|
|
@@ -133,6 +133,8 @@ files:
|
|
|
133
133
|
- app/assets/config/spree_elta_courier_manifest.js
|
|
134
134
|
- app/assets/images/integration_icons/elta-courier-logo.png
|
|
135
135
|
- app/controllers/spree/admin/elta_courier_controller.rb
|
|
136
|
+
- app/javascript/spree_elta_courier/application.js
|
|
137
|
+
- app/javascript/spree_elta_courier/controllers/elta_courier_controller.js
|
|
136
138
|
- app/lib/elta_courier/soap_client.rb
|
|
137
139
|
- app/models/spree/integrations/elta_courier.rb
|
|
138
140
|
- app/models/spree/order_decorator.rb
|
|
@@ -140,7 +142,9 @@ files:
|
|
|
140
142
|
- app/services/spree_elta_courier/create_voucher.rb
|
|
141
143
|
- app/services/spree_elta_courier/print_vouchers.rb
|
|
142
144
|
- app/views/spree/admin/integrations/forms/_elta_courier.html.erb
|
|
145
|
+
- app/views/spree_elta_courier/_head.html.erb
|
|
143
146
|
- app/views/spree_elta_courier/_order_dropdown_options.html.erb
|
|
147
|
+
- config/importmap.rb
|
|
144
148
|
- config/initializers/spree.rb
|
|
145
149
|
- config/locales/el.yml
|
|
146
150
|
- config/locales/en.yml
|
|
@@ -160,10 +164,10 @@ licenses:
|
|
|
160
164
|
- AGPL-3.0-or-later
|
|
161
165
|
metadata:
|
|
162
166
|
bug_tracker_uri: https://github.com/olympusone/spree_elta_courier/issues
|
|
163
|
-
changelog_uri: https://github.com/olympusone/spree_elta_courier/releases/tag/v1.0
|
|
167
|
+
changelog_uri: https://github.com/olympusone/spree_elta_courier/releases/tag/v1.1.0
|
|
164
168
|
documentation_uri: https://github.com/olympusone/spree_elta_courier
|
|
165
169
|
homepage_uri: https://github.com/olympusone/spree_elta_courier
|
|
166
|
-
source_code_uri: https://github.com/olympusone/spree_elta_courier/tree/v1.0
|
|
170
|
+
source_code_uri: https://github.com/olympusone/spree_elta_courier/tree/v1.1.0
|
|
167
171
|
rdoc_options: []
|
|
168
172
|
require_paths:
|
|
169
173
|
- lib
|