spree_elta_courier 1.0.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0138c167e19a827d9eda2caef4333702930eb2d1f436b6a7f9755bb83b9a79d6'
4
- data.tar.gz: 6aaf7177fb8045fb654cb47282a148baab634bb6d541a8731561bd52dcbf252d
3
+ metadata.gz: 299aba1d364e609c4578085d0638d4c79ef57e189ab77d50b00b80576120e208
4
+ data.tar.gz: 1baef138576cd3836b195ec0c4fbe91c216eb4eabe083c6e781cd09b2812f4a9
5
5
  SHA512:
6
- metadata.gz: eaa5dfcba4320663fd8f21880aaa667e754fc5e56ebcbb242a430a77eafda2df4a75afc83dfa0a5ce83085ddfb23dddc32a57cc189c1cde146c02d51c7cca29d
7
- data.tar.gz: 8bef0689177ce154d5c51aeda6f245349707632258e09596572cf019d468d70df14f99db56d41788ce4c2ba4eac414ab9734c5c33b7a6b049dee8a4dca643806
6
+ metadata.gz: 696c147dbd40e9cb7014756e36c006bf4c7fc92c0c26d46db0c1e809d6e0f6622dae2976714d696f625a4087a6062d668fbd6f2c93992d366f2af898ca3793f7
7
+ data.tar.gz: 03b5341408f149e988b729fa8fdc9581ec71c440ed7a77d281e8a5b7c39bc8be87abce348ce4977cadaeaa6c1a0120dd408a1ec8b32e42bf1929414fcb2be79b
data/LICENSE.md CHANGED
@@ -1,10 +1,15 @@
1
- # MIT License
1
+ # LICENSE
2
2
 
3
- Copyright (c) 2025 OlympusOne
3
+ Copyright (c) 2025 OlympusOne. All rights reserved.
4
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:
5
+ This program is free software: you can redistribute it and/or modify it under the terms of the
6
+ GNU Affero General Public License as published by the Free Software Foundation, either
7
+ version 3 of the License, or any later version.
6
8
 
