spree_tradebyte 0.1.12.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.byebug_history +39 -0
- data/.gitignore +22 -0
- data/.rspec +3 -0
- data/.rubocop.yml +24 -0
- data/.travis.yml +31 -0
- data/Appraisals +29 -0
- data/Gemfile +16 -0
- data/LICENSE +26 -0
- data/README.md +59 -0
- data/Rakefile +21 -0
- data/app/assets/javascripts/spree/backend/spree_tradebyte.js +2 -0
- data/app/assets/javascripts/spree/frontend/spree_tradebyte.js +2 -0
- data/app/assets/stylesheets/spree/backend/spree_tradebyte.css +4 -0
- data/app/assets/stylesheets/spree/frontend/spree_tradebyte.css +4 -0
- data/app/jobs/spree_tradebyte/application_job.rb +7 -0
- data/app/jobs/spree_tradebyte/export_products_job.rb +229 -0
- data/app/jobs/spree_tradebyte/export_stock_job.rb +39 -0
- data/app/jobs/spree_tradebyte/import_orders_job.rb +70 -0
- data/app/jobs/spree_tradebyte/order/processor.rb +158 -0
- data/app/mailers/application_mailer.rb +5 -0
- data/app/mailers/spree_tradebyte/error_notification_mailer.rb +9 -0
- data/app/models/spree/order/mail_defuser.rb +15 -0
- data/app/models/spree/order/tradebyte_message_builder.rb +133 -0
- data/app/models/spree/order_decorator.rb +14 -0
- data/app/models/spree/order_updater_decorator.rb +18 -0
- data/app/models/spree/payment_method/tradebyte.rb +7 -0
- data/app/models/spree/product_decorator.rb +15 -0
- data/app/models/spree/reimbursement/mail_defuser.rb +9 -0
- data/app/models/spree/reimbursement_decorator.rb +11 -0
- data/app/models/spree/shipment_decorator.rb +9 -0
- data/app/models/spree/shipment_handler/mail_defuser.rb +7 -0
- data/app/models/spree/shipment_handler_decorator.rb +5 -0
- data/app/models/spree/variant_decorator.rb +47 -0
- data/app/overrides/order_index.rb +13 -0
- data/app/overrides/tradebyte_settings.rb +13 -0
- data/app/views/layouts/spree_tradebyte/mailer.html.erb +13 -0
- data/app/views/layouts/spree_tradebyte/mailer.text.erb +1 -0
- data/app/views/spree/admin/orders/_index_tradebyte_state_override.html.erb +7 -0
- data/app/views/spree/admin/orders/_index_tradebyte_state_override_head.html.erb +1 -0
- data/app/views/spree/admin/products/_tradebyte_fields.html.erb +15 -0
- data/app/views/spree/admin/variants/_tradebyte_fields.html.erb +16 -0
- data/app/views/spree_tradebyte/error_notification_mailer/exception_mail.html.erb +12 -0
- data/bin/rails +8 -0
- data/config/locales/en.yml +5 -0
- data/config/routes.rb +3 -0
- data/db/migrate/20190301122602_add_tradebyte_exported_to_spree_orders.rb +5 -0
- data/db/migrate/20190305123644_add_columns_to_spree_orders.rb +8 -0
- data/db/migrate/20190307133555_add_tradebyte_id_to_spree_line_items.rb +5 -0
- data/db/migrate/20190315162630_add_tradebyte_sku_to_line_items.rb +5 -0
- data/db/migrate/20190529120919_add_tradebyte_fields_to_products.rb +7 -0
- data/db/migrate/20190529145337_add_tradebyte_settings_to_spree_variants.rb +5 -0
- data/db/migrate/20190611114706_create_shipping_methods_for_tradebyte.rb +17 -0
- data/db/migrate/20190611114720_create_payment_method_for_tradebyte.rb +5 -0
- data/lib/generators/spree_tradebyte/install/install_generator.rb +28 -0
- data/lib/generators/spree_tradebyte/templates/initializer.rb +42 -0
- data/lib/helpers/setup_configuration.rb +27 -0
- data/lib/spree_tradebyte.rb +26 -0
- data/lib/spree_tradebyte/engine.rb +25 -0
- data/lib/spree_tradebyte/factories.rb +6 -0
- data/lib/spree_tradebyte/tb_logger.rb +14 -0
- data/lib/spree_tradebyte/tradebyte_ftp.rb +98 -0
- data/lib/spree_tradebyte/version.rb +18 -0
- data/lib/tasks/variants.rake +13 -0
- data/spree_tradebyte.gemspec +48 -0
- metadata +427 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
module Spree
|
2
|
+
OrderUpdater.class_eval do
|
3
|
+
|
4
|
+
# give each of the shipments a chance to update themselves
|
5
|
+
def update_shipments
|
6
|
+
shipping_method_filter = order.completed? ? ShippingMethod::DISPLAY_ON_BACK_END : ShippingMethod::DISPLAY_ON_FRONT_END
|
7
|
+
|
8
|
+
shipments.each do |shipment|
|
9
|
+
next unless shipment.persisted?
|
10
|
+
|
11
|
+
shipment.update!(order)
|
12
|
+
shipment.refresh_rates(shipping_method_filter)
|
13
|
+
shipment.update_amounts
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'storext'
|
2
|
+
require 'active_record/type'
|
3
|
+
|
4
|
+
Spree::Product.class_eval do
|
5
|
+
include Storext.model
|
6
|
+
|
7
|
+
store :tradebyte_settings, coder: JSON
|
8
|
+
|
9
|
+
store_attributes :tradebyte_settings do
|
10
|
+
SpreeTradebyte.channels.each do |channel|
|
11
|
+
send("#{channel}_active", ActiveModel::Type::Boolean, default: false)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Spree::Reimbursement.class_eval do
|
2
|
+
|
3
|
+
Spree::Reimbursement.state_machine.after_transition to: :reimbursed, do: :send_tradebyte_reimbursed_notifications
|
4
|
+
|
5
|
+
def send_tradebyte_reimbursed_notifications
|
6
|
+
order.tb_send_return_messages(return_items) if order.is_tradebyte_order?
|
7
|
+
end
|
8
|
+
|
9
|
+
self.prepend(Spree::Reimbursement::MailDefuser)
|
10
|
+
|
11
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'storext'
|
2
|
+
|
3
|
+
Spree::Variant.class_eval do
|
4
|
+
|
5
|
+
after_create :update_tradebyte_prices
|
6
|
+
|
7
|
+
include Storext.model
|
8
|
+
store :tradebyte_settings, coder: JSON
|
9
|
+
|
10
|
+
store_attributes :tradebyte_settings do
|
11
|
+
SpreeTradebyte.channels.each do |channel|
|
12
|
+
send("#{channel}_a_vk", Float, default: 0.0)
|
13
|
+
send("#{channel}_a_vk_old", Float, default: 0.0)
|
14
|
+
send("#{channel}_a_uvp", Float, default: 0.0)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
has_one :master, through: :product
|
19
|
+
|
20
|
+
def all_images
|
21
|
+
if images.any?
|
22
|
+
images
|
23
|
+
else
|
24
|
+
variants_in_color = Spree::Variant.same_product_colors(self)
|
25
|
+
variant_with_images = variants_in_color.detect {|v| v.images.any?}
|
26
|
+
if variant_with_images
|
27
|
+
variant_with_images.images
|
28
|
+
else
|
29
|
+
master.images
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.same_product_colors(variant)
|
35
|
+
joins(option_values: :translations).where(spree_option_value_translations: {presentation: variant.option_value('color')}, product_id: variant.product_id).includes(:default_price, option_values: :option_type)
|
36
|
+
end
|
37
|
+
|
38
|
+
def update_tradebyte_prices(new_price = self.price)
|
39
|
+
SpreeTradebyte.channels.each do |channel|
|
40
|
+
send("#{channel}_a_vk=", new_price)
|
41
|
+
send("#{channel}_a_vk_old=", new_price)
|
42
|
+
send("#{channel}_a_uvp=", new_price)
|
43
|
+
end
|
44
|
+
save!(validate: false)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Deface::Override.new(
|
2
|
+
virtual_path: 'spree/admin/orders/index',
|
3
|
+
name: 'add tradebyte order info header',
|
4
|
+
insert_after: '#listing_orders thead th:nth-last-child(3)',
|
5
|
+
partial: 'spree/admin/orders/index_tradebyte_state_override_head'
|
6
|
+
)
|
7
|
+
|
8
|
+
Deface::Override.new(
|
9
|
+
virtual_path: 'spree/admin/orders/index',
|
10
|
+
name: 'add tradebyte order info',
|
11
|
+
insert_after: '#listing_orders tbody td:nth-last-child(3)',
|
12
|
+
partial: 'spree/admin/orders/index_tradebyte_state_override'
|
13
|
+
)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Deface::Override.new(
|
2
|
+
virtual_path: 'spree/admin/products/_form',
|
3
|
+
name: 'tradebyte_product_details',
|
4
|
+
insert_bottom: '[data-hook="admin_product_form_additional_fields"]',
|
5
|
+
partial: 'spree/admin/products/tradebyte_fields'
|
6
|
+
)
|
7
|
+
|
8
|
+
Deface::Override.new(
|
9
|
+
virtual_path: 'spree/admin/variants/_form',
|
10
|
+
name: 'tradebyte_variant_details',
|
11
|
+
insert_after: '[data-hook="admin_variant_form_additional_fields"]',
|
12
|
+
partial: 'spree/admin/variants/tradebyte_fields'
|
13
|
+
)
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= yield %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<th><%= sort_link @search, :is_tradebyte_order, 'Type' %></th>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<div data-hook="admin_product_form_custom_fields">
|
2
|
+
<%= f.field_container :tradebyte_settings, class: ['form-group'] do %>
|
3
|
+
<h3>Tradebyte settings</h3>
|
4
|
+
|
5
|
+
<% @product.tradebyte_settings.each do |k, _| %>
|
6
|
+
<div class="checkbox">
|
7
|
+
<%= f.label k do %>
|
8
|
+
<%= f.check_box k %>
|
9
|
+
<%= k.humanize %>
|
10
|
+
<% end %>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<% end %>
|
15
|
+
</div>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<div class="col-xs-12 col-md-12" data-hook="admin_variant_tradebyte_settings">
|
2
|
+
<%= f.field_container :tradebyte_settings, class: ['form-group'] do %>
|
3
|
+
<h3>Tradebyte settings</h3>
|
4
|
+
|
5
|
+
<div class="row">
|
6
|
+
<% @variant.tradebyte_settings.each do |k,v| %>
|
7
|
+
<div class="form-group col-md-4">
|
8
|
+
<%= f.label k %>
|
9
|
+
<%= f.text_field k, value: v, class: 'form-control' %>
|
10
|
+
</div>
|
11
|
+
<% end %>
|
12
|
+
</div>
|
13
|
+
|
14
|
+
|
15
|
+
<% end %>
|
16
|
+
</div>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<h1>Something went wrong while importing a tradebyte order</h1>
|
2
|
+
<br>
|
3
|
+
<br>
|
4
|
+
<h2>Order:</h2>
|
5
|
+
<p><%= @order.inspect %></p>
|
6
|
+
<br>
|
7
|
+
<br>
|
8
|
+
<h2>Message:</h2>
|
9
|
+
<p><%= @exception.message %></p>
|
10
|
+
<br><br><br>
|
11
|
+
<h2>Backtrace:</h2>
|
12
|
+
<p><%= @exception.backtrace.join('<br>').html_safe %></p>
|
data/bin/rails
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" from the root of your extension
|
3
|
+
|
4
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
5
|
+
ENGINE_PATH = File.expand_path('../../lib/spree_tradebyte/engine', __FILE__)
|
6
|
+
|
7
|
+
require 'rails/all'
|
8
|
+
require 'rails/engine/commands'
|
data/config/routes.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
class AddColumnsToSpreeOrders < ActiveRecord::Migration[5.0]
|
2
|
+
def change
|
3
|
+
add_column :spree_orders, :tradebyte_id, :integer
|
4
|
+
add_column :spree_orders, :tradebyte_channel_id, :string
|
5
|
+
add_column :spree_orders, :tradebyte_channel_sign, :string
|
6
|
+
add_column :spree_orders, :is_tradebyte_order, :boolean, default: false
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateShippingMethodsForTradebyte < ActiveRecord::Migration[5.0]
|
2
|
+
def change
|
3
|
+
@all_zones = Spree::Zone.all
|
4
|
+
@default_category = Spree::ShippingCategory.first
|
5
|
+
|
6
|
+
Spree::ShippingMethod.create(name: 'TB PostNL', code: 'zanl', display_on: :back_end, admin_name: 'POSTNL', calculator_attributes: {type: 'Spree::Calculator::Shipping::FlatRate'}).tap(&method(:add_data))
|
7
|
+
Spree::ShippingMethod.create(name: 'TB DHL', code: 'zade amde', display_on: :back_end, admin_name: 'DHL', calculator_attributes: {type: 'Spree::Calculator::Shipping::FlatRate'}).tap(&method(:add_data))
|
8
|
+
Spree::ShippingMethod.create(name: 'TB DPD', code: 'bonl bobe', display_on: :back_end, admin_name: 'DPD', calculator_attributes: {type: 'Spree::Calculator::Shipping::FlatRate'}).tap(&method(:add_data))
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_data(shipping_method)
|
13
|
+
shipping_method.zones = @all_zones
|
14
|
+
shipping_method.shipping_categories << @default_category
|
15
|
+
shipping_method.save
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module SpreeTradebyte
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
class_option :auto_run_migrations, type: :boolean, default: false
|
5
|
+
|
6
|
+
def self.source_root
|
7
|
+
File.dirname(__FILE__) + '/../templates'
|
8
|
+
end
|
9
|
+
|
10
|
+
def copy_initializer_file
|
11
|
+
copy_file "./initializer.rb", "config/initializers/spree_tradebyte.rb"
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_migrations
|
15
|
+
run 'bundle exec rake railties:install:migrations FROM=spree_tradebyte'
|
16
|
+
end
|
17
|
+
|
18
|
+
def run_migrations
|
19
|
+
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
|
20
|
+
if run_migrations
|
21
|
+
run 'bundle exec rake db:migrate'
|
22
|
+
else
|
23
|
+
puts 'Skipping rake db:migrate, don\'t forget to run it!'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
SpreeTradebyte.configuration do |config|
|
2
|
+
# The TradeByte FTP server used for the file exchange
|
3
|
+
config.ftp_server = ''
|
4
|
+
|
5
|
+
# The TradeByte FTP username
|
6
|
+
config.ftp_user = ''
|
7
|
+
|
8
|
+
# The TradeByte FTP password
|
9
|
+
config.ftp_password = ''
|
10
|
+
|
11
|
+
# The TradeByte FTP port
|
12
|
+
config.ftp_port = ''
|
13
|
+
|
14
|
+
# Queue adapter for handling the import and export jobs
|
15
|
+
config.active_job_queue_adapter = :async
|
16
|
+
|
17
|
+
# Admin email to send error notifications
|
18
|
+
# ActionMailer needs to be able to send emails for this to work
|
19
|
+
config.admin_email = ''
|
20
|
+
|
21
|
+
# the method to call on the shipping method to determine the TB.ONE parcel type. :code and :admin_name are existing
|
22
|
+
# options. Any method can be called though.
|
23
|
+
config.parcel_type_method = :admin_name
|
24
|
+
|
25
|
+
# Which method should be called for the product identifier
|
26
|
+
config.product_id_method = :id
|
27
|
+
|
28
|
+
# The brand communicated to tradebyte for each article
|
29
|
+
config.brand_name = ''
|
30
|
+
|
31
|
+
# The backend host domain
|
32
|
+
config.host = ''
|
33
|
+
|
34
|
+
# The name of the taxonomy used to determine the tradebyte category structure
|
35
|
+
config.base_taxonomy = 'tradebyte'
|
36
|
+
|
37
|
+
# Which channels are active?
|
38
|
+
config.channels = %w{bonl bobe zade zanl amde}
|
39
|
+
|
40
|
+
# Delivery time (ActiveSupport::Duration)
|
41
|
+
config.delivery_time = 1.day
|
42
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module SetupConfiguration
|
2
|
+
|
3
|
+
def configuration
|
4
|
+
yield self
|
5
|
+
end
|
6
|
+
|
7
|
+
def define_setting(name, default = nil)
|
8
|
+
class_variable_set("@@#{name}", default)
|
9
|
+
|
10
|
+
define_class_method "#{name}=" do |value|
|
11
|
+
class_variable_set("@@#{name}", value)
|
12
|
+
end
|
13
|
+
|
14
|
+
define_class_method name do
|
15
|
+
class_variable_get("@@#{name}")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def define_class_method(name, &block)
|
22
|
+
(class << self; self; end).instance_eval do
|
23
|
+
define_method name, &block
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|