spree_core 5.1.0.beta2 → 5.1.0.beta4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8150046e1776256aacec11512b848d9cbd5074d17b7aacafd7b2736cfd934c3
4
- data.tar.gz: 8a04db5d73b2abf21a587ea66313d4fb7ff7120ed46ef9d22f38ddf1b3c5f295
3
+ metadata.gz: 40078ca0fe53f0e6a2af34f66cec79f80823d752aceabac637f5e247b32976a6
4
+ data.tar.gz: 5ae9476bc4e0fee22c705e9b1979a4d29d1057066c20d017a8c956392d137712
5
5
  SHA512:
6
- metadata.gz: 8024d8aa8b617d7be12713acf1787a7c4569dc708d74cbf34850ec6bc8fcea5630c15fdfe6efa4796c82825fc9724d637b219da887f888f909dd29d22582178f
7
- data.tar.gz: 60db3009f9a9a30bfca2b8c6895b7777a35eaac8819ca06a112e2315e234137ee87e5fea3796335e53e8a8e5c562f22183d7d8c6c3c3b1f8e9466d76ba3bbde5
6
+ metadata.gz: ff673f06e666ffcf7b987182bbc226c6663a645a7fac34d14ae79021f076972f21de05e27639e920885cd2478dc17a2f1f648bcfcbb29987909a71ab71913e6d
7
+ data.tar.gz: e52971afaf599280aef97bbad4cc33d81621003770dd43edae06532bb86486584d0bfc758299896dbbb56a1f9fc71c34c68791b47bbe1ce8588ba786ec4a78b5
@@ -17,6 +17,8 @@ module Spree
17
17
  end
18
18
 
19
19
  def logo_path
20
+ Spree::Deprecation.warn('logo_path is deprecated and will be removed in Spree 6.0. Please use Active Storage URL helpers instead.')
21
+
20
22
  return main_app.cdn_image_url(store_logo.variant(resize_to_limit: [244, 104])) if store_logo&.variable?
21
23
 
22
24
  return main_app.cdn_image_url(store_logo) if store_logo&.image?
@@ -0,0 +1,39 @@
1
+ module Spree
2
+ module PaymentSourceConcern
3
+ extend ActiveSupport::Concern
4
+
5
+ # Available actions for the payment source.
6
+ # @return [Array<String>]
7
+ def actions
8
+ %w{capture void credit}
9
+ end
10
+
11
+ # Indicates whether its possible to capture the payment
12
+ # @param payment [Spree::Payment]
13
+ # @return [Boolean]
14
+ def can_capture?(payment)
15
+ payment.pending? || payment.checkout?
16
+ end
17
+
18
+ # Indicates whether its possible to void the payment.
19
+ # @param payment [Spree::Payment]
20
+ # @return [Boolean]
21
+ def can_void?(payment)
22
+ !payment.failed? && !payment.void?
23
+ end
24
+
25
+ # Indicates whether its possible to credit the payment. Note that most gateways require that the
26
+ # payment be settled first which generally happens within 12-24 hours of the transaction.
27
+ # @param payment [Spree::Payment]
28
+ # @return [Boolean]
29
+ def can_credit?(payment)
30
+ payment.completed? && payment.credit_allowed > 0
31
+ end
32
+
33
+ # Returns true if the payment source has a payment profile.
34
+ # @return [Boolean]
35
+ def has_payment_profile?
36
+ gateway_customer_profile_id.present? || gateway_payment_profile_id.present?
37
+ end
38
+ end
39
+ end
@@ -305,7 +305,12 @@ module Spree
305
305
  # .search_by_name
306
306
  if defined?(PgSearch)
307
307
  include PgSearch::Model
308
- pg_search_scope :search_by_name, against: { name: 'A', meta_title: 'B' }, using: { tsearch: { any_word: true, prefix: true } }
308
+
309
+ if connected? && connection.extension_enabled?('pg_trgm')
310
+ pg_search_scope :search_by_name, against: { name: 'A', meta_title: 'B' }, using: { trigram: { threshold: 0.3, word_similarity: true } }
311
+ else
312
+ pg_search_scope :search_by_name, against: { name: 'A', meta_title: 'B' }, using: { tsearch: { any_word: true, prefix: true } }
313
+ end
309
314
  else