7
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
8
13
 
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.
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see [https://www.gnu.org/licenses/](https://www.gnu.org/licenses/).
data/README.md CHANGED
@@ -1,45 +1,59 @@
1
1
  # Spree Elta Courier
2
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.
3
+ This is an Elta Courier extension for [Spree Commerce](https://spreecommerce.org), an opensource e-commerce platform built with Ruby on Rails. It adds the ability to manage Elta Courier vouchers.
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/spree_elta_courier.svg)](https://badge.fury.io/rb/spree_elta_courier)
6
6
 
7
7
  ## Installation
8
8
 
9
- 1. Add this extension to your Gemfile with this line:
9
+ 1. Add this extension to your Gemfile:
10
10
 
11
11
  ```ruby
12
12
  bundle add spree_elta_courier
13
13
  ```
14
14
 
15
- 2. Run the install generator
15
+ 2. Restart your server.
16
16
 
17
- ```ruby
18
- bundle exec rails g spree_elta_courier:install
19
- ```
17
+ ## Usage (Creating & Printing Vouchers)
18
+
19
+ Prerequisites for an order:
20
+
21
+ - Shipping and billing addresses present
22
+ - Payment completed
23
+ - Order state: ready (so shipments exist and are ready to ship)
24
+
25
+ Workflow:
26
+
27
+ 1. Open the order in Spree Admin.
28
+ 2. If the order meets the prerequisites, the “Create Voucher” option appears in the top‑right dropdown.
29
+ 3. Click “Create Voucher” (creates one voucher per shipment or split shipment).
30
+ 4. After successful creation, the “Print Voucher” option becomes available.
31
+ 5. Click “Print Voucher”: a merged (or single) PDF opens in a new tab for download/printing.
20
32
 
21
- 3. Restart your server
33
+ Notes:
22
34
 
23
- If your server was running, restart it so that it can find the assets properly.
35
+ - Multiple shipment vouchers are merged into one PDF.
36
+ - If no voucher can be created (e.g. order not ready), the button does not appear.
37
+ - Errors will return and log details server‑side.
24
38
 
25
39
  ## Developing
26
40
 
27
- 1. Create a dummy app
41
+ 1. Create a dummy app:
28
42
 
29
43
  ```bash
30
44
  bundle update
31
45
  bundle exec rake test_app
32
46
  ```
33
47
 
34
- 2. Add your new code
35
- 3. Run tests
48
+ 2. Add code.
49
+
50
+ 3. Run tests:
36
51
 
37
52
  ```bash
38
53
  bundle exec rspec
39
54
  ```
40
55
 
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:
56
+ When testing your application's integration you may use its factories:
43
57
 
44
58
  ```ruby
45
59
  require 'spree_elta_courier/factories'
@@ -47,19 +61,21 @@ require 'spree_elta_courier/factories'
47
61
 
48
62
  ## Testing
49
63
 
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:
64
+ Generate the test app:
53
65
 
54
66
  ```bash
55
67
  bundle exec rake test_app
56
68
  ```
57
69
 
58
- After this command completes, you should be able to run `rspec`.
70
+ Then run:
71
+
72
+ ```bash
73
+ bundle exec rspec
74
+ ```
59
75
 
60
76
  ## Releasing a new version
61
77
 
62
- ```shell
78
+ ```bash
63
79
  bundle exec gem bump -p -t
64
80
  bundle exec gem release
65
81
  ```
@@ -72,4 +88,4 @@ If you'd like to contribute, please take a look at the
72
88
  [instructions](CONTRIBUTING.md) for installing dependencies and crafting a good
73
89
  pull request.
74
90
 
75
- Copyright (c) 2025 OlympusOne, released under the MIT
91
+ Copyright (c) 2025 OlympusOne, released under the AGPL-3.0 or later.
@@ -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.update(
18
- tracking: result[:vg_code]
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
- voucher_numbers = @order.shipments.select(&:can_print_voucher?)
39
- .map(&:tracking).compact
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
@@ -10,3 +10,7 @@ if (typeof window.Stimulus === "undefined") {
10
10
  } else {
11
11
  application = window.Stimulus
12
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 :order, :shipment, :client
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' => 1,
24
- 'pel_paral_sxolia' => order.special_instructions,
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
@@ -1 +1 @@
1
- <%= javascript_import_module_tag 'application-spree-elta-courier' %>
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
- <%= 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
- %>
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? %>
@@ -1,9 +1,7 @@
1
1
  Rails.application.config.after_initialize do
2
2
  Rails.application.config.spree.integrations << Spree::Integrations::EltaCourier
3
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
4
+ # Admin partials
5
+ Rails.application.config.spree_admin.head_partials << 'spree_elta_courier/head'
6
+ Rails.application.config.spree_admin.order_page_dropdown_partials << 'spree_elta_courier/order_dropdown_options'
9
7
  end
@@ -11,8 +11,10 @@ el:
11
11
  preferred_user_code: User Code
12
12
  preferred_password: Password
13
13
  preferred_paper_size: Μέγεθος Χαρτιού
14
- create_voucher: Δημιουργία Voucher
15
- print_voucher: Εκτύπωση Voucher
14
+ create_voucher: Δημιουργία Voucher (Elta Courier)
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
@@ -11,8 +11,10 @@ en:
11
11
  preferred_user_code: User Code
12
12
  preferred_password: Password
13
13
  preferred_paper_size: Paper Size
14
- create_voucher: Create Voucher
15
- print_voucher: Print Voucher
14
+ create_voucher: Create Voucher (Elta Courier)
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
@@ -20,7 +20,6 @@ module SpreeEltaCourier
20
20
 
21
21
  initializer 'spree_elta_courier.importmap', after: 'spree.admin.importmap' do |app|
22
22
  app.config.spree_admin.importmap.draw(root.join('config/importmap.rb'))
23
-
24
23
  app.config.spree_admin.cache_sweepers << root.join('app/javascript')
25
24
  end
26
25
 
@@ -1,3 +1,11 @@
1
- Dir["#{File.dirname(__FILE__)}/testing_support/factories/**"].each do |f|
2
- load File.expand_path(f)
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_user_code { ENV['ELTA_COURIER_USER_CODE'] }
7
+ preferred_password { ENV['ELTA_COURIER_PASSWORD'] }
8
+ preferred_paper_size { "1" }
9
+ store { Spree::Store.default }
10
+ end
3
11
  end
@@ -1,5 +1,5 @@
1
1
  module SpreeEltaCourier
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.1.0'.freeze
3
3
 
4
4
  def gem_version
5
5
  Gem::Version.new(VERSION)
@@ -5,7 +5,4 @@ require 'spree_elta_courier/version'
5
5
  require 'spree_elta_courier/configuration'
6
6
 
7
7
  module SpreeEltaCourier
8
- def self.queue
9
- 'default'
10
- end
11
- end
8
+ end
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.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OlympusOne
@@ -15,42 +15,42 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: 5.1.0
18
+ version: 5.1.8
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: 5.1.0
25
+ version: 5.1.8
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: spree_storefront
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 5.1.0
32
+ version: 5.1.8
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: 5.1.0
39
+ version: 5.1.8
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: spree_admin
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: 5.1.0
46
+ version: 5.1.8
47
47
  type: :runtime
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: 5.1.0
53
+ version: 5.1.8
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: spree_extension
56
56
  requirement: !ruby/object:Gem::Requirement
@@ -134,6 +134,7 @@ files:
134
134
  - app/assets/images/integration_icons/elta-courier-logo.png
135
135
  - app/controllers/spree/admin/elta_courier_controller.rb
136
136
  - app/javascript/spree_elta_courier/application.js
137
+ - app/javascript/spree_elta_courier/controllers/elta_courier_controller.js
137
138
  - app/lib/elta_courier/soap_client.rb
138
139
  - app/models/spree/integrations/elta_courier.rb
139
140
  - app/models/spree/order_decorator.rb
@@ -148,12 +149,10 @@ files:
148
149
  - config/locales/el.yml
149
150
  - config/locales/en.yml
150
151
  - config/routes.rb
151
- - lib/generators/spree_elta_courier/install/install_generator.rb
152
152
  - lib/spree_elta_courier.rb
153
153
  - lib/spree_elta_courier/configuration.rb
154
154
  - lib/spree_elta_courier/engine.rb
155
155
  - lib/spree_elta_courier/factories.rb
156
- - lib/spree_elta_courier/testing_support/factories/elta_courier_integration.rb
157
156
  - lib/spree_elta_courier/version.rb
158
157
  - lib/spree_elta_courier/wsdl/CREATEAWB02.wsdl
159
158
  - lib/spree_elta_courier/wsdl/ELTACOURIERPOSTSIDETA.wsdl
@@ -162,13 +161,13 @@ files:
162
161
  - lib/spree_elta_courier/wsdl/PELTT03.wsdl
163
162
  homepage: https://github.com/olympusone/spree_elta_courier
164
163
  licenses:
165
- - MIT
164
+ - AGPL-3.0-or-later
166
165
  metadata:
167
166
  bug_tracker_uri: https://github.com/olympusone/spree_elta_courier/issues
168
- changelog_uri: https://github.com/olympusone/spree_elta_courier/releases/tag/v1.0.0
167
+ changelog_uri: https://github.com/olympusone/spree_elta_courier/releases/tag/v1.1.0
169
168
  documentation_uri: https://github.com/olympusone/spree_elta_courier
170
169
  homepage_uri: https://github.com/olympusone/spree_elta_courier
171
- source_code_uri: https://github.com/olympusone/spree_elta_courier/tree/v1.0.0
170
+ source_code_uri: https://github.com/olympusone/spree_elta_courier/tree/v1.1.0
172
171
  rdoc_options: []
173
172
  require_paths:
174
173
  - lib
@@ -1,20 +0,0 @@
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
@@ -1,10 +0,0 @@
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