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
@@ -9,6 +9,25 @@ module Spree
|
|
9
9
|
end.sort_by { |c| c.name.parameterize }
|
10
10
|
end
|
11
11
|
|
12
|
+
def all_countries
|
13
|
+
countries = Spree::Country.all
|
14
|
+
|
15
|
+
countries.collect do |country|
|
16
|
+
country.name = Spree.t(country.iso, scope: 'country_names', default: country.name)
|
17
|
+
country
|
18
|
+
end.sort_by { |c| c.name.parameterize }
|
19
|
+
end
|
20
|
+
|
21
|
+
def spree_resource_path(resource)
|
22
|
+
last_word = resource.class.name.split('::', 10).last
|
23
|
+
|
24
|
+
spree_class_name_as_path(last_word)
|
25
|
+
end
|
26
|
+
|
27
|
+
def spree_class_name_as_path(class_name)
|
28
|
+
class_name.underscore.humanize.parameterize(separator: '_')
|
29
|
+
end
|
30
|
+
|
12
31
|
def display_price(product_or_variant)
|
13
32
|
product_or_variant.
|
14
33
|
price_in(current_currency).
|
@@ -36,6 +55,11 @@ module Spree
|
|
36
55
|
end
|
37
56
|
|
38
57
|
def logo(image_path = nil, options = {})
|
58
|
+
ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
|
59
|
+
`BaseHelper#logo` is deprecated and will be removed in Spree 5.0.
|
60
|
+
Please use `FrontendHelper#logo` instead
|
61
|
+
DEPRECATION
|
62
|
+
|
39
63
|
image_path ||= if current_store.logo.attached? && current_store.logo.variable?
|
40
64
|
main_app.url_for(current_store.logo.variant(resize: '244x104>'))
|
41
65
|
elsif current_store.logo.attached? && current_store.logo.image?
|
@@ -51,6 +75,10 @@ module Spree
|
|
51
75
|
end
|
52
76
|
end
|
53
77
|
|
78
|
+
def spree_favicon_path
|
79
|
+
main_app.url_for(current_store.favicon || 'favicon.ico')
|
80
|
+
end
|
81
|
+
|
54
82
|
def object
|
55
83
|
instance_variable_get('@' + controller_name.singularize)
|
56
84
|
end
|
@@ -95,7 +123,7 @@ module Spree
|
|
95
123
|
description: [object.name, current_store.meta_description].reject(&:blank?).join(', '))
|
96
124
|
else
|
97
125
|
meta.reverse_merge!(keywords: (current_store.meta_keywords || current_store.seo_title),
|
98
|
-
description: (current_store.
|
126
|
+
description: (current_store.homepage(I18n.locale)&.seo_meta_description || current_store.seo_meta_description))
|
99
127
|
end
|
100
128
|
end
|
101
129
|
meta
|
@@ -143,6 +171,34 @@ module Spree
|
|
143
171
|
Spree::Core::Engine.frontend_available?
|
144
172
|
end
|
145
173
|
|
174
|
+
def rails_5?
|
175
|
+
Rails::VERSION::STRING < '6.0'
|
176
|
+
end
|
177
|
+
|
178
|
+
def spree_storefront_resource_url(resource, options = {})
|
179
|
+
if defined?(locale_param) && locale_param.present?
|
180
|
+
options.merge!(locale: locale_param)
|
181
|
+
end
|
182
|
+
|
183
|
+
localize = if options[:locale].present?
|
184
|
+
"/#{options[:locale]}"
|
185
|
+
else
|
186
|
+
''
|
187
|
+
end
|
188
|
+
|
189
|
+
if resource.instance_of?(Spree::Product)
|
190
|
+
"#{current_store.formatted_url + localize}/#{Spree::Config[:storefront_products_path]}/#{resource.slug}"
|
191
|
+
elsif resource.instance_of?(Spree::Taxon)
|
192
|
+
"#{current_store.formatted_url + localize}/#{Spree::Config[:storefront_taxons_path]}/#{resource.permalink}"
|
193
|
+
elsif resource.instance_of?(Spree::Cms::Pages::FeaturePage) || resource.instance_of?(Spree::Cms::Pages::StandardPage)
|
194
|
+
"#{current_store.formatted_url + localize}/#{Spree::Config[:storefront_pages_path]}/#{resource.slug}"
|
195
|
+
elsif localize.blank?
|
196
|
+
current_store.formatted_url
|
197
|
+
else
|
198
|
+
current_store.formatted_url + localize
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
146
202
|
# we should always try to render image of the default variant
|
147
203
|
# same as it's done on PDP
|
148
204
|
def default_image_for_product(product)
|
@@ -171,7 +227,7 @@ module Spree
|
|
171
227
|
|
172
228
|
def base_cache_key
|
173
229
|
[I18n.locale, current_currency, defined?(try_spree_current_user) && try_spree_current_user.present?,
|
174
|
-
|
230
|
+
defined?(try_spree_current_user) && try_spree_current_user.try(:has_spree_role?, 'admin')]
|
175
231
|
end
|
176
232
|
|
177
233
|
def maximum_quantity
|
@@ -190,11 +246,13 @@ module Spree
|
|
190
246
|
options = options.first || {}
|
191
247
|
options[:alt] ||= product.name
|
192
248
|
image_path = default_image_for_product_or_variant(product)
|
193
|
-
if image_path.present?
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
249
|
+
img = if image_path.present?
|
250
|
+
create_product_image_tag image_path, product, options, style
|
251
|
+
else
|
252
|
+
inline_svg_tag "noimage/backend-missing-image.svg", class: "noimage", size: "60%*60%"
|
253
|
+
end
|
254
|
+
|
255
|
+
content_tag(:div, img, class: "admin-product-image-container #{style}-img")
|
198
256
|
end
|
199
257
|
end
|
200
258
|
|
@@ -211,5 +269,9 @@ module Spree
|
|
211
269
|
|
212
270
|
tag('meta', name: 'robots', content: current_store.seo_robots)
|
213
271
|
end
|
272
|
+
|
273
|
+
def taxon_wysiwyg_editor_enabled?
|
274
|
+
Spree::Config[:taxon_wysiwyg_editor_enabled]
|
275
|
+
end
|
214
276
|
end
|
215
277
|
end
|
@@ -16,12 +16,16 @@ module Spree
|
|
16
16
|
|
17
17
|
def locale_presentation(locale)
|
18
18
|
if I18n.exists?('spree.i18n.this_file_language', locale: locale)
|
19
|
-
[
|
19
|
+
[locale_full_name(locale), locale.to_s]
|
20
20
|
else
|
21
21
|
locale.to_s == 'en' ? ['English (US)', 'en'] : [locale, locale.to_s]
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
def locale_full_name(locale)
|
26
|
+
Spree.t('i18n.this_file_language', locale: locale)
|
27
|
+
end
|
28
|
+
|
25
29
|
def should_render_locale_dropdown?
|
26
30
|
return false if current_store.nil?
|
27
31
|
|
@@ -44,9 +44,13 @@ module Spree
|
|
44
44
|
variants_option_types_presenter(variants, product).options
|
45
45
|
end
|
46
46
|
|
47
|
+
def product_wysiwyg_editor_enabled?
|
48
|
+
Spree::Config[:product_wysiwyg_editor_enabled]
|
49
|
+
end
|
50
|
+
|
47
51
|
# converts line breaks in product description into <p> tags (for html display purposes)
|
48
52
|
def product_description(product)
|
49
|
-
description = if Spree::Config[:show_raw_product_description]
|
53
|
+
description = if Spree::Config[:show_raw_product_description] || product_wysiwyg_editor_enabled?
|
50
54
|
product.description
|
51
55
|
else
|
52
56
|
product.description.to_s.gsub(/(.*?)\r?\n\r?\n/m, '<p>\1</p>')
|
@@ -63,7 +67,7 @@ module Spree
|
|
63
67
|
end
|
64
68
|
|
65
69
|
def cache_key_for_products(products = @products, additional_cache_key = nil)
|
66
|
-
max_updated_at = (products.maximum(:updated_at) || Date.today).to_s(:number)
|
70
|
+
max_updated_at = (products.except(:group, :order).maximum(:updated_at) || Date.today).to_s(:number)
|
67
71
|
products_cache_keys = "spree/products/#{products.map(&:id).join('-')}-#{params[:page]}-#{params[:sort_by]}-#{max_updated_at}-#{@taxon&.id}"
|
68
72
|
(common_product_cache_keys + [products_cache_keys] + [additional_cache_key]).compact.join('/')
|
69
73
|
end
|
@@ -131,7 +135,7 @@ module Spree
|
|
131
135
|
|
132
136
|
return [] if product_ids.empty?
|
133
137
|
|
134
|
-
|
138
|
+
current_store.products.
|
135
139
|
available.not_discontinued.distinct.
|
136
140
|
where(id: product_ids).
|
137
141
|
includes(
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Spree
|
2
|
+
module DisplayLink
|
3
|
+
def link
|
4
|
+
case linked_resource_type
|
5
|
+
when 'Spree::Taxon'
|
6
|
+
return if linked_resource&.permalink.blank?
|
7
|
+
|
8
|
+
if spree_routes.method_defined?(:nested_taxons_path)
|
9
|
+
spree_routes.nested_taxons_path(linked_resource.permalink)
|
10
|
+
else
|
11
|
+
"/#{Spree::Config[:storefront_taxons_path]}/#{linked_resource.permalink}"
|
12
|
+
end
|
13
|
+
when 'Spree::Product'
|
14
|
+
return if linked_resource&.slug.blank?
|
15
|
+
|
16
|
+
if spree_routes.method_defined?(:products_path)
|
17
|
+
spree_routes.product_path(linked_resource)
|
18
|
+
else
|
19
|
+
"/#{Spree::Config[:storefront_products_path]}/#{linked_resource.slug}"
|
20
|
+
end
|
21
|
+
when 'Spree::CmsPage'
|
22
|
+
return if linked_resource&.slug.blank?
|
23
|
+
|
24
|
+
if spree_routes.method_defined?(:page_path)
|
25
|
+
spree_routes.page_path(linked_resource.slug)
|
26
|
+
else
|
27
|
+
"/#{Spree::Config[:storefront_pages_path]}/#{linked_resource.slug}"
|
28
|
+
end
|
29
|
+
when 'Home Page'
|
30
|
+
'/'
|
31
|
+
when 'URL'
|
32
|
+
destination
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def spree_routes
|
39
|
+
Spree::Core::Engine.routes.url_helpers
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -17,13 +17,17 @@ module Spree
|
|
17
17
|
# Decorate a method, but with some additional options
|
18
18
|
# extend Spree::DisplayMoney
|
19
19
|
# money_methods tax_amount: { currency: "CAD", no_cents: true }, :price
|
20
|
+
# Use generated method with the same arguments as in wrapped method
|
21
|
+
# def tax_amount(order, country)
|
22
|
+
# display_tax_amount(order, country)
|
20
23
|
def money_methods(*args)
|
21
24
|
args.each do |money_method|
|
22
25
|
money_method = { money_method => {} } unless money_method.is_a? Hash
|
23
26
|
money_method.each do |method_name, opts|
|
24
|
-
define_method("display_#{method_name}") do
|
27
|
+
define_method("display_#{method_name}") do |**args_list|
|
25
28
|
default_opts = respond_to?(:currency) ? { currency: currency } : {}
|
26
|
-
|
29
|
+
|
30
|
+
Spree::Money.new(send(method_name, **args_list), default_opts.merge(opts).merge(args_list.slice(:currency)))
|
27
31
|
end
|
28
32
|
end
|
29
33
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Spree
|
2
|
+
module FilterParam
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
before_save :set_filter_param
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def set_filter_param
|
12
|
+
return if param_candidate.blank?
|
13
|
+
|
14
|
+
self.filter_param = param_candidate.parameterize
|
15
|
+
end
|
16
|
+
|
17
|
+
def param_candidate
|
18
|
+
name
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Spree
|
2
|
+
module ImageMethods
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
def generate_url(size:, gravity: 'center', quality: 80, background: 'show')
|
6
|
+
return if size.blank?
|
7
|
+
size = size.gsub(/\s+/, '')
|
8
|
+
|
9
|
+
return unless size.match(/(\d+)x(\d+)/)
|
10
|
+
|
11
|
+
polymorphic_path(attachment.variant(
|
12
|
+
gravity: gravity,
|
13
|
+
resize: size,
|
14
|
+
extent: size,
|
15
|
+
background: background,
|
16
|
+
quality: quality.to_i
|
17
|
+
), only_path: true)
|
18
|
+
end
|
19
|
+
|
20
|
+
def original_url
|
21
|
+
polymorphic_path(attachment, only_path: true)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Spree
|
2
|
+
module MemoizedData
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
# reset cache on save inside trasaction and transaction commit
|
7
|
+
after_save :reset_memoized_data
|
8
|
+
after_commit :reset_memoized_data
|
9
|
+
|
10
|
+
def reload(options = {})
|
11
|
+
reset_memoized_data
|
12
|
+
super(options)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def reset_memoized_data
|
18
|
+
self.class.const_get('MEMOIZED_METHODS').each do |v|
|
19
|
+
instance_variable_set(:"@#{v.gsub(/\?/, '')}", nil)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Spree
|
2
|
+
module MultiStoreResource
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
scope :for_store, ->(store) { joins(:stores).where(Store.table_name => { id: store.id }) }
|
7
|
+
|
8
|
+
validate :must_have_one_store, unless: :disable_store_presence_validation?
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def must_have_one_store
|
14
|
+
return if stores.any?
|
15
|
+
|
16
|
+
errors.add(:stores, Spree.t(:must_have_one_store))
|
17
|
+
end
|
18
|
+
|
19
|
+
# this can be overriden on model basis
|
20
|
+
def disable_store_presence_validation?
|
21
|
+
Spree::Config[:disable_store_presence_validation]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -43,23 +43,35 @@ module Spree
|
|
43
43
|
add_simple_scopes simple_scopes
|
44
44
|
|
45
45
|
add_search_scope :ascend_by_master_price do
|
46
|
-
|
46
|
+
order("#{price_table_name}.amount ASC")
|
47
47
|
end
|
48
48
|
|
49
49
|
add_search_scope :descend_by_master_price do
|
50
|
-
|
50
|
+
order("#{price_table_name}.amount DESC")
|
51
51
|
end
|
52
52
|
|
53
53
|
add_search_scope :price_between do |low, high|
|
54
|
-
|
54
|
+
where(Price.table_name => { amount: low..high })
|
55
55
|
end
|
56
56
|
|
57
57
|
add_search_scope :master_price_lte do |price|
|
58
|
-
|
58
|
+
where("#{price_table_name}.amount <= ?", price)
|
59
59
|
end
|
60
60
|
|
61
61
|
add_search_scope :master_price_gte do |price|
|
62
|
-
|
62
|
+
where("#{price_table_name}.amount >= ?", price)
|
63
|
+
end
|
64
|
+
|
65
|
+
add_search_scope :in_stock do
|
66
|
+
joins(:variants_including_master).merge(Spree::Variant.in_stock)
|
67
|
+
end
|
68
|
+
|
69
|
+
add_search_scope :backorderable do
|
70
|
+
joins(:variants_including_master).merge(Spree::Variant.backorderable)
|
71
|
+
end
|
72
|
+
|
73
|
+
add_search_scope :in_stock_or_backorderable do
|
74
|
+
joins(:variants_including_master).merge(Spree::Variant.in_stock_or_backorderable)
|
63
75
|
end
|
64
76
|
|
65
77
|
# This scope selects products in taxon AND all its descendants
|
@@ -94,6 +106,19 @@ module Spree
|
|
94
106
|
taxons.first ? prepare_taxon_conditions(taxons) : where(nil)
|
95
107
|
end
|
96
108
|
|
109
|
+
add_search_scope :ascend_by_taxons_min_position do |taxon_ids|
|
110
|
+
joins(:classifications).
|
111
|
+
where(Classification.table_name => { taxon_id: taxon_ids }).
|
112
|
+
select(
|
113
|
+
[
|
114
|
+
"#{Product.table_name}.*",
|
115
|
+
"MIN(#{Classification.table_name}.position) AS min_position"
|
116
|
+
].join(', ')
|
117
|
+
).
|
118
|
+
group(:id).
|
119
|
+
order(min_position: :asc)
|
120
|
+
end
|
121
|
+
|
97
122
|
# a scope that finds all products having property specified by name, object or id
|
98
123
|
add_search_scope :with_property do |property|
|
99
124
|
joins(:properties).where(property_conditions(property))
|
@@ -107,6 +132,12 @@ module Spree
|
|
107
132
|
where(property_conditions(property))
|
108
133
|
end
|
109
134
|
|
135
|
+
add_search_scope :with_property_values do |property_filter_param, property_values|
|
136
|
+
joins(product_properties: :property).
|
137
|
+
where(Property.table_name => { filter_param: property_filter_param }).
|
138
|
+
where(ProductProperty.table_name => { filter_param: property_values.map(&:parameterize) })
|
139
|
+
end
|
140
|
+
|
110
141
|
add_search_scope :with_option do |option|
|
111
142
|
option_types = OptionType.table_name
|
112
143
|
conditions = case option
|
@@ -198,18 +229,50 @@ module Spree
|
|
198
229
|
end
|
199
230
|
end
|
200
231
|
search_scopes << :not_discontinued
|
232
|
+
|
233
|
+
def self.with_currency(currency)
|
234
|
+
joins(variants_including_master: :prices).
|
235
|
+
where(Price.table_name => { currency: currency.upcase }).
|
236
|
+
where.not(Price.table_name => { amount: nil }).
|
237
|
+
distinct
|
238
|
+
end
|
239
|
+
search_scopes << :with_currency
|
240
|
+
|
201
241
|
# Can't use add_search_scope for this as it needs a default argument
|
202
|
-
def self.available(available_on = nil,
|
242
|
+
def self.available(available_on = nil, currency = nil)
|
203
243
|
available_on ||= Time.current
|
204
|
-
|
244
|
+
|
245
|
+
scope = not_discontinued.where("#{Product.quoted_table_name}.available_on <= ?", available_on)
|
246
|
+
|
247
|
+
unless Spree::Config.show_products_without_price
|
248
|
+
currency ||= Spree::Config[:currency]
|
249
|
+
scope = scope.with_currency(currency)
|
250
|
+
end
|
251
|
+
|
252
|
+
scope
|
205
253
|
end
|
206
254
|
search_scopes << :available
|
207
255
|
|
208
256
|
def self.active(currency = nil)
|
209
|
-
available(nil, currency
|
257
|
+
available(nil, currency)
|
210
258
|
end
|
211
259
|
search_scopes << :active
|
212
260
|
|
261
|
+
def self.for_filters(currency, taxon: nil)
|
262
|
+
scope = active(currency)
|
263
|
+
scope = scope.in_taxon(taxon) if taxon.present?
|
264
|
+
scope
|
265
|
+
end
|
266
|
+
search_scopes << :for_filters
|
267
|
+
|
268
|
+
def self.for_user(user = nil)
|
269
|
+
if user.try(:has_spree_role?, 'admin')
|
270
|
+
with_deleted
|
271
|
+
else
|
272
|
+
not_deleted.not_discontinued.where("#{Product.quoted_table_name}.available_on <= ?", Time.current)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
213
276
|
add_search_scope :taxons_name_eq do |name|
|
214
277
|
group('spree_products.id').joins(:taxons).where(Taxon.arel_table[:name].eq(name))
|
215
278
|
end
|