310
315
  def self.search_by_name(query)
311
316
  i18n { name.lower.matches("%#{query.downcase}%") }
@@ -189,7 +189,7 @@ module Spree
189
189
  end
190
190
 
191
191
  def show_company_address_field?
192
- false
192
+ Spree::Store.current.prefers_company_field_enabled?
193
193
  end
194
194
 
195
195
  def editable?
@@ -2,6 +2,8 @@ module Spree
2
2
  class CreditCard < Spree.base_class
3
3
  include ActiveMerchant::Billing::CreditCardMethods
4
4
  include Spree::Metadata
5
+ include Spree::PaymentSourceConcern
6
+
5
7
  if defined?(Spree::Webhooks::HasWebhooks)
6
8
  include Spree::Webhooks::HasWebhooks
7
9
  end
@@ -135,30 +137,6 @@ module Spree
135
137
  brand.present? ? brand.upcase : Spree.t(:no_cc_type)
136
138
  end
137
139
 
138
- def actions
139
- %w{capture void credit}
140
- end
141
-
142
- # Indicates whether its possible to capture the payment
143
- def can_capture?(payment)
144
- payment.pending? || payment.checkout?
145
- end
146
-
147
- # Indicates whether its possible to void the payment.
148
- def can_void?(payment)
149
- !payment.failed? && !payment.void?
150
- end
151
-
152
- # Indicates whether its possible to credit the payment. Note that most gateways require that the
153
- # payment be settled first which generally happens within 12-24 hours of the transaction.
154
- def can_credit?(payment)
155
- payment.completed? && payment.credit_allowed > 0
156
- end
157
-
158
- def has_payment_profile?
159
- gateway_customer_profile_id.present? || gateway_payment_profile_id.present?
160
- end
161
-
162
140
  # ActiveMerchant needs first_name/last_name because we pass it a Spree::CreditCard and it calls those methods on it.
163
141
  # Looking at the ActiveMerchant source code we should probably be calling #to_active_merchant before passing
164
142
  # the object to ActiveMerchant but this should do for now.
@@ -0,0 +1,33 @@
1
+ module Spree
2
+ class Gateway::CustomPaymentSourceMethod < Gateway
3
+ def provider_class
4
+ self.class
5
+ end
6
+
7
+ def payment_source_class
8
+ Spree::PaymentSource
9
+ end
10
+
11
+ def payment_profiles_supported?
12
+ true
13
+ end
14
+
15
+ def show_in_admin?
16
+ false
17
+ end
18
+
19
+ def create_profile(payment)
20
+ return if payment.source.gateway_customer.present?
21
+
22
+ user = payment.source.user || payment.order.user
23
+ return if user.blank?
24
+
25
+ find_or_create_customer(user)
26
+ end
27
+
28
+ # simulate a 3rd party payment gateway api to fetch/or create a customer
29
+ def find_or_create_customer(user)
30
+ gateway_customers.find_or_create_by!(user: user, profile_id: "CUSTOMER-#{user.id}")
31
+ end
32
+ end
33
+ end
@@ -302,7 +302,8 @@ module Spree
302
302
  # Payment profile cannot be created without source
303
303
  return unless source
304
304
  # Imported payments shouldn't create a payment profile.
305
- return if source.imported
305
+ # Imported is only available on Spree::CreditCard, non-credit card payments should not have this attribute.
306
+ return if source.respond_to?(:imported) && source.imported
306
307
 
307
308
  payment_method.create_profile(self)
308
309
  rescue ActiveMerchant::ConnectionError => e
@@ -1,10 +1,31 @@
1
+ # This model is used to store payment sources for non-credit card payments, eg wallet, account, etc.
1
2
  module Spree
2
3
  class PaymentSource < Spree.base_class
3
4
  include Spree::Metadata
5
+ include Spree::PaymentSourceConcern
4
6
 
7
+ #
8
+ # Associations
9
+ #
5
10
  belongs_to :payment_method, class_name: 'Spree::PaymentMethod'
