spree_core 4.2.5 → 4.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/finders/concerns/spree/product_filterable.rb +9 -0
- data/app/finders/spree/cms_pages/find.rb +41 -0
- data/app/finders/spree/menus/find.rb +11 -0
- data/app/finders/spree/option_values/find_available.rb +20 -0
- data/app/finders/spree/orders/find_complete.rb +14 -2
- data/app/finders/spree/orders/find_current.rb +1 -13
- data/app/finders/spree/product_properties/find_available.rb +20 -0
- data/app/finders/spree/products/find.rb +80 -21
- data/app/finders/spree/stores/find_current.rb +24 -0
- data/app/finders/spree/taxons/find.rb +22 -6
- data/app/helpers/spree/base_helper.rb +69 -7
- data/app/helpers/spree/locale_helper.rb +5 -1
- data/app/helpers/spree/products_helper.rb +7 -3
- data/app/models/concerns/spree/display_link.rb +42 -0
- data/app/models/concerns/spree/display_money.rb +6 -2
- data/app/models/concerns/spree/filter_param.rb +21 -0
- data/app/models/concerns/spree/image_methods.rb +24 -0
- data/app/models/concerns/spree/memoized_data.rb +24 -0
- data/app/models/concerns/spree/multi_store_resource.rb +24 -0
- data/app/models/concerns/spree/product_scopes.rb +71 -8
- data/app/models/concerns/spree/single_store_resource.rb +19 -0
- data/app/models/concerns/spree/user_address.rb +19 -0
- data/app/models/concerns/spree/user_methods.rb +14 -12
- data/app/models/concerns/spree/user_payment_source.rb +1 -1
- data/app/models/concerns/spree/user_reporting.rb +35 -10
- data/app/models/concerns/spree/user_roles.rb +25 -0
- data/app/models/spree/ability.rb +3 -1
- data/app/models/spree/address.rb +27 -6
- data/app/models/spree/app_configuration.rb +8 -0
- data/app/models/spree/app_dependencies.rb +20 -6
- data/app/models/spree/base.rb +18 -0
- data/app/models/spree/classification.rb +3 -0
- data/app/models/spree/cms/pages/feature_page.rb +7 -0
- data/app/models/spree/cms/pages/homepage.rb +20 -0
- data/app/models/spree/cms/pages/standard_page.rb +4 -0
- data/app/models/spree/cms/sections/featured_article.rb +22 -0
- data/app/models/spree/cms/sections/hero_image.rb +38 -0
- data/app/models/spree/cms/sections/image_gallery.rb +103 -0
- data/app/models/spree/cms/sections/product_carousel.rb +14 -0
- data/app/models/spree/cms/sections/rich_text_content.rb +13 -0
- data/app/models/spree/cms/sections/side_by_side_images.rb +74 -0
- data/app/models/spree/cms_page.rb +66 -0
- data/app/models/spree/cms_section.rb +69 -0
- data/app/models/spree/country.rb +14 -6
- data/app/models/spree/credit_card.rb +2 -8
- data/app/models/spree/customer_return.rb +8 -2
- data/app/models/spree/gateway/bogus.rb +6 -4
- data/app/models/spree/icon.rb +9 -0
- data/app/models/spree/image/configuration/active_storage.rb +2 -0
- data/app/models/spree/image.rb +5 -24
- data/app/models/spree/inventory_unit.rb +1 -1
- data/app/models/spree/line_item.rb +1 -1
- data/app/models/spree/menu.rb +63 -0
- data/app/models/spree/menu_item.rb +76 -0
- data/app/models/spree/option_type.rb +1 -1
- data/app/models/spree/option_value.rb +11 -0
- data/app/models/spree/option_value_variant.rb +1 -1
- data/app/models/spree/order/address_book.rb +3 -5
- data/app/models/spree/order/currency_updater.rb +1 -1
- data/app/models/spree/order/emails.rb +32 -0
- data/app/models/spree/order/payments.rb +1 -1
- data/app/models/spree/order/store_credit.rb +1 -1
- data/app/models/spree/order.rb +46 -45
- data/app/models/spree/payment.rb +7 -0
- data/app/models/spree/payment_method.rb +16 -0
- data/app/models/spree/preferences/preferable.rb +12 -0
- data/app/models/spree/preferences/preferable_class_methods.rb +10 -1
- data/app/models/spree/product.rb +37 -30
- data/app/models/spree/product_property.rb +19 -4
- data/app/models/spree/promotion/rules/country.rb +1 -1
- data/app/models/spree/promotion/rules/first_order.rb +4 -3
- data/app/models/spree/promotion/rules/taxon.rb +10 -7
- data/app/models/spree/promotion.rb +6 -15
- data/app/models/spree/promotion_handler/cart.rb +7 -2
- data/app/models/spree/promotion_handler/coupon.rb +5 -4
- data/app/models/spree/promotion_handler/free_shipping.rb +5 -6
- data/app/models/spree/promotion_handler/page.rb +3 -2
- data/app/models/spree/promotion_handler/promotion_duplicator.rb +1 -0
- data/app/models/spree/promotion_rule.rb +2 -0
- data/app/models/spree/property.rb +28 -1
- data/app/models/spree/reimbursement.rb +3 -1
- data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +2 -1
- data/app/models/spree/shipment_handler.rb +4 -2
- data/app/models/spree/stock/quantifier.rb +6 -6
- data/app/models/spree/stock_location.rb +9 -0
- data/app/models/spree/store.rb +90 -7
- data/app/models/spree/store_credit.rb +7 -3
- data/app/models/spree/store_credit_event.rb +2 -2
- data/app/models/spree/store_payment_method.rb +11 -0
- data/app/models/spree/store_product.rb +11 -0
- data/app/models/spree/store_promotion.rb +11 -0
- data/app/models/spree/taxon.rb +22 -1
- data/app/models/spree/taxon_image/configuration/active_storage.rb +2 -0
- data/app/models/spree/taxon_image.rb +1 -0
- data/app/models/spree/taxonomy.rb +3 -1
- data/app/models/spree/variant.rb +21 -6
- data/app/presenters/spree/filters/options_presenter.rb +47 -0
- data/app/presenters/spree/filters/price_presenter.rb +22 -0
- data/app/presenters/spree/filters/price_range_presenter.rb +29 -0
- data/app/presenters/spree/filters/properties_presenter.rb +23 -0
- data/app/presenters/spree/filters/property_presenter.rb +42 -0
- data/app/presenters/spree/filters/quantified_price_range_presenter.rb +44 -0
- data/app/services/spree/account/addresses/create.rb +1 -0
- data/app/services/spree/account/addresses/helper.rb +6 -0
- data/app/services/spree/account/addresses/update.rb +9 -3
- data/app/services/spree/account/create.rb +17 -0
- data/app/services/spree/account/update.rb +15 -0
- data/app/services/spree/build_localized_redirect_url.rb +1 -1
- data/app/services/spree/cart/associate.rb +16 -0
- data/app/services/spree/cart/change_currency.rb +27 -0
- data/app/services/spree/cart/create.rb +5 -3
- data/app/services/spree/cart/destroy.rb +40 -0
- data/app/services/spree/cart/empty.rb +36 -0
- data/app/services/spree/cart/estimate_shipping_rates.rb +3 -3
- data/app/services/spree/checkout/add_store_credit.rb +1 -1
- data/app/services/spree/classifications/reposition.rb +18 -0
- data/app/services/spree/credit_cards/destroy.rb +41 -0
- data/app/sorters/spree/base_sorter.rb +23 -11
- data/app/sorters/spree/products/sort.rb +23 -7
- data/app/validators/db_maximum_length_validator.rb +5 -0
- data/app/validators/email_validator.rb +3 -1
- data/config/initializers/active_storage.rb +2 -0
- data/config/locales/en.yml +177 -3
- data/config/routes.rb +0 -5
- data/db/migrate/20201023152810_add_filterable_to_spree_properties.rb +8 -0
- data/db/migrate/20210407200948_create_spree_menus.rb +16 -0
- data/db/migrate/20210408092939_create_spree_menu_items.rb +31 -0
- data/db/migrate/20210504163720_add_filter_param_to_spree_product_properties.rb +8 -0
- data/db/migrate/20210505114659_add_filter_param_to_spree_properties.rb +8 -0
- data/db/migrate/20210512191732_create_spree_cms_pages.rb +24 -0
- data/db/migrate/20210514204251_create_spree_cms_sections.rb +22 -0
- data/db/migrate/20210527094055_create_spree_products_stores.rb +36 -0
- data/db/migrate/20210608045519_ensure_store_default_country_is_set.rb +5 -0
- data/db/migrate/20210702112334_add_missing_timestamp_columns.rb +46 -0
- data/db/migrate/20210713131614_add_unique_index_on_property_id_and_product_id_to_product_properties.rb +29 -0
- data/db/migrate/20210715091956_add_store_id_to_spree_store_credits.rb +10 -0
- data/db/migrate/20210716093151_add_store_id_to_spree_taxonomies.rb +11 -0
- data/db/migrate/20210716104141_add_index_on_name_parent_id_and_taxonomy_id_on_spree_taxons.rb +31 -0
- data/db/migrate/20210721120857_add_index_on_permalink_parent_id_and_taxonomy_id_on_spree_taxons.rb +31 -0
- data/db/migrate/20210721125657_create_spree_promotions_stores.rb +29 -0
- data/db/migrate/20210722090705_add_store_id_to_spree_customer_returns.rb +11 -0
- data/db/migrate/20210726065456_change_integer_id_columns_into_bigint.rb +305 -0
- data/db/migrate/20210730154425_fix_promotion_code_and_path_unique_indexes.rb +9 -0
- data/lib/generators/spree/dummy/dummy_generator.rb +11 -6
- data/lib/generators/spree/dummy/templates/rails/test.rb +2 -0
- data/lib/generators/spree/dummy_model/templates/model.rb.tt +1 -1
- data/lib/generators/spree/install/install_generator.rb +12 -24
- data/lib/spree/core/components.rb +8 -0
- data/lib/spree/core/controller_helpers/auth.rb +7 -1
- data/lib/spree/core/controller_helpers/common.rb +1 -1
- data/lib/spree/core/controller_helpers/order.rb +4 -4
- data/lib/spree/core/controller_helpers/search.rb +1 -0
- data/lib/spree/core/controller_helpers/store.rb +24 -1
- data/lib/spree/core/engine.rb +6 -0
- data/lib/spree/core/importer/product.rb +3 -1
- data/lib/spree/core/product_duplicator.rb +1 -0
- data/lib/spree/core/search/base.rb +17 -22
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/core.rb +8 -4
- data/lib/spree/i18n.rb +1 -1
- data/lib/spree/money.rb +2 -1
- data/lib/spree/permitted_attributes.rb +21 -3
- data/lib/spree/testing_support/authorization_helpers.rb +6 -3
- data/lib/spree/testing_support/capybara_config.rb +3 -1
- data/lib/spree/testing_support/common_rake.rb +17 -4
- data/lib/spree/testing_support/extension_rake.rb +2 -2
- data/lib/spree/testing_support/factories/address_factory.rb +1 -1
- data/lib/spree/testing_support/factories/classification_factory.rb +8 -0
- data/lib/spree/testing_support/factories/cms_page_factory.rb +20 -0
- data/lib/spree/testing_support/factories/cms_section_factory.rb +31 -0
- data/lib/spree/testing_support/factories/customer_return_factory.rb +24 -17
- data/lib/spree/testing_support/factories/icon_factory.rb +7 -0
- data/lib/spree/testing_support/factories/line_item_factory.rb +6 -2
- data/lib/spree/testing_support/factories/menu_factory.rb +16 -0
- data/lib/spree/testing_support/factories/menu_item_factory.rb +10 -0
- data/lib/spree/testing_support/factories/options_factory.rb +5 -0
- data/lib/spree/testing_support/factories/order_factory.rb +11 -2
- data/lib/spree/testing_support/factories/payment_method_factory.rb +6 -2
- data/lib/spree/testing_support/factories/product_factory.rb +17 -1
- data/lib/spree/testing_support/factories/product_property_factory.rb +1 -1
- data/lib/spree/testing_support/factories/promotion_factory.rb +18 -9
- data/lib/spree/testing_support/factories/property_factory.rb +22 -0
- data/lib/spree/testing_support/factories/stock_location_factory.rb +5 -4
- data/lib/spree/testing_support/factories/store_credit_factory.rb +1 -0
- data/lib/spree/testing_support/factories/store_factory.rb +11 -0
- data/lib/spree/testing_support/factories/taxon_factory.rb +3 -1
- data/lib/spree/testing_support/factories/taxon_image_factory.rb +7 -0
- data/lib/spree/testing_support/factories/taxonomy_factory.rb +1 -0
- data/lib/spree/testing_support/factories/user_factory.rb +7 -2
- data/lib/spree/testing_support/factories/variant_factory.rb +2 -2
- data/lib/spree/testing_support/flatpickr_capybara.rb +58 -35
- data/lib/spree/testing_support/locale_helpers.rb +1 -1
- data/lib/spree/testing_support/order_walkthrough.rb +9 -9
- data/lib/spree/testing_support/rspec_retry_config.rb +5 -0
- data/lib/tasks/core.rake +1 -1
- data/spec/fixtures/favicon.ico +0 -0
- data/spec/fixtures/files/icon_256x256.gif +0 -0
- data/spec/fixtures/files/icon_256x256.png +0 -0
- data/spec/fixtures/files/icon_512x512.png +0 -0
- data/spec/fixtures/files/img_256x128.png +0 -0
- data/spree_core.gemspec +12 -11
- metadata +211 -159
- data/app/assets/images/logo/spree_50.png +0 -0
- data/app/assets/images/noimage/large.png +0 -0
- data/app/assets/images/noimage/mini.png +0 -0
- data/app/assets/images/noimage/product.png +0 -0
- data/app/assets/images/noimage/small.png +0 -0
- data/app/assets/javascripts/spree.js +0 -78
- data/app/controllers/spree/errors_controller.rb +0 -11
- data/app/helpers/spree/mail_helper.rb +0 -29
- data/app/mailers/spree/base_mailer.rb +0 -46
- data/app/mailers/spree/order_mailer.rb +0 -26
- data/app/mailers/spree/reimbursement_mailer.rb +0 -12
- data/app/mailers/spree/shipment_mailer.rb +0 -12
- data/app/mailers/spree/test_mailer.rb +0 -8
- data/app/models/spree/validations/db_maximum_length_validator.rb +0 -22
- data/app/views/layouts/spree/base_mailer.html.erb +0 -46
- data/app/views/spree/errors/forbidden.html.erb +0 -0
- data/app/views/spree/errors/unauthorized.html.erb +0 -0
- data/app/views/spree/order_mailer/cancel_email.html.erb +0 -24
- data/app/views/spree/order_mailer/cancel_email.text.erb +0 -38
- data/app/views/spree/order_mailer/confirm_email.html.erb +0 -23
- data/app/views/spree/order_mailer/confirm_email.text.erb +0 -39
- data/app/views/spree/order_mailer/store_owner_notification_email.html.erb +0 -23
- data/app/views/spree/order_mailer/store_owner_notification_email.text.erb +0 -38
- data/app/views/spree/reimbursement_mailer/reimbursement_email.html.erb +0 -56
- data/app/views/spree/reimbursement_mailer/reimbursement_email.text.erb +0 -24
- data/app/views/spree/shared/_base_mailer_footer.html.erb +0 -12
- data/app/views/spree/shared/_base_mailer_header.html.erb +0 -13
- data/app/views/spree/shared/_base_mailer_stylesheets.html.erb +0 -456
- data/app/views/spree/shared/_error_messages.html.erb +0 -11
- data/app/views/spree/shared/_mailer_line_item.html.erb +0 -16
- data/app/views/spree/shared/_paths.html.erb +0 -8
- data/app/views/spree/shared/_purchased_items_table.html.erb +0 -69
- data/app/views/spree/shared/purchased_items_table/_adjustment.html.erb +0 -13
- data/app/views/spree/shared/purchased_items_table/_line_item.html.erb +0 -27
- data/app/views/spree/shared/purchased_items_table/_subtotal.html.erb +0 -13
- data/app/views/spree/shared/purchased_items_table/_total.html.erb +0 -13
- data/app/views/spree/shipment_mailer/shipped_email.html.erb +0 -36
- data/app/views/spree/shipment_mailer/shipped_email.text.erb +0 -17
- data/app/views/spree/test_mailer/test_email.html.erb +0 -40
- data/app/views/spree/test_mailer/test_email.text.erb +0 -4
- data/config/initializers/assets.rb +0 -2
- data/config/initializers/premailer_assets.rb +0 -1
- data/config/initializers/premailer_rails.rb +0 -3
- data/db/migrate/20140805171219_make_existing_credit_cards_default.rb +0 -10
- data/lib/generators/spree/dummy/templates/initializers/bullet.rb +0 -5
- data/lib/generators/spree/install/templates/vendor/assets/javascripts/spree/backend/all.js +0 -15
- data/lib/generators/spree/install/templates/vendor/assets/javascripts/spree/frontend/all.js +0 -16
- data/lib/generators/spree/install/templates/vendor/assets/stylesheets/spree/backend/all.css +0 -16
- data/lib/generators/spree/install/templates/vendor/assets/stylesheets/spree/frontend/all.css +0 -16
- data/lib/generators/spree/mailers_preview/mailers_preview_generator.rb +0 -23
- data/lib/generators/spree/mailers_preview/templates/mailers/previews/order_preview.rb +0 -13
- data/lib/generators/spree/mailers_preview/templates/mailers/previews/reimbursement_preview.rb +0 -5
- data/lib/generators/spree/mailers_preview/templates/mailers/previews/shipment_preview.rb +0 -5
- data/lib/generators/spree/mailers_preview/templates/mailers/previews/user_preview.rb +0 -11
- data/lib/tasks/email.rake +0 -10
- data/vendor/assets/javascripts/cleave.js +0 -1669
- data/vendor/assets/javascripts/fetch.umd.js +0 -531
- data/vendor/assets/javascripts/jquery.payment.js +0 -652
- data/vendor/assets/javascripts/jsuri.js +0 -458
- data/vendor/assets/javascripts/polyfill.min.js +0 -1
@@ -0,0 +1,22 @@
|
|
1
|
+
module Spree
|
2
|
+
module Filters
|
3
|
+
class PricePresenter
|
4
|
+
def initialize(amount:, currency:)
|
5
|
+
@amount = amount.to_i
|
6
|
+
@currency = currency
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_i
|
10
|
+
amount
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
Spree::Money.new(amount, currency: currency, no_cents_if_whole: true).to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader :amount, :currency
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Spree
|
2
|
+
module Filters
|
3
|
+
class PriceRangePresenter
|
4
|
+
def self.from_param(param, currency:)
|
5
|
+
prices = param.split('-')
|
6
|
+
|
7
|
+
new(
|
8
|
+
min_price: PricePresenter.new(amount: prices.first, currency: currency),
|
9
|
+
max_price: PricePresenter.new(amount: prices.last, currency: currency)
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(min_price:, max_price:)
|
14
|
+
@min_price = min_price
|
15
|
+
@max_price = max_price
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_reader :min_price, :max_price
|
19
|
+
|
20
|
+
def to_param
|
21
|
+
"#{min_price.to_i}-#{max_price.to_i}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_s
|
25
|
+
"#{min_price} - #{max_price}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Spree
|
2
|
+
module Filters
|
3
|
+
class PropertiesPresenter
|
4
|
+
def initialize(product_properties_scope:)
|
5
|
+
@product_properties = product_properties_scope.includes(:property)
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_a
|
9
|
+
grouped_options.map do |property, product_properties|
|
10
|
+
PropertyPresenter.new(property: property, product_properties: product_properties)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
attr_reader :product_properties
|
17
|
+
|
18
|
+
def grouped_options
|
19
|
+
product_properties.group_by(&:property)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Spree
|
2
|
+
module Filters
|
3
|
+
class PropertyPresenter
|
4
|
+
def initialize(property:, product_properties:)
|
5
|
+
@property = property
|
6
|
+
@product_properties = product_properties
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :product_properties
|
10
|
+
|
11
|
+
delegate_missing_to :property
|
12
|
+
|
13
|
+
def uniq_values
|
14
|
+
property.uniq_values(product_properties_scope: product_properties)
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_h
|
18
|
+
{
|
19
|
+
id: property.id,
|
20
|
+
name: property.name,
|
21
|
+
presentation: property.presentation,
|
22
|
+
values: values_hash
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_reader :property
|
29
|
+
|
30
|
+
def values_hash
|
31
|
+
value_hashes = uniq_values.map do |filter_param, value|
|
32
|
+
{
|
33
|
+
value: value,
|
34
|
+
filter_param: filter_param
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
value_hashes.sort_by { |e| e[:value] }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Spree
|
2
|
+
module Filters
|
3
|
+
class QuantifiedPriceRangePresenter
|
4
|
+
ALLOWED_QUANTIFIERS = [
|
5
|
+
:less_than,
|
6
|
+
:more_than
|
7
|
+
].freeze
|
8
|
+
|
9
|
+
def initialize(price:, quantifier:)
|
10
|
+
if ALLOWED_QUANTIFIERS.exclude?(quantifier.to_sym)
|
11
|
+
raise ArgumentError, "quantifier must be one of: #{ALLOWED_QUANTIFIERS.join(', ')}"
|
12
|
+
end
|
13
|
+
|
14
|
+
@price = price
|
15
|
+
@quantifier = quantifier.to_sym
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_param
|
19
|
+
case quantifier
|
20
|
+
when :less_than
|
21
|
+
less_than_param
|
22
|
+
when :more_than
|
23
|
+
more_than_param
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_s
|
28
|
+
"#{I18n.t("activerecord.attributes.spree/product.#{quantifier}")} #{price}"
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
attr_reader :price, :quantifier
|
34
|
+
|
35
|
+
def less_than_param
|
36
|
+
"0-#{price.to_i}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def more_than_param
|
40
|
+
"#{price.to_i}-Infinity"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -31,6 +31,12 @@ module Spree
|
|
31
31
|
params[:state_id] = country.states.find_by(name: state_name)&.id
|
32
32
|
params
|
33
33
|
end
|
34
|
+
|
35
|
+
def assign_to_user_as_default(user:, address_id:)
|
36
|
+
if user.addresses.pluck(:id) == [address_id] # check if it's user first address
|
37
|
+
user.update(bill_address_id: address_id, ship_address_id: address_id)
|
38
|
+
end
|
39
|
+
end
|
34
40
|
end
|
35
41
|
end
|
36
42
|
end
|
@@ -11,12 +11,18 @@ module Spree
|
|
11
11
|
address_params[:country_id] ||= address.country_id
|
12
12
|
fill_country_and_state_ids(address_params)
|
13
13
|
|
14
|
-
if address
|
15
|
-
success(address)
|
14
|
+
if address&.editable?
|
15
|
+
address.update(address_params) ? success(address) : failure(address)
|
16
16
|
else
|
17
|
-
|
17
|
+
new_address(address_params).valid? ? address.destroy && success(new_address) : failure(new_address)
|
18
18
|
end
|
19
19
|
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def new_address(address_params = {})
|
24
|
+
@new_address ||= ::Spree::Address.find_or_create_by(address_params.except(:id, :updated_at, :created_at))
|
25
|
+
end
|
20
26
|
end
|
21
27
|
end
|
22
28
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Spree
|
2
|
+
module Account
|
3
|
+
class Create
|
4
|
+
prepend Spree::ServiceModule::Base
|
5
|
+
|
6
|
+
def call(user_params: {})
|
7
|
+
user = Spree.user_class.new(user_params)
|
8
|
+
|
9
|
+
if user.save
|
10
|
+
success(user)
|
11
|
+
else
|
12
|
+
failure(user)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -6,7 +6,7 @@ module Spree
|
|
6
6
|
|
7
7
|
LOCALE_REGEX = /^\/[A-Za-z]{2}\/|^\/[A-Za-z]{2}-[A-Za-z]{2}\/|^\/[A-Za-z]{2}$|^\/[A-Za-z]{2}-[A-Za-z]{2}$/.freeze
|
8
8
|
|
9
|
-
SUPPORTED_PATHS_REGEX = /\/(
|
9
|
+
SUPPORTED_PATHS_REGEX = /\/(#{Spree::Config[:storefront_products_path]}|#{Spree::Config[:storefront_taxons_path]}\/|cart|checkout|addresses|content|#{Spree::Config[:storefront_pages_path]})/.freeze
|
10
10
|
|
11
11
|
# rubocop:disable Lint/UnusedMethodArgument
|
12
12
|
def call(url:, locale:, default_locale: nil)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Spree
|
2
|
+
module Cart
|
3
|
+
class Associate
|
4
|
+
prepend Spree::ServiceModule::Base
|
5
|
+
|
6
|
+
def call(guest_order:, user:)
|
7
|
+
if guest_order.user.nil?
|
8
|
+
guest_order.associate_user!(user)
|
9
|
+
success(guest_order)
|
10
|
+
else
|
11
|
+
failure(guest_order, 'Already assigned to a user')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Spree
|
2
|
+
module Cart
|
3
|
+
class ChangeCurrency
|
4
|
+
prepend Spree::ServiceModule::Base
|
5
|
+
|
6
|
+
def call(order:, new_currency:)
|
7
|
+
return failure('Currency not supported') unless supported_currency?(order, new_currency)
|
8
|
+
|
9
|
+
result = order.update!(currency: new_currency) rescue false
|
10
|
+
|
11
|
+
if result
|
12
|
+
success(order)
|
13
|
+
else
|
14
|
+
failure('Failed to update order')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def supported_currency?(order, currency)
|
21
|
+
store = order.store
|
22
|
+
supported_currencies = store.supported_currencies_list
|
23
|
+
supported_currencies.map(&:iso_code).include?(currency.upcase)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -6,14 +6,16 @@ module Spree
|
|
6
6
|
def call(user:, store:, currency:, order_params: nil)
|
7
7
|
order_params ||= {}
|
8
8
|
|
9
|
+
# we cannot create an order without store
|
10
|
+
return failure(:store_is_required) if store.nil?
|
11
|
+
|
9
12
|
default_params = {
|
10
13
|
user: user,
|
11
|
-
|
12
|
-
currency: currency,
|
14
|
+
currency: currency || store.default_currency,
|
13
15
|
token: Spree::GenerateToken.new.call(Spree::Order)
|
14
16
|
}
|
15
17
|
|
16
|
-
order =
|
18
|
+
order = store.orders.create!(default_params.merge(order_params))
|
17
19
|
success(order)
|
18
20
|
end
|
19
21
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Spree
|
2
|
+
module Cart
|
3
|
+
class Destroy
|
4
|
+
prepend Spree::ServiceModule::Base
|
5
|
+
|
6
|
+
def call(order:)
|
7
|
+
run :check_if_can_be_destroyed
|
8
|
+
run :cancel_shipments
|
9
|
+
run :void_payments
|
10
|
+
run :destroy_order
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def check_if_can_be_destroyed(order:)
|
16
|
+
return failure(Spree.t(:cannot_be_destroyed)) unless order&.can_be_destroyed?
|
17
|
+
|
18
|
+
success(order: order)
|
19
|
+
end
|
20
|
+
|
21
|
+
def cancel_shipments(order:)
|
22
|
+
order.shipments.each(&:cancel!)
|
23
|
+
|
24
|
+
success(order: order)
|
25
|
+
end
|
26
|
+
|
27
|
+
def void_payments(order:)
|
28
|
+
order.payments.each(&:void!)
|
29
|
+
|
30
|
+
success(order: order)
|
31
|
+
end
|
32
|
+
|
33
|
+
def destroy_order(order:)
|
34
|
+
order.destroy
|
35
|
+
|
36
|
+
success(order)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Spree
|
2
|
+
module Cart
|
3
|
+
class Empty
|
4
|
+
prepend Spree::ServiceModule::Base
|
5
|
+
|
6
|
+
def call(order:)
|
7
|
+
run :check_if_can_be_empty
|
8
|
+
run :empty_order
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def check_if_can_be_empty(order:)
|
14
|
+
return failure(Spree.t(:cannot_empty)) if order.nil? || order.completed?
|
15
|
+
|
16
|
+
success(order: order)
|
17
|
+
end
|
18
|
+
|
19
|
+
def empty_order(order:)
|
20
|
+
ActiveRecord::Base.transaction do
|
21
|
+
order.line_items.destroy_all
|
22
|
+
order.updater.update_item_count
|
23
|
+
order.adjustments.destroy_all
|
24
|
+
order.shipments.destroy_all
|
25
|
+
order.state_changes.destroy_all
|
26
|
+
order.order_promotions.destroy_all
|
27
|
+
order.update_totals
|
28
|
+
order.persist_totals
|
29
|
+
order.restart_checkout_flow
|
30
|
+
|
31
|
+
success(order)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -4,7 +4,7 @@ module Spree
|
|
4
4
|
prepend Spree::ServiceModule::Base
|
5
5
|
|
6
6
|
def call(order:, country_iso: nil)
|
7
|
-
country_id = country_id(country_iso)
|
7
|
+
country_id = country_id(order.store, country_iso)
|
8
8
|
dummy_order = generate_dummy_order(order, country_id)
|
9
9
|
|
10
10
|
packages = ::Spree::Stock::Coordinator.new(dummy_order).packages
|
@@ -20,11 +20,11 @@ module Spree
|
|
20
20
|
|
21
21
|
private
|
22
22
|
|
23
|
-
def country_id(country_iso)
|
23
|
+
def country_id(store, country_iso)
|
24
24
|
if country_iso.present?
|
25
25
|
::Spree::Country.by_iso(country_iso)&.id
|
26
26
|
else
|
27
|
-
|
27
|
+
store.default_country_id
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -23,7 +23,7 @@ module Spree
|
|
23
23
|
payment_method = Spree::PaymentMethod::StoreCredit.available.first
|
24
24
|
raise 'Store credit payment method could not be found' unless payment_method
|
25
25
|
|
26
|
-
@order.user.store_credits.order_by_priority.each do |credit|
|
26
|
+
@order.user.store_credits.for_store(@order.store).order_by_priority.each do |credit|
|
27
27
|
break if remaining_total.zero?
|
28
28
|
next if credit.amount_remaining.zero?
|
29
29
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Spree
|
2
|
+
module Classifications
|
3
|
+
class Reposition
|
4
|
+
prepend Spree::ServiceModule::Base
|
5
|
+
|
6
|
+
def call(classification:, position:)
|
7
|
+
if position.is_a?(String) && !position.match(/^\d+$/)
|
8
|
+
return failure(nil, I18n.t('errors.messages.not_a_number'))
|
9
|
+
end
|
10
|
+
|
11
|
+
# Because position we get back is 0-indexed.
|
12
|
+
# acts_as_list is 1-indexed.
|
13
|
+
classification.insert_at(position.to_i + 1)
|
14
|
+
success(classification)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|