spree_core 3.7.14.1 → 4.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/app/controllers/spree/base_controller.rb +0 -1
- data/app/finders/spree/taxons/find.rb +6 -5
- data/app/helpers/spree/base_helper.rb +0 -9
- data/app/helpers/spree/products_helper.rb +1 -1
- data/app/models/concerns/spree/product_scopes.rb +254 -0
- data/app/models/concerns/spree/user_address.rb +5 -2
- data/app/models/friendly_id/slug_decorator.rb +8 -2
- data/app/models/spree/ability.rb +21 -22
- data/app/models/spree/address.rb +37 -24
- data/app/models/spree/adjustment.rb +0 -10
- data/app/models/spree/app_dependencies.rb +2 -2
- data/app/models/spree/asset.rb +1 -12
- data/app/models/spree/country.rb +2 -2
- data/app/models/spree/credit_card.rb +4 -5
- data/app/models/spree/gateway/bogus.rb +1 -1
- data/app/models/spree/image.rb +8 -1
- data/app/models/spree/image/configuration/active_storage.rb +0 -2
- data/app/models/spree/order.rb +13 -78
- data/app/models/spree/order/address_book.rb +86 -0
- data/app/models/spree/order/checkout.rb +4 -22
- data/app/models/spree/order/currency_updater.rb +1 -1
- data/app/models/spree/order/store_credit.rb +0 -18
- data/app/models/spree/order_merger.rb +1 -0
- data/app/models/spree/payment.rb +4 -2
- data/app/models/spree/payment/gateway_options.rb +1 -1
- data/app/models/spree/payment/processing.rb +2 -0
- data/app/models/spree/preferences/configuration.rb +1 -1
- data/app/models/spree/preferences/preferable.rb +1 -1
- data/app/models/spree/product.rb +2 -3
- data/app/models/spree/promotion_handler/coupon.rb +2 -1
- data/app/models/spree/reimbursement_tax_calculator.rb +1 -1
- data/app/models/spree/return_item.rb +1 -1
- data/app/models/spree/return_item/eligibility_validator/default.rb +2 -0
- data/app/models/spree/return_item/eligibility_validator/{rma_required.rb → r_m_a_required.rb} +0 -0
- data/app/models/spree/shipment.rb +1 -1
- data/app/models/spree/store_credit.rb +4 -5
- data/app/models/spree/taxon_image.rb +1 -1
- data/app/models/spree/taxonomy.rb +1 -1
- data/app/services/spree/cart/add_item.rb +3 -1
- data/app/services/spree/cart/update.rb +1 -1
- data/config/locales/en.yml +15 -0
- data/db/default/spree/stores.rb +1 -0
- data/db/default/spree/zones.rb +16 -0
- data/db/migrate/20140806144901_add_type_to_reimbursement_type.rb +1 -1
- data/db/migrate/20141101231208_fix_adjustment_order_presence.rb +2 -2
- data/db/migrate/20170323151450_add_missing_unique_indexes_for_unique_attributes.rb +1 -1
- data/db/migrate/20190305121659_add_iso_and_iso3_validation_on_presence_and_uniqueness.rb +18 -0
- data/db/migrate/20190523092729_add_user_id_and_deleted_at_to_spree_addresses.rb +12 -0
- data/lib/generators/spree/dummy/dummy_generator.rb +3 -1
- data/lib/spree/core.rb +0 -2
- data/lib/spree/core/importer/order.rb +64 -103
- data/lib/spree/core/importer/product.rb +2 -2
- data/lib/spree/core/product_duplicator.rb +1 -5
- data/lib/spree/core/version.rb +1 -3
- data/lib/spree/permitted_attributes.rb +3 -1
- data/lib/spree/testing_support/ability_helpers.rb +3 -11
- data/lib/spree/testing_support/capybara_config.rb +4 -1
- data/lib/spree/testing_support/capybara_ext.rb +22 -98
- data/lib/spree/testing_support/controller_requests.rb +36 -26
- data/lib/spree/testing_support/factories/image_factory.rb +2 -6
- data/lib/spree/testing_support/factories/return_item_factory.rb +2 -2
- data/lib/spree/testing_support/factories/taxon_factory.rb +1 -1
- data/lib/spree/testing_support/i18n.rb +6 -8
- data/lib/spree/testing_support/image_helpers.rb +5 -11
- data/lib/tasks/exchanges.rake +35 -37
- data/spree_core.gemspec +11 -14
- metadata +63 -103
- data/app/models/concerns/spree/acts_as_taggable.rb +0 -11
- data/app/models/spree/image/configuration/paperclip.rb +0 -64
- data/app/models/spree/order_contents.rb +0 -54
- data/app/models/spree/product/scopes.rb +0 -250
- data/app/models/spree/tag.rb +0 -4
- data/app/models/spree/taxon_image/configuration/paperclip.rb +0 -27
- data/config/initializers/acts_as_taggable_on.rb +0 -9
- data/config/initializers/use_paperclip.rb +0 -3
- data/db/migrate/20160511071954_acts_as_taggable_on_spree_migration.rb +0 -40
- data/db/migrate/20160511072249_change_collation_for_spree_tag_names.rb +0 -9
- data/db/migrate/20160511072335_add_missing_indexes_to_spree_taggings.rb +0 -14
- data/lib/spree/core/controller_helpers/respond_with.rb +0 -67
- data/lib/spree/responder.rb +0 -44
- data/lib/spree/testing_support/factories/tag_factory.rb +0 -5
@@ -27,7 +27,7 @@ module Spree
|
|
27
27
|
price = price_from_line_item(line_item)
|
28
28
|
|
29
29
|
if price
|
30
|
-
line_item.
|
30
|
+
line_item.update!(currency: price.currency, price: price.amount)
|
31
31
|
else
|
32
32
|
raise "no #{currency} price found for #{line_item.product.name} (#{line_item.variant.sku})"
|
33
33
|
end
|
@@ -1,24 +1,6 @@
|
|
1
1
|
module Spree
|
2
2
|
class Order < Spree::Base
|
3
3
|
module StoreCredit
|
4
|
-
def add_store_credit_payments(amount = nil)
|
5
|
-
ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
|
6
|
-
Spree::Order#add_store_credit_payments method is deprecated and will be removed in Spree 4.0.
|
7
|
-
Please use Spree::Checkout::AddStoreCredit service to add Store Credit to Order.
|
8
|
-
DEPRECATION
|
9
|
-
|
10
|
-
Spree::Checkout::AddStoreCredit.call(order: self, amount: amount)
|
11
|
-
end
|
12
|
-
|
13
|
-
def remove_store_credit_payments
|
14
|
-
ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
|
15
|
-
Spree::Order#remove_store_credit_payments method is deprecated and will be removed in Spree 4.0.
|
16
|
-
Please use Spree::Checkout::RemoveStoreCredit service to remove Store Credit from Order.
|
17
|
-
DEPRECATION
|
18
|
-
|
19
|
-
Spree::Checkout::RemoveStoreCredit.call(order: self)
|
20
|
-
end
|
21
|
-
|
22
4
|
def covered_by_store_credit?
|
23
5
|
return false unless user
|
24
6
|
|
@@ -47,6 +47,7 @@ module Spree
|
|
47
47
|
handle_error(current_line_item) unless current_line_item.save
|
48
48
|
else
|
49
49
|
other_order_line_item.order_id = order.id
|
50
|
+
other_order_line_item.adjustments.update_all(order_id: order.id)
|
50
51
|
handle_error(other_order_line_item) unless other_order_line_item.save
|
51
52
|
end
|
52
53
|
end
|
data/app/models/spree/payment.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require_dependency 'spree/payment/processing'
|
2
|
+
|
1
3
|
module Spree
|
2
4
|
class Payment < Spree::Base
|
3
5
|
include Spree::Core::NumberGenerator.new(prefix: 'P', letters: true, length: 7)
|
@@ -227,7 +229,7 @@ module Spree
|
|
227
229
|
state: 'pending',
|
228
230
|
capture_on_dispatch: true
|
229
231
|
).authorize!
|
230
|
-
|
232
|
+
update(amount: captured_amount)
|
231
233
|
end
|
232
234
|
end
|
233
235
|
|
@@ -252,7 +254,7 @@ module Spree
|
|
252
254
|
return unless store_credit? && source.is_a?(Spree::StoreCredit)
|
253
255
|
|
254
256
|
# creates the store credit event
|
255
|
-
source.
|
257
|
+
source.update!(action: Spree::StoreCredit::ELIGIBLE_ACTION,
|
256
258
|
action_amount: amount,
|
257
259
|
action_authorization_code: response_code)
|
258
260
|
end
|
data/app/models/spree/product.rb
CHANGED
@@ -21,7 +21,8 @@
|
|
21
21
|
module Spree
|
22
22
|
class Product < Spree::Base
|
23
23
|
extend FriendlyId
|
24
|
-
include
|
24
|
+
include Spree::ProductScopes
|
25
|
+
|
25
26
|
friendly_id :slug_candidates, use: :history
|
26
27
|
|
27
28
|
acts_as_paranoid
|
@@ -432,5 +433,3 @@ module Spree
|
|
432
433
|
end
|
433
434
|
end
|
434
435
|
end
|
435
|
-
|
436
|
-
require_dependency 'spree/product/scopes'
|
@@ -25,6 +25,7 @@ module Spree
|
|
25
25
|
|
26
26
|
def remove(coupon_code)
|
27
27
|
promotion = order.promotions.with_coupon_code(coupon_code)
|
28
|
+
|
28
29
|
if promotion.present?
|
29
30
|
# Order promotion has to be destroyed before line item removing
|
30
31
|
order.order_promotions.find_by!(promotion_id: promotion.id).destroy
|
@@ -75,7 +76,7 @@ module Spree
|
|
75
76
|
line_item = order.find_line_item_by_variant(item.variant)
|
76
77
|
next if line_item.blank?
|
77
78
|
|
78
|
-
Spree::Dependencies.cart_remove_item_service
|
79
|
+
Spree::Dependencies.cart_remove_item_service(order: order, item: item.variant, quantity: item.quantity)
|
79
80
|
end
|
80
81
|
end
|
81
82
|
|
@@ -29,7 +29,7 @@ module Spree
|
|
29
29
|
additional_tax_total = percent_of_tax * return_item.inventory_unit.additional_tax_total
|
30
30
|
included_tax_total = percent_of_tax * return_item.inventory_unit.included_tax_total
|
31
31
|
|
32
|
-
return_item.
|
32
|
+
return_item.update!(additional_tax_total: additional_tax_total,
|
33
33
|
included_tax_total: included_tax_total)
|
34
34
|
end
|
35
35
|
end
|
data/app/models/spree/return_item/eligibility_validator/{rma_required.rb → r_m_a_required.rb}
RENAMED
File without changes
|
@@ -307,7 +307,7 @@ module Spree
|
|
307
307
|
|
308
308
|
# Update Shipment and make sure Order states follow the shipment changes
|
309
309
|
def update_attributes_and_order(params = {})
|
310
|
-
if
|
310
|
+
if update params
|
311
311
|
if params.key? :selected_shipping_rate_id
|
312
312
|
# Changing the selected Shipping Rate won't update the cost (for now)
|
313
313
|
# so we persist the Shipment#cost before calculating order shipment
|
@@ -52,9 +52,8 @@ module Spree
|
|
52
52
|
else
|
53
53
|
authorization_code = generate_authorization_code
|
54
54
|
end
|
55
|
-
|
56
55
|
if validate_authorization(amount, order_currency)
|
57
|
-
|
56
|
+
update!(
|
58
57
|
action: AUTHORIZE_ACTION,
|
59
58
|
action_amount: amount,
|
60
59
|
action_originator: options[:action_originator],
|
@@ -85,7 +84,7 @@ module Spree
|
|
85
84
|
errors.add(:base, Spree.t('store_credit_payment_method.currency_mismatch'))
|
86
85
|
false
|
87
86
|
else
|
88
|
-
|
87
|
+
update!(
|
89
88
|
action: CAPTURE_ACTION,
|
90
89
|
action_amount: amount,
|
91
90
|
action_originator: options[:action_originator],
|
@@ -103,7 +102,7 @@ module Spree
|
|
103
102
|
|
104
103
|
def void(authorization_code, options = {})
|
105
104
|
if auth_event = store_credit_events.find_by(action: AUTHORIZE_ACTION, authorization_code: authorization_code)
|
106
|
-
|
105
|
+
update!(
|
107
106
|
action: VOID_ACTION,
|
108
107
|
action_amount: auth_event.amount,
|
109
108
|
action_authorization_code: authorization_code,
|
@@ -209,7 +208,7 @@ module Spree
|
|
209
208
|
store_credit_events.where(action: ALLOCATION_ACTION).first_or_initialize
|
210
209
|
end
|
211
210
|
|
212
|
-
event.
|
211
|
+
event.update!(
|
213
212
|
amount: action_amount || amount,
|
214
213
|
authorization_code: action_authorization_code || event.authorization_code || generate_authorization_code,
|
215
214
|
user_total_amount: user.total_available_store_credit,
|
@@ -35,7 +35,9 @@ module Spree
|
|
35
35
|
|
36
36
|
return failure(line_item) unless line_item.save
|
37
37
|
|
38
|
-
|
38
|
+
line_item.reload.update_price
|
39
|
+
|
40
|
+
::Spree::TaxRate.adjust(order, [line_item]) if line_item_created
|
39
41
|
success(order: order, line_item: line_item, line_item_created: line_item_created, options: options)
|
40
42
|
end
|
41
43
|
end
|
@@ -4,7 +4,7 @@ module Spree
|
|
4
4
|
prepend Spree::ServiceModule::Base
|
5
5
|
|
6
6
|
def call(order:, params:)
|
7
|
-
return failure(order) unless order.
|
7
|
+
return failure(order) unless order.update(filter_order_items(order, params))
|
8
8
|
|
9
9
|
order.line_items = order.line_items.select { |li| li.quantity > 0 }
|
10
10
|
# Update totals, then check if the order is eligible for any cart promotions.
|
data/config/locales/en.yml
CHANGED
@@ -478,6 +478,20 @@ en:
|
|
478
478
|
address1: Address
|
479
479
|
address2: Address (contd.)
|
480
480
|
addresses: Addresses
|
481
|
+
address_book:
|
482
|
+
other_address: "Other address"
|
483
|
+
add_new_shipping_address: "Add new address"
|
484
|
+
new_shipping_address: "New Address"
|
485
|
+
edit_shipping_address: "Edit Address"
|
486
|
+
no_shipping_addresses_on_file: "No addresses on file"
|
487
|
+
shipping_addresses: "Addresses"
|
488
|
+
successfully_created: "Address has been successfully created."
|
489
|
+
successfully_removed: "Address has been successfully removed."
|
490
|
+
successfully_saved: "Saved successfully"
|
491
|
+
unsuccessfully_saved: "There was an error while trying to save your address."
|
492
|
+
successfully_updated: "Updated successfully"
|
493
|
+
unsuccessfully_updated: "There was an update while trying to update your address."
|
494
|
+
save: "Save"
|
481
495
|
adjustable: Adjustable
|
482
496
|
adjustment: Adjustment
|
483
497
|
adjustment_amount: Amount
|
@@ -682,6 +696,7 @@ en:
|
|
682
696
|
date_range: Date Range
|
683
697
|
default: Default
|
684
698
|
default_country_cannot_be_deleted: Default country cannot be deleted
|
699
|
+
default_currency: Default currency
|
685
700
|
default_refund_amount: Default Refund Amount
|
686
701
|
default_tax: Default Tax
|
687
702
|
default_tax_zone: Default Tax Zone
|
data/db/default/spree/stores.rb
CHANGED
data/db/default/spree/zones.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
eu_vat = Spree::Zone.where(name: 'EU_VAT', description: 'Countries that make up the EU VAT zone.', kind: 'country').first_or_create!
|
2
2
|
north_america = Spree::Zone.where(name: 'North America', description: 'USA + Canada', kind: 'country').first_or_create!
|
3
|
+
south_america = Spree::Zone.where(name: 'South America', description: 'South America', kind: 'country').first_or_create!
|
4
|
+
middle_east = Spree::Zone.where(name: 'Middle East', description: 'Middle East', kind: 'country').first_or_create!
|
5
|
+
asia = Spree::Zone.where(name: 'Asia', description: 'Asia', kind: 'country').first_or_create!
|
3
6
|
|
4
7
|
%w(PL FI PT RO DE FR SK HU SI IE AT ES IT BE SE LV BG GB LT CY LU MT DK NL EE HR CZ GR).each do |name|
|
5
8
|
eu_vat.zone_members.where(zoneable: Spree::Country.find_by!(iso: name)).first_or_create!
|
@@ -8,3 +11,16 @@ end
|
|
8
11
|
%w(US CA).each do |name|
|
9
12
|
north_america.zone_members.where(zoneable: Spree::Country.find_by!(iso: name)).first_or_create!
|
10
13
|
end
|
14
|
+
|
15
|
+
%w(BH CY EG IR IQ IL JO KW LB OM QA SA SY TR AE YE).each do |name|
|
16
|
+
middle_east.zone_members.where(zoneable: Spree::Country.find_by!(iso: name)).first_or_create!
|
17
|
+
end
|
18
|
+
|
19
|
+
%w(AF AM AZ BH BD BT BN KH CN CX CC IO GE HK IN ID IR IQ IL JP JO KZ KW KG LA LB MO MY MV MN MM NP
|
20
|
+
KP OM PK PS PH QA SA SG KR LK SY TW TJ TH TR TM AE UZ VN YE).each do |name|
|
21
|
+
asia.zone_members.where(zoneable: Spree::Country.find_by!(iso: name)).first_or_create!
|
22
|
+
end
|
23
|
+
|
24
|
+
%w(AR BO BR CL CO EC FK GF GY PY PE SR UY VE).each do |name|
|
25
|
+
south_america.zone_members.where(zoneable: Spree::Country.find_by!(iso: name)).first_or_create!
|
26
|
+
end
|
@@ -4,6 +4,6 @@ class AddTypeToReimbursementType < ActiveRecord::Migration[4.2]
|
|
4
4
|
add_index :spree_reimbursement_types, :type
|
5
5
|
|
6
6
|
Spree::ReimbursementType.reset_column_information
|
7
|
-
Spree::ReimbursementType.find_by(name: Spree::ReimbursementType::ORIGINAL).
|
7
|
+
Spree::ReimbursementType.find_by(name: Spree::ReimbursementType::ORIGINAL).update!(type: 'Spree::ReimbursementType::OriginalPayment')
|
8
8
|
end
|
9
9
|
end
|
@@ -4,9 +4,9 @@ class FixAdjustmentOrderPresence < ActiveRecord::Migration[4.2]
|
|
4
4
|
Spree::Adjustment.where(order: nil).find_each do |adjustment|
|
5
5
|
adjustable = adjustment.adjustable
|
6
6
|
if adjustable.is_a? Spree::Order
|
7
|
-
adjustment.
|
7
|
+
adjustment.update!(order_id: adjustable.id)
|
8
8
|
else
|
9
|
-
adjustment.
|
9
|
+
adjustment.update!(adjustable: adjustable.order)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -26,7 +26,7 @@ class AddMissingUniqueIndexesForUniqueAttributes < ActiveRecord::Migration[5.0]
|
|
26
26
|
|
27
27
|
remove_index table_name, column if index_exists?(table_name, column)
|
28
28
|
if supports_expression_index?
|
29
|
-
add_index table_name, "lower(#{column})", unique: true
|
29
|
+
add_index table_name, "(lower(#{column}))", unique: true
|
30
30
|
else
|
31
31
|
add_index table_name, column, unique: true
|
32
32
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class AddIsoAndIso3ValidationOnPresenceAndUniqueness < ActiveRecord::Migration[5.2]
|
2
|
+
def up
|
3
|
+
Spree::Country.where.not(id: Spree::Country.group(:iso).select("min(id)")).destroy_all
|
4
|
+
Spree::Country.where.not(id: Spree::Country.group(:iso3).select("min(id)")).destroy_all
|
5
|
+
|
6
|
+
change_column_null(:spree_countries, :iso, false)
|
7
|
+
change_column_null(:spree_countries, :iso3, false)
|
8
|
+
add_index :spree_countries, :iso, unique: true
|
9
|
+
add_index :spree_countries, :iso3, unique: true
|
10
|
+
end
|
11
|
+
|
12
|
+
def down
|
13
|
+
change_column_null(:spree_countries, :iso, true)
|
14
|
+
change_column_null(:spree_countries, :iso3, true)
|
15
|
+
remove_index :spree_countries, :iso, unique: true
|
16
|
+
remove_index :spree_countries, :iso3, unique: true
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# this migration does the same as this two from SpreeAddressBook
|
2
|
+
# https://github.com/spree-contrib/spree_address_book/blob/master/db/migrate/20110302102208_add_user_id_and_deleted_at_to_addresses.rb
|
3
|
+
# https://github.com/spree-contrib/spree_address_book/blob/master/db/migrate/20170405133031_add_missing_indexes.rb
|
4
|
+
class AddUserIdAndDeletedAtToSpreeAddresses < ActiveRecord::Migration[5.2]
|
5
|
+
def change
|
6
|
+
add_column :spree_addresses, :user_id, :integer unless column_exists?(:spree_addresses, :user_id)
|
7
|
+
add_index :spree_addresses, :user_id unless index_exists?(:spree_addresses, :user_id)
|
8
|
+
|
9
|
+
add_column :spree_addresses, :deleted_at, :datetime unless column_exists?(:spree_addresses, :deleted_at)
|
10
|
+
add_index :spree_addresses, :deleted_at unless index_exists?(:spree_addresses, :deleted_at)
|
11
|
+
end
|
12
|
+
end
|
@@ -38,6 +38,8 @@ module Spree
|
|
38
38
|
opts[:skip_spring] = true
|
39
39
|
opts[:skip_test] = true
|
40
40
|
opts[:skip_yarn] = true
|
41
|
+
opts[:skip_javascript] = true
|
42
|
+
opts[:skip_bootsnap] = true
|
41
43
|
|
42
44
|
puts 'Generating dummy Rails application...'
|
43
45
|
invoke Rails::Generators::AppGenerator,
|
@@ -135,7 +137,7 @@ end
|
|
135
137
|
end
|
136
138
|
|
137
139
|
def gemfile_path
|
138
|
-
core_gems = ['spree/core', 'spree/api', 'spree/backend', 'spree/frontend'
|
140
|
+
core_gems = ['spree/core', 'spree/api', 'spree/backend', 'spree/frontend']
|
139
141
|
|
140
142
|
if core_gems.include?(lib_name)
|
141
143
|
'../../../../../Gemfile'
|
data/lib/spree/core.rb
CHANGED
@@ -7,7 +7,6 @@ require 'friendly_id'
|
|
7
7
|
require 'kaminari'
|
8
8
|
require 'mail'
|
9
9
|
require 'monetize'
|
10
|
-
require 'paperclip'
|
11
10
|
require 'paranoia'
|
12
11
|
require 'mini_magick'
|
13
12
|
require 'premailer/rails'
|
@@ -101,7 +100,6 @@ require 'spree/core/product_duplicator'
|
|
101
100
|
require 'spree/core/controller_helpers/auth'
|
102
101
|
require 'spree/core/controller_helpers/common'
|
103
102
|
require 'spree/core/controller_helpers/order'
|
104
|
-
require 'spree/core/controller_helpers/respond_with'
|
105
103
|
require 'spree/core/controller_helpers/search'
|
106
104
|
require 'spree/core/controller_helpers/store'
|
107
105
|
require 'spree/core/controller_helpers/strong_parameters'
|
@@ -26,7 +26,7 @@ module Spree
|
|
26
26
|
|
27
27
|
params.delete(:user_id) unless user.try(:has_spree_role?, 'admin') && params.key?(:user_id)
|
28
28
|
|
29
|
-
order.
|
29
|
+
order.update!(params)
|
30
30
|
|
31
31
|
order.create_proposed_shipments unless shipments_attrs.present?
|
32
32
|
|
@@ -47,41 +47,41 @@ module Spree
|
|
47
47
|
return [] unless shipments_hash
|
48
48
|
|
49
49
|
shipments_hash.each do |s|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
50
|
+
shipment = order.shipments.build
|
51
|
+
shipment.tracking = s[:tracking]
|
52
|
+
shipment.stock_location = Spree::StockLocation.find_by(admin_name: s[:stock_location]) ||
|
53
|
+
Spree::StockLocation.find_by!(name: s[:stock_location])
|
54
|
+
inventory_units = create_inventory_units_from_order_and_params(order, s[:inventory_units])
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
if s[:shipped_at].present?
|
60
|
-
inventory_unit.pending = false
|
61
|
-
inventory_unit.state = 'shipped'
|
62
|
-
end
|
63
|
-
|
64
|
-
inventory_unit.save!
|
65
|
-
end
|
56
|
+
inventory_units.each do |inventory_unit|
|
57
|
+
inventory_unit.shipment = shipment
|
66
58
|
|
67
59
|
if s[:shipped_at].present?
|
68
|
-
|
69
|
-
|
60
|
+
inventory_unit.pending = false
|
61
|
+
inventory_unit.state = 'shipped'
|
70
62
|
end
|
71
63
|
|
72
|
-
|
64
|
+
inventory_unit.save!
|
65
|
+
end
|
66
|
+
|
67
|
+
if s[:shipped_at].present?
|
68
|
+
shipment.shipped_at = s[:shipped_at]
|
69
|
+
shipment.state = 'shipped'
|
70
|
+
end
|
71
|
+
|
72
|
+
shipment.save!
|
73
73
|
|
74
|
-
|
75
|
-
|
74
|
+
shipping_method = Spree::ShippingMethod.find_by(name: s[:shipping_method]) ||
|
75
|
+
Spree::ShippingMethod.find_by!(admin_name: s[:shipping_method])
|
76
|
+
rate = shipment.shipping_rates.create!(shipping_method: shipping_method, cost: s[:cost])
|
76
77
|
|
77
|
-
|
78
|
-
|
78
|
+
shipment.selected_shipping_rate_id = rate.id
|
79
|
+
shipment.update_amounts
|
79
80
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
end
|
81
|
+
adjustments = s.delete(:adjustments_attributes)
|
82
|
+
create_adjustments_from_params(adjustments, order, shipment)
|
83
|
+
rescue Exception => e
|
84
|
+
raise "Order import shipments: #{e.message} #{s}"
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
@@ -101,57 +101,22 @@ module Spree
|
|
101
101
|
def self.create_line_items_from_params(line_items, order)
|
102
102
|
return {} unless line_items
|
103
103
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
{ "variant_id": 456, "quantity": 1 }
|
117
|
-
]
|
118
|
-
}
|
119
|
-
}
|
120
|
-
|
121
|
-
Old Syntax:
|
122
|
-
|
123
|
-
{
|
124
|
-
"order": {
|
125
|
-
"line_items": {
|
126
|
-
"1": { "variant_id": 123, "quantity": 1 },
|
127
|
-
"2": { "variant_id": 123, "quantity": 1 }
|
128
|
-
}
|
129
|
-
}
|
130
|
-
}
|
131
|
-
DEPRECATION
|
132
|
-
:each_value
|
133
|
-
when Array
|
134
|
-
:each
|
135
|
-
end
|
136
|
-
|
137
|
-
line_items.send(iterator) do |line_item|
|
138
|
-
begin
|
139
|
-
adjustments = line_item.delete(:adjustments_attributes)
|
140
|
-
extra_params = line_item.except(:variant_id, :quantity, :sku)
|
141
|
-
line_item = ensure_variant_id_from_params(line_item)
|
142
|
-
variant = Spree::Variant.find(line_item[:variant_id])
|
143
|
-
line_item = Cart::AddItem.call(order: order, variant: variant, quantity: line_item[:quantity]).value
|
144
|
-
# Raise any errors with saving to prevent import succeeding with line items
|
145
|
-
# failing silently.
|
146
|
-
if extra_params.present?
|
147
|
-
line_item.update_attributes!(extra_params)
|
148
|
-
else
|
149
|
-
line_item.save!
|
150
|
-
end
|
151
|
-
create_adjustments_from_params(adjustments, order, line_item)
|
152
|
-
rescue Exception => e
|
153
|
-
raise "Order import line items: #{e.message} #{line_item}"
|
104
|
+
line_items.each do |line_item|
|
105
|
+
adjustments = line_item.delete(:adjustments_attributes)
|
106
|
+
extra_params = line_item.except(:variant_id, :quantity, :sku)
|
107
|
+
line_item = ensure_variant_id_from_params(line_item)
|
108
|
+
variant = Spree::Variant.find(line_item[:variant_id])
|
109
|
+
line_item = Cart::AddItem.call(order: order, variant: variant, quantity: line_item[:quantity]).value
|
110
|
+
# Raise any errors with saving to prevent import succeeding with line items
|
111
|
+
# failing silently.
|
112
|
+
if extra_params.present?
|
113
|
+
line_item.update!(extra_params)
|
114
|
+
else
|
115
|
+
line_item.save!
|
154
116
|
end
|
117
|
+
create_adjustments_from_params(adjustments, order, line_item)
|
118
|
+
rescue Exception => e
|
119
|
+
raise "Order import line items: #{e.message} #{line_item}"
|
155
120
|
end
|
156
121
|
end
|
157
122
|
|
@@ -159,18 +124,16 @@ module Spree
|
|
159
124
|
return [] unless adjustments
|
160
125
|
|
161
126
|
adjustments.each do |a|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
raise "Order import adjustments: #{e.message} #{a}"
|
173
|
-
end
|
127
|
+
adjustment = (adjustable || order).adjustments.build(
|
128
|
+
order: order,
|
129
|
+
amount: a[:amount].to_f,
|
130
|
+
label: a[:label],
|
131
|
+
source_type: source_type_from_adjustment(a)
|
132
|
+
)
|
133
|
+
adjustment.save!
|
134
|
+
adjustment.close!
|
135
|
+
rescue Exception => e
|
136
|
+
raise "Order import adjustments: #{e.message} #{a}"
|
174
137
|
end
|
175
138
|
end
|
176
139
|
|
@@ -178,19 +141,17 @@ module Spree
|
|
178
141
|
return [] unless payments_hash
|
179
142
|
|
180
143
|
payments_hash.each do |p|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
raise "Order import payments: #{e.message} #{p}"
|
193
|
-
end
|
144
|
+
payment = order.payments.build order: order
|
145
|
+
payment.amount = p[:amount].to_f
|
146
|
+
# Order API should be using state as that's the normal payment field.
|
147
|
+
# spree_wombat serializes payment state as status so imported orders should fall back to status field.
|
148
|
+
payment.state = p[:state] || p[:status] || 'completed'
|
149
|
+
payment.created_at = p[:created_at] if p[:created_at]
|
150
|
+
payment.payment_method = Spree::PaymentMethod.find_by!(name: p[:payment_method])
|
151
|
+
payment.source = create_source_payment_from_params(p[:source], payment) if p[:source]
|
152
|
+
payment.save!
|
153
|
+
rescue Exception => e
|
154
|
+
raise "Order import payments: #{e.message} #{p}"
|
194
155
|
end
|
195
156
|
end
|
196
157
|
|