6
11
  belongs_to :user, class_name: Spree.user_class.to_s, optional: true
7
12
 
13
+ #
14
+ # Validations
15
+ #
8
16
  validates_uniqueness_of :gateway_payment_profile_id, scope: :type
17
+
18
+ #
19
+ # Delegations
20
+ #
21
+ delegate :profile_id, to: :gateway_customer, prefix: true, allow_nil: true
22
+
23
+ # Returns the gateway customer for the user.
24
+ # @return [Spree::GatewayCustomer]
25
+ def gateway_customer
26
+ return if user.blank?
27
+
28
+ payment_method.gateway_customers.find_by(user: user)
29
+ end
9
30
  end
10
31
  end
@@ -50,8 +50,11 @@ module Spree
50
50
  if defined?(PgSearch)
51
51
  include PgSearch::Model
52
52
 
53
- pg_search_scope :search_by_name, against: { name: 'A', meta_title: 'B' },
54
- using: { tsearch: { prefix: true, any_word: true } }
53
+ if connected? && connection.extension_enabled?('pg_trgm')
54
+ pg_search_scope :search_by_name, against: { name: 'A', meta_title: 'B' }, using: { trigram: { threshold: 0.3, word_similarity: true } }
55
+ else
56
+ pg_search_scope :search_by_name, against: { name: 'A', meta_title: 'B' }, using: { tsearch: { any_word: true, prefix: true } }
57
+ end
55
58
  end
56
59
 
57
60
  before_save :set_slug
@@ -29,7 +29,6 @@ module Spree
29
29
  after_update :conditional_touch_records
30
30
 
31
31
  delegate :name, :iso3, :iso, :iso_name, to: :country, prefix: true
32
- delegate :show_company_address_field?, to: :address
33
32
 
34
33
  def state_text
35
34
  state.try(:abbr) || state.try(:name) || state_name
