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.
Files changed (263) hide show
  1. checksums.yaml +4 -4
  2. data/app/finders/concerns/spree/product_filterable.rb +9 -0
  3. data/app/finders/spree/cms_pages/find.rb +41 -0
  4. data/app/finders/spree/menus/find.rb +11 -0
  5. data/app/finders/spree/option_values/find_available.rb +20 -0
  6. data/app/finders/spree/orders/find_complete.rb +14 -2
  7. data/app/finders/spree/orders/find_current.rb +1 -13
  8. data/app/finders/spree/product_properties/find_available.rb +20 -0
  9. data/app/finders/spree/products/find.rb +80 -21
  10. data/app/finders/spree/stores/find_current.rb +24 -0
  11. data/app/finders/spree/taxons/find.rb +22 -6
  12. data/app/helpers/spree/base_helper.rb +69 -7
  13. data/app/helpers/spree/locale_helper.rb +5 -1
  14. data/app/helpers/spree/products_helper.rb +7 -3
  15. data/app/models/concerns/spree/display_link.rb +42 -0
  16. data/app/models/concerns/spree/display_money.rb +6 -2
  17. data/app/models/concerns/spree/filter_param.rb +21 -0
  18. data/app/models/concerns/spree/image_methods.rb +24 -0
  19. data/app/models/concerns/spree/memoized_data.rb +24 -0
  20. data/app/models/concerns/spree/multi_store_resource.rb +24 -0
  21. data/app/models/concerns/spree/product_scopes.rb +71 -8
  22. data/app/models/concerns/spree/single_store_resource.rb +19 -0
  23. data/app/models/concerns/spree/user_address.rb +19 -0
  24. data/app/models/concerns/spree/user_methods.rb +14 -12
  25. data/app/models/concerns/spree/user_payment_source.rb +1 -1
  26. data/app/models/concerns/spree/user_reporting.rb +35 -10
  27. data/app/models/concerns/spree/user_roles.rb +25 -0
  28. data/app/models/spree/ability.rb +3 -1
  29. data/app/models/spree/address.rb +27 -6
  30. data/app/models/spree/app_configuration.rb +8 -0
  31. data/app/models/spree/app_dependencies.rb +20 -6
  32. data/app/models/spree/base.rb +18 -0
  33. data/app/models/spree/classification.rb +3 -0
  34. data/app/models/spree/cms/pages/feature_page.rb +7 -0
  35. data/app/models/spree/cms/pages/homepage.rb +20 -0
  36. data/app/models/spree/cms/pages/standard_page.rb +4 -0
  37. data/app/models/spree/cms/sections/featured_article.rb +22 -0
  38. data/app/models/spree/cms/sections/hero_image.rb +38 -0
  39. data/app/models/spree/cms/sections/image_gallery.rb +103 -0
  40. data/app/models/spree/cms/sections/product_carousel.rb +14 -0
  41. data/app/models/spree/cms/sections/rich_text_content.rb +13 -0
  42. data/app/models/spree/cms/sections/side_by_side_images.rb +74 -0
  43. data/app/models/spree/cms_page.rb +66 -0
  44. data/app/models/spree/cms_section.rb +69 -0
  45. data/app/models/spree/country.rb +14 -6
  46. data/app/models/spree/credit_card.rb +2 -8
  47. data/app/models/spree/customer_return.rb +8 -2
  48. data/app/models/spree/gateway/bogus.rb +6 -4
  49. data/app/models/spree/icon.rb +9 -0
  50. data/app/models/spree/image/configuration/active_storage.rb +2 -0
  51. data/app/models/spree/image.rb +5 -24
  52. data/app/models/spree/inventory_unit.rb +1 -1
  53. data/app/models/spree/line_item.rb +1 -1
  54. data/app/models/spree/menu.rb +63 -0
  55. data/app/models/spree/menu_item.rb +76 -0
  56. data/app/models/spree/option_type.rb +1 -1
  57. data/app/models/spree/option_value.rb +11 -0
  58. data/app/models/spree/option_value_variant.rb +1 -1
  59. data/app/models/spree/order/address_book.rb +3 -5
  60. data/app/models/spree/order/currency_updater.rb +1 -1
  61. data/app/models/spree/order/emails.rb +32 -0
  62. data/app/models/spree/order/payments.rb +1 -1
  63. data/app/models/spree/order/store_credit.rb +1 -1
  64. data/app/models/spree/order.rb +46 -45
  65. data/app/models/spree/payment.rb +7 -0
  66. data/app/models/spree/payment_method.rb +16 -0
  67. data/app/models/spree/preferences/preferable.rb +12 -0
  68. data/app/models/spree/preferences/preferable_class_methods.rb +10 -1
  69. data/app/models/spree/product.rb +37 -30
  70. data/app/models/spree/product_property.rb +19 -4
  71. data/app/models/spree/promotion/rules/country.rb +1 -1
  72. data/app/models/spree/promotion/rules/first_order.rb +4 -3
  73. data/app/models/spree/promotion/rules/taxon.rb +10 -7
  74. data/app/models/spree/promotion.rb +6 -15
  75. data/app/models/spree/promotion_handler/cart.rb +7 -2
  76. data/app/models/spree/promotion_handler/coupon.rb +5 -4
  77. data/app/models/spree/promotion_handler/free_shipping.rb +5 -6
  78. data/app/models/spree/promotion_handler/page.rb +3 -2
  79. data/app/models/spree/promotion_handler/promotion_duplicator.rb +1 -0
  80. data/app/models/spree/promotion_rule.rb +2 -0
  81. data/app/models/spree/property.rb +28 -1
  82. data/app/models/spree/reimbursement.rb +3 -1
  83. data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +2 -1
  84. data/app/models/spree/shipment_handler.rb +4 -2
  85. data/app/models/spree/stock/quantifier.rb +6 -6
  86. data/app/models/spree/stock_location.rb +9 -0
  87. data/app/models/spree/store.rb +90 -7
  88. data/app/models/spree/store_credit.rb +7 -3
  89. data/app/models/spree/store_credit_event.rb +2 -2
  90. data/app/models/spree/store_payment_method.rb +11 -0
  91. data/app/models/spree/store_product.rb +11 -0
  92. data/app/models/spree/store_promotion.rb +11 -0
  93. data/app/models/spree/taxon.rb +22 -1
  94. data/app/models/spree/taxon_image/configuration/active_storage.rb +2 -0
  95. data/app/models/spree/taxon_image.rb +1 -0
  96. data/app/models/spree/taxonomy.rb +3 -1
  97. data/app/models/spree/variant.rb +21 -6
  98. data/app/presenters/spree/filters/options_presenter.rb +47 -0
  99. data/app/presenters/spree/filters/price_presenter.rb +22 -0
  100. data/app/presenters/spree/filters/price_range_presenter.rb +29 -0
  101. data/app/presenters/spree/filters/properties_presenter.rb +23 -0
  102. data/app/presenters/spree/filters/property_presenter.rb +42 -0
  103. data/app/presenters/spree/filters/quantified_price_range_presenter.rb +44 -0
  104. data/app/services/spree/account/addresses/create.rb +1 -0
  105. data/app/services/spree/account/addresses/helper.rb +6 -0
  106. data/app/services/spree/account/addresses/update.rb +9 -3
  107. data/app/services/spree/account/create.rb +17 -0
  108. data/app/services/spree/account/update.rb +15 -0
  109. data/app/services/spree/build_localized_redirect_url.rb +1 -1
  110. data/app/services/spree/cart/associate.rb +16 -0
  111. data/app/services/spree/cart/change_currency.rb +27 -0
  112. data/app/services/spree/cart/create.rb +5 -3
  113. data/app/services/spree/cart/destroy.rb +40 -0
  114. data/app/services/spree/cart/empty.rb +36 -0
  115. data/app/services/spree/cart/estimate_shipping_rates.rb +3 -3
  116. data/app/services/spree/checkout/add_store_credit.rb +1 -1
  117. data/app/services/spree/classifications/reposition.rb +18 -0
  118. data/app/services/spree/credit_cards/destroy.rb +41 -0
  119. data/app/sorters/spree/base_sorter.rb +23 -11
  120. data/app/sorters/spree/products/sort.rb +23 -7
  121. data/app/validators/db_maximum_length_validator.rb +5 -0
  122. data/app/validators/email_validator.rb +3 -1
  123. data/config/initializers/active_storage.rb +2 -0
  124. data/config/locales/en.yml +177 -3
  125. data/config/routes.rb +0 -5
  126. data/db/migrate/20201023152810_add_filterable_to_spree_properties.rb +8 -0
  127. data/db/migrate/20210407200948_create_spree_menus.rb +16 -0
  128. data/db/migrate/20210408092939_create_spree_menu_items.rb +31 -0
  129. data/db/migrate/20210504163720_add_filter_param_to_spree_product_properties.rb +8 -0
  130. data/db/migrate/20210505114659_add_filter_param_to_spree_properties.rb +8 -0
  131. data/db/migrate/20210512191732_create_spree_cms_pages.rb +24 -0
  132. data/db/migrate/20210514204251_create_spree_cms_sections.rb +22 -0
  133. data/db/migrate/20210527094055_create_spree_products_stores.rb +36 -0
  134. data/db/migrate/20210608045519_ensure_store_default_country_is_set.rb +5 -0
  135. data/db/migrate/20210702112334_add_missing_timestamp_columns.rb +46 -0
  136. data/db/migrate/20210713131614_add_unique_index_on_property_id_and_product_id_to_product_properties.rb +29 -0
  137. data/db/migrate/20210715091956_add_store_id_to_spree_store_credits.rb +10 -0
  138. data/db/migrate/20210716093151_add_store_id_to_spree_taxonomies.rb +11 -0
  139. data/db/migrate/20210716104141_add_index_on_name_parent_id_and_taxonomy_id_on_spree_taxons.rb +31 -0
  140. data/db/migrate/20210721120857_add_index_on_permalink_parent_id_and_taxonomy_id_on_spree_taxons.rb +31 -0
  141. data/db/migrate/20210721125657_create_spree_promotions_stores.rb +29 -0
  142. data/db/migrate/20210722090705_add_store_id_to_spree_customer_returns.rb +11 -0
  143. data/db/migrate/20210726065456_change_integer_id_columns_into_bigint.rb +305 -0
  144. data/db/migrate/20210730154425_fix_promotion_code_and_path_unique_indexes.rb +9 -0
  145. data/lib/generators/spree/dummy/dummy_generator.rb +11 -6
  146. data/lib/generators/spree/dummy/templates/rails/test.rb +2 -0
  147. data/lib/generators/spree/dummy_model/templates/model.rb.tt +1 -1
  148. data/lib/generators/spree/install/install_generator.rb +12 -24
  149. data/lib/spree/core/components.rb +8 -0
  150. data/lib/spree/core/controller_helpers/auth.rb +7 -1
  151. data/lib/spree/core/controller_helpers/common.rb +1 -1
  152. data/lib/spree/core/controller_helpers/order.rb +4 -4
  153. data/lib/spree/core/controller_helpers/search.rb +1 -0
  154. data/lib/spree/core/controller_helpers/store.rb +24 -1
  155. data/lib/spree/core/engine.rb +6 -0
  156. data/lib/spree/core/importer/product.rb +3 -1
  157. data/lib/spree/core/product_duplicator.rb +1 -0
  158. data/lib/spree/core/search/base.rb +17 -22
  159. data/lib/spree/core/version.rb +1 -1
  160. data/lib/spree/core.rb +8 -4
  161. data/lib/spree/i18n.rb +1 -1
  162. data/lib/spree/money.rb +2 -1
  163. data/lib/spree/permitted_attributes.rb +21 -3
  164. data/lib/spree/testing_support/authorization_helpers.rb +6 -3
  165. data/lib/spree/testing_support/capybara_config.rb +3 -1
  166. data/lib/spree/testing_support/common_rake.rb +17 -4
  167. data/lib/spree/testing_support/extension_rake.rb +2 -2
  168. data/lib/spree/testing_support/factories/address_factory.rb +1 -1
  169. data/lib/spree/testing_support/factories/classification_factory.rb +8 -0
  170. data/lib/spree/testing_support/factories/cms_page_factory.rb +20 -0
  171. data/lib/spree/testing_support/factories/cms_section_factory.rb +31 -0
  172. data/lib/spree/testing_support/factories/customer_return_factory.rb +24 -17
  173. data/lib/spree/testing_support/factories/icon_factory.rb +7 -0
  174. data/lib/spree/testing_support/factories/line_item_factory.rb +6 -2
  175. data/lib/spree/testing_support/factories/menu_factory.rb +16 -0
  176. data/lib/spree/testing_support/factories/menu_item_factory.rb +10 -0
  177. data/lib/spree/testing_support/factories/options_factory.rb +5 -0
  178. data/lib/spree/testing_support/factories/order_factory.rb +11 -2
  179. data/lib/spree/testing_support/factories/payment_method_factory.rb +6 -2
  180. data/lib/spree/testing_support/factories/product_factory.rb +17 -1
  181. data/lib/spree/testing_support/factories/product_property_factory.rb +1 -1
  182. data/lib/spree/testing_support/factories/promotion_factory.rb +18 -9
  183. data/lib/spree/testing_support/factories/property_factory.rb +22 -0
  184. data/lib/spree/testing_support/factories/stock_location_factory.rb +5 -4
  185. data/lib/spree/testing_support/factories/store_credit_factory.rb +1 -0
  186. data/lib/spree/testing_support/factories/store_factory.rb +11 -0
  187. data/lib/spree/testing_support/factories/taxon_factory.rb +3 -1
  188. data/lib/spree/testing_support/factories/taxon_image_factory.rb +7 -0
  189. data/lib/spree/testing_support/factories/taxonomy_factory.rb +1 -0
  190. data/lib/spree/testing_support/factories/user_factory.rb +7 -2
  191. data/lib/spree/testing_support/factories/variant_factory.rb +2 -2
  192. data/lib/spree/testing_support/flatpickr_capybara.rb +58 -35
  193. data/lib/spree/testing_support/locale_helpers.rb +1 -1
  194. data/lib/spree/testing_support/order_walkthrough.rb +9 -9
  195. data/lib/spree/testing_support/rspec_retry_config.rb +5 -0
  196. data/lib/tasks/core.rake +1 -1
  197. data/spec/fixtures/favicon.ico +0 -0
  198. data/spec/fixtures/files/icon_256x256.gif +0 -0
  199. data/spec/fixtures/files/icon_256x256.png +0 -0
  200. data/spec/fixtures/files/icon_512x512.png +0 -0
  201. data/spec/fixtures/files/img_256x128.png +0 -0
  202. data/spree_core.gemspec +12 -11
  203. metadata +211 -159
  204. data/app/assets/images/logo/spree_50.png +0 -0
  205. data/app/assets/images/noimage/large.png +0 -0
  206. data/app/assets/images/noimage/mini.png +0 -0
  207. data/app/assets/images/noimage/product.png +0 -0
  208. data/app/assets/images/noimage/small.png +0 -0
  209. data/app/assets/javascripts/spree.js +0 -78
  210. data/app/controllers/spree/errors_controller.rb +0 -11
  211. data/app/helpers/spree/mail_helper.rb +0 -29
  212. data/app/mailers/spree/base_mailer.rb +0 -46
  213. data/app/mailers/spree/order_mailer.rb +0 -26
  214. data/app/mailers/spree/reimbursement_mailer.rb +0 -12
  215. data/app/mailers/spree/shipment_mailer.rb +0 -12
  216. data/app/mailers/spree/test_mailer.rb +0 -8
  217. data/app/models/spree/validations/db_maximum_length_validator.rb +0 -22
  218. data/app/views/layouts/spree/base_mailer.html.erb +0 -46
  219. data/app/views/spree/errors/forbidden.html.erb +0 -0
  220. data/app/views/spree/errors/unauthorized.html.erb +0 -0
  221. data/app/views/spree/order_mailer/cancel_email.html.erb +0 -24
  222. data/app/views/spree/order_mailer/cancel_email.text.erb +0 -38
  223. data/app/views/spree/order_mailer/confirm_email.html.erb +0 -23
  224. data/app/views/spree/order_mailer/confirm_email.text.erb +0 -39
  225. data/app/views/spree/order_mailer/store_owner_notification_email.html.erb +0 -23
  226. data/app/views/spree/order_mailer/store_owner_notification_email.text.erb +0 -38
  227. data/app/views/spree/reimbursement_mailer/reimbursement_email.html.erb +0 -56
  228. data/app/views/spree/reimbursement_mailer/reimbursement_email.text.erb +0 -24
  229. data/app/views/spree/shared/_base_mailer_footer.html.erb +0 -12
  230. data/app/views/spree/shared/_base_mailer_header.html.erb +0 -13
  231. data/app/views/spree/shared/_base_mailer_stylesheets.html.erb +0 -456
  232. data/app/views/spree/shared/_error_messages.html.erb +0 -11
  233. data/app/views/spree/shared/_mailer_line_item.html.erb +0 -16
  234. data/app/views/spree/shared/_paths.html.erb +0 -8
  235. data/app/views/spree/shared/_purchased_items_table.html.erb +0 -69
  236. data/app/views/spree/shared/purchased_items_table/_adjustment.html.erb +0 -13
  237. data/app/views/spree/shared/purchased_items_table/_line_item.html.erb +0 -27
  238. data/app/views/spree/shared/purchased_items_table/_subtotal.html.erb +0 -13
  239. data/app/views/spree/shared/purchased_items_table/_total.html.erb +0 -13
  240. data/app/views/spree/shipment_mailer/shipped_email.html.erb +0 -36
  241. data/app/views/spree/shipment_mailer/shipped_email.text.erb +0 -17
  242. data/app/views/spree/test_mailer/test_email.html.erb +0 -40
  243. data/app/views/spree/test_mailer/test_email.text.erb +0 -4
  244. data/config/initializers/assets.rb +0 -2
  245. data/config/initializers/premailer_assets.rb +0 -1
  246. data/config/initializers/premailer_rails.rb +0 -3
  247. data/db/migrate/20140805171219_make_existing_credit_cards_default.rb +0 -10
  248. data/lib/generators/spree/dummy/templates/initializers/bullet.rb +0 -5
  249. data/lib/generators/spree/install/templates/vendor/assets/javascripts/spree/backend/all.js +0 -15
  250. data/lib/generators/spree/install/templates/vendor/assets/javascripts/spree/frontend/all.js +0 -16
  251. data/lib/generators/spree/install/templates/vendor/assets/stylesheets/spree/backend/all.css +0 -16
  252. data/lib/generators/spree/install/templates/vendor/assets/stylesheets/spree/frontend/all.css +0 -16
  253. data/lib/generators/spree/mailers_preview/mailers_preview_generator.rb +0 -23
  254. data/lib/generators/spree/mailers_preview/templates/mailers/previews/order_preview.rb +0 -13
  255. data/lib/generators/spree/mailers_preview/templates/mailers/previews/reimbursement_preview.rb +0 -5
  256. data/lib/generators/spree/mailers_preview/templates/mailers/previews/shipment_preview.rb +0 -5
  257. data/lib/generators/spree/mailers_preview/templates/mailers/previews/user_preview.rb +0 -11
  258. data/lib/tasks/email.rake +0 -10
  259. data/vendor/assets/javascripts/cleave.js +0 -1669
  260. data/vendor/assets/javascripts/fetch.umd.js +0 -531
  261. data/vendor/assets/javascripts/jquery.payment.js +0 -652
  262. data/vendor/assets/javascripts/jsuri.js +0 -458
  263. 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.meta_description || current_store.seo_title))
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
- defined?(try_spree_current_user) && try_spree_current_user.try(:has_spree_role?, 'admin')]
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
- create_product_image_tag image_path, product, options, style
195
- else
196
- image_tag "noimage/#{style}.png", options
197
- end
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
- [Spree.t('i18n.this_file_language', locale: locale), locale.to_s]
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
- Spree::Product.
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
- Spree::Money.new(send(method_name), default_opts.merge(opts))
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
- joins(master: :default_price).order("#{price_table_name}.amount ASC")
46
+ order("#{price_table_name}.amount ASC")
47
47
  end
48
48
 
49
49
  add_search_scope :descend_by_master_price do
50
- joins(master: :default_price).order("#{price_table_name}.amount DESC")
50
+ order("#{price_table_name}.amount DESC")
51
51
  end
52
52
 
53
53
  add_search_scope :price_between do |low, high|
54
- joins(master: :default_price).where(Price.table_name => { amount: low..high })
54
+ where(Price.table_name => { amount: low..high })
55
55
  end
56
56
 
57
57
  add_search_scope :master_price_lte do |price|
58
- joins(master: :default_price).where("#{price_table_name}.amount <= ?", price)
58
+ where("#{price_table_name}.amount <= ?", price)
59
59
  end
60
60
 
61
61
  add_search_scope :master_price_gte do |price|
62
- joins(master: :default_price).where("#{price_table_name}.amount >= ?", price)
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, _currency = nil)
242
+ def self.available(available_on = nil, currency = nil)
203
243
  available_on ||= Time.current
204
- not_discontinued.joins(master: :prices).where("#{Product.quoted_table_name}.available_on <= ?", available_on)
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&.upcase)
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