@@ -136,6 +135,7 @@ module Spree
136
135
  Spree::Address.new(
137
136
  address1: address1,
138
137
  address2: address2,
138
+ company: company,
139
139
  city: city,
140
140
  state: state,
141
141
  state_name: state_name,
@@ -159,6 +159,10 @@ module Spree
159
159
  false
160
160
  end
161
161
 
162
+ def show_company_address_field?
163
+ true
164
+ end
165
+
162
166
  def display_name
163
167
  @display_name ||= [admin_name, name].delete_if(&:blank?).join(' / ')
164
168
  end
@@ -48,6 +48,9 @@ module Spree
48
48
  preference :password_protected, :boolean, default: false
49
49
  # Checkout preferences
50
50
  preference :guest_checkout, :boolean, default: true
51
+ preference :special_instructions_enabled, :boolean, default: false
52
+ # Address preferences
53
+ preference :company_field_enabled, :boolean, default: false
51
54
  # digital assets preferences
52
55
  preference :limit_digital_download_count, :boolean, default: true
53
56
  preference :limit_digital_download_days, :boolean, default: true
@@ -36,6 +36,13 @@ module Spree
36
36
  @wished_items_count ||= variant_ids.count
37
37
  end
38
38
 
39
+ # returns the variant ids in the wishlist
40
+ #
41
+ # @return [Array<Integer>]
42
+ def variant_ids
43
+ @variant_ids ||= wished_items.pluck(:variant_id)
44
+ end
45
+
39
46
  def self.get_by_param(param)
40
47
  find_by(token: param)
41
48
  end
@@ -136,8 +136,15 @@ module Spree
136
136
  o.position = opt[:position]
137
137
  o.save!
138
138
  end
139
- option_value = option_type.option_values.where(name: opt[:value].parameterize).first_or_initialize do |o|
140
- o.name = o.presentation = opt[:value]
139
+
140
+ option_value_identificator = if opt[:option_value_name].present?
141
+ opt[:option_value_name]
142
+ else
143
+ opt[:option_value_presentation].parameterize
144
+ end
145
+
146
+ option_value = option_type.option_values.where(name: option_value_identificator).first_or_initialize do |o|
147
+ o.name = o.presentation = opt[:option_value_presentation]
141
148
  o.save!
142
149
  end
143
150
 
@@ -30,6 +30,15 @@
30
30
  <div class="flex-shrink-0">
31
31
  <%= payment_method_icon_tag source.class.to_s.demodulize.downcase, height: 30 %>
32
32
  </div>
33
+ <div>
34
+ <% if payment.payment_method.respond_to?(:source_partial_name) %>
35
+ <%= render partial: "spree/payment_sources/#{payment.payment_method.source_partial_name}", locals: { payment: payment, source: source } %>
36
+ <% elsif source.respond_to?(:name) %>
37
+ <%= source.name %>
38
+ <% else %>
39
+ <%= source.class.to_s.demodulize.downcase %>
40
+ <% end %>
41
+ </div>
33
42
  <% else %>
34
43
  <div class="flex-shrink-0">
35
44
  <%= payment_method_icon_tag payment.payment_method.payment_icon_name %>
@@ -567,6 +567,7 @@ en:
567
567
  receive: Mark as received
568
568
  refund: Refund
569
569
  reject: Reject
570
+ remove: Remove
570
571
  resend: Resend
571
572
  resolve: Mark as resolved
572
573
  save: Save
@@ -630,6 +631,7 @@ en:
630
631
  successfully_updated: Updated successfully
631
632
  unsuccessfully_saved: There was an error while trying to save your address.
632
633
  unsuccessfully_updated: There was an update while trying to update your address.
634
+ address_settings: Address settings
633
635
  addresses: Addresses
634
636
  adjustable: Adjustable
635
637
  adjustment: Adjustment
@@ -0,0 +1,5 @@
1
+ class AddCompanyToSpreeStockLocations < ActiveRecord::Migration[7.2]
2
+ def change
3
+ add_column :spree_stock_locations, :company, :string, if_not_exists: true
4
+ end
5
+ end
@@ -37,7 +37,7 @@ module Spree
37
37
  preference :auto_capture_on_dispatch, :boolean, default: false # Captures payment for each shipment in Shipment#after_ship callback, and makes Shipment.ready when payment authorized.
38
38
  preference :binary_inventory_cache, :boolean, default: false, deprecated: true # only invalidate product cache when a stock item changes whether it is in_stock
39
39
  preference :checkout_zone, :string, default: nil, deprecated: true # replace with the name of a zone if you would like to limit the countries
40
- preference :company, :boolean, default: false # Request company field for billing and shipping addr
40
+ preference :company, :boolean, default: false, deprecated: 'Use the company_field_enabled preference in the Spree::Store model' # Request company field for billing and shipping addr
41
41
  preference :currency, :string, default: 'USD', deprecated: true
42
42
  preference :credit_to_new_allocation, :boolean, default: false
43
43
  preference :disable_sku_validation, :boolean, default: false # when turned off disables the built-in SKU uniqueness validation
@@ -98,6 +98,7 @@ module Spree
98
98
  Rails.application.config.spree.payment_methods = [
99
99
  Spree::Gateway::Bogus,
100
100
  Spree::Gateway::BogusSimple,
101
+ Spree::Gateway::CustomPaymentSourceMethod,
101
102
  Spree::PaymentMethod::Check,
102
103
  Spree::PaymentMethod::StoreCredit
103
104
  ]
@@ -1,5 +1,5 @@
1
1
  module Spree
2
- VERSION = '5.1.0.beta2'.freeze
2
+ VERSION = '5.1.0.beta4'.freeze
3
3
 
4
4
  def self.version
5
5
  VERSION
@@ -27,6 +27,8 @@ module Spree
27
27
  :page_section_attributes,
28
28
  :payment_attributes,
29
29
  :payment_method_attributes,
30
+ :post_attributes,
31
+ :post_category_attributes,
30
32
  :product_attributes,
31
33
  :promotion_attributes,
32
34
  :promotion_rule_attributes,
@@ -101,7 +103,7 @@ module Spree
101
103
 
102
104
  @@digital_link_attributes = [:access_counter]
103
105
 
104
- @@export_attributes = [:type, :format, :record_selection, search_params: {}]
106
+ @@export_attributes = [:type, :format, :record_selection, :search_params]
105
107
 
106
108
  @@image_attributes = [:alt, :attachment, :position, :viewable_type, :viewable_id]
107
109
 
@@ -125,16 +127,20 @@ module Spree
125
127
 
126
128
  @@page_attributes = [:name, :slug, :meta_title, :meta_description, :meta_keywords]
127
129
 
128
- @@page_block_attributes = [:type, :name, :position]
130
+ @@page_block_attributes = [:type, :name, :text, :position]
129
131
 
130
- @@page_link_attributes = [:linkable_id, :linkable_type, :position, :label, :url]
132
+ @@page_link_attributes = [:linkable_id, :linkable_type, :position, :label, :url, :open_in_new_tab]
131
133
 
132
- @@page_section_attributes = [:type, :name, :position, :asset]
134
+ @@page_section_attributes = [:type, :name, :position, :asset, :text, :description]
133
135
 
134
136
  @@payment_attributes = [:amount, :payment_method_id, :payment_method]
135
137
 
136
138
  @@payment_method_attributes = [:name, :type, :description, :active, :display_on, :auto_capture, :position]
137
139
 
140
+ @@post_attributes = [:title, :meta_title, :meta_description, :slug, :author_id, :post_category_id, :published_at, :content, :excerpt, :image, tag_list: []]
141
+
142
+ @@post_category_attributes = [:title, :slug, :description]
143
+
138
144
  @@product_properties_attributes = [:property_name, :property_id, :value, :position, :_destroy]
139
145
 
140
146
  @@product_attributes = [
@@ -207,7 +213,7 @@ module Spree
207
213
  @@stock_item_attributes = [:variant_id, :stock_location_id, :backorderable, :count_on_hand]
208
214
 
209
215
  @@stock_location_attributes = [
210
- :name, :active, :address1, :address2, :city, :zipcode,
216
+ :name, :active, :address1, :address2, :city, :zipcode, :company,
211
217
  :backorderable_default, :state_name, :state_id, :country_id, :phone,
212
218
  :propagate_all_variants
213
219
  ]
@@ -265,7 +271,7 @@ module Spree
265
271
  :weight, :height, :width, :depth, :sku, :barcode, :cost_currency,
266
272
  :weight_unit, :dimensions_unit,
267
273
  {
268
- options: [:id, :name, :value, :position, :_destroy],
274
+ options: [:id, :name, :option_value_presentation, :option_value_name, :position, :_destroy],
269
275
  stock_items_attributes: [:id, :count_on_hand, :stock_location_id, :backorderable, :_destroy],
270
276
  prices_attributes: [:id, :amount, :compare_at_amount, :currency, :_destroy],
271
277
  price: {},
@@ -20,5 +20,7 @@ FactoryBot.define do
20
20
  factory :newsletter_page_section, class: Spree::PageSections::Newsletter
21
21
 
22
22
  factory :video_page_section, class: Spree::PageSections::Video
23
+
24
+ factory :image_with_text_page_section, class: Spree::PageSections::ImageWithText
23
25
  end
24
26
  end
@@ -14,6 +14,11 @@ FactoryBot.define do
14
14
  create(:refund, amount: 5, payment: payment)
15
15
  end
16
16
  end
17
+
18
+ factory :custom_payment, class: Spree::Payment do
19
+ payment_method { create(:custom_payment_method, stores: [order.store]) }
20
+ source { create(:payment_source, user: order.user, payment_method: payment_method) }
21
+ end
17
22
  end
18
23
 
19
24
  factory :check_payment, class: Spree::Payment do
@@ -37,4 +37,9 @@ FactoryBot.define do
37
37
  active { true }
38
38
  auto_capture { true }
39
39
  end
40
+
41
+ factory :custom_payment_method, parent: :payment_method, class: Spree::Gateway::CustomPaymentSourceMethod do
42
+ type { 'Spree::Gateway::CustomPaymentSourceMethod' }
43
+ name { 'Custom' }
44
+ end
40
45
  end
@@ -0,0 +1,5 @@
1
+ FactoryBot.define do
2
+ factory :payment_source, class: Spree::PaymentSource do
3
+ association(:payment_method, factory: :custom_payment_method)
4
+ end
5
+ end
@@ -1,6 +1,6 @@
1
1
  FactoryBot.define do
2
2
  factory :post, class: Spree::Post do
3
- post_category { create(:post_category) }
3
+ post_category { create(:post_category, store: Spree::Store.default || create(:store)) }
4
4
  title { FFaker::Lorem.sentence }
5
5
  content { FFaker::Lorem.paragraph }
6
6
  published_at { Time.current }
@@ -8,7 +8,7 @@ FactoryBot.define do
8
8
  end
9
9
 
10
10
  trait :preview do
11
- parent { create(:theme) }
11
+ parent { Spree::Store.default.default_theme || create(:theme, store: store) }
12
12
  end
13
13
  end
14
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.0.beta2
4
+ version: 5.1.0.beta4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Schofield
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2025-05-22 00:00:00.000000000 Z
13
+ date: 2025-06-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: i18n-tasks
@@ -622,6 +622,7 @@ files:
622
622
  - app/models/concerns/spree/number_as_param.rb
623
623
  - app/models/concerns/spree/number_identifier.rb
624
624
  - app/models/concerns/spree/parameterizable_name.rb
625
+ - app/models/concerns/spree/payment_source_concern.rb
625
626
  - app/models/concerns/spree/previewable.rb
626
627
  - app/models/concerns/spree/product_scopes.rb
627
628
  - app/models/concerns/spree/ransackable_attributes.rb
@@ -686,6 +687,7 @@ files:
686
687
  - app/models/spree/gateway.rb
687
688
  - app/models/spree/gateway/bogus.rb
688
689
  - app/models/spree/gateway/bogus_simple.rb
690
+ - app/models/spree/gateway/custom_payment_source_method.rb
689
691
  - app/models/spree/gateway_customer.rb
690
692
  - app/models/spree/image.rb
691
693
  - app/models/spree/image/configuration/active_storage.rb
@@ -1158,6 +1160,7 @@ files:
1158
1160
  - db/migrate/20250418174652_add_resource_to_spree_role_users.rb
1159
1161
  - db/migrate/20250508060800_add_selected_locale_to_spree_admin_users.rb
1160
1162
  - db/migrate/20250509143831_add_session_id_to_spree_assets.rb
1163
+ - db/migrate/20250527134027_add_company_to_spree_stock_locations.rb
1161
1164
  - db/seeds.rb
1162
1165
  - lib/friendly_id/paranoia.rb
1163
1166
  - lib/generators/spree/authentication/custom/custom_generator.rb
@@ -1265,6 +1268,7 @@ files:
1265
1268
  - lib/spree/testing_support/factories/payment_capture_event_factory.rb
1266
1269
  - lib/spree/testing_support/factories/payment_factory.rb
1267
1270
  - lib/spree/testing_support/factories/payment_method_factory.rb
1271
+ - lib/spree/testing_support/factories/payment_source_factory.rb
1268
1272
  - lib/spree/testing_support/factories/post_category_factory.rb
1269
1273
  - lib/spree/testing_support/factories/post_factory.rb
1270
1274
  - lib/spree/testing_support/factories/price_factory.rb
@@ -1344,9 +1348,9 @@ licenses:
1344
1348
  - BSD-3-Clause
1345
1349
  metadata:
1346
1350
  bug_tracker_uri: https://github.com/spree/spree/issues
1347
- changelog_uri: https://github.com/spree/spree/releases/tag/v5.1.0.beta2
1351
+ changelog_uri: https://github.com/spree/spree/releases/tag/v5.1.0.beta4
1348
1352
  documentation_uri: https://docs.spreecommerce.org/
1349
- source_code_uri: https://github.com/spree/spree/tree/v5.1.0.beta2
1353
+ source_code_uri: https://github.com/spree/spree/tree/v5.1.0.beta4
1350
1354
  post_install_message:
1351
1355
  rdoc_options: []
1352
1356
  require_paths: