Skip to content

Commit

Permalink
Merge pull request openfoodfoundation#11579 from macanudo527/remove_d…
Browse files Browse the repository at this point in the history
…elegate_belongs_to

Remove Deprecated delegate_belongs_to
  • Loading branch information
drummer83 authored Oct 1, 2023
2 parents 11ea4d9 + 91b251a commit 8150a8b
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 104 deletions.
1 change: 0 additions & 1 deletion app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

class ApplicationRecord < ActiveRecord::Base
include DelegateBelongsTo
include Spree::Core::Permalinks
include Spree::Preferences::Preferable
include Searchable
Expand Down
12 changes: 7 additions & 5 deletions app/models/product_import/entry_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,14 @@ def enterprise_field
end

def mark_as_new_variant(entry, product_id)
new_variant = Spree::Variant.new(
entry.assignable_attributes.except('id', 'product_id', 'on_hand', 'on_demand',
'variant_unit', 'variant_unit_name',
'variant_unit_scale', 'primary_taxon_id')
variant_attributes = entry.assignable_attributes.except(
'id', 'product_id', 'on_hand', 'on_demand', 'variant_unit', 'variant_unit_name',
'variant_unit_scale', 'primary_taxon_id'
)
# Variant needs a product. Product needs to be assigned first in order for
# delegate to work. name= will fail otherwise.
new_variant = Spree::Variant.new(product_id:, **variant_attributes)

new_variant.save
if new_variant.persisted?
if entry.attributes['on_demand'].present?
Expand All @@ -82,7 +85,6 @@ def mark_as_new_variant(entry, product_id)
end
end

new_variant.product_id = product_id
check_on_hand_nil(entry, new_variant)

if new_variant.valid?
Expand Down
3 changes: 1 addition & 2 deletions app/models/spree/gateway.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# frozen_string_literal: true

require 'concerns/payment_method_distributors'
require 'spree/core/delegate_belongs_to'

module Spree
class Gateway < PaymentMethod
acts_as_taggable
include PaymentMethodDistributors

delegate_belongs_to :provider, :authorize, :purchase, :capture, :void, :credit
delegate :authorize, :purchase, :capture, :void, :credit, to: :provider

validates :name, :type, presence: true

Expand Down
10 changes: 7 additions & 3 deletions app/models/spree/variant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Variant < ApplicationRecord
belongs_to :tax_category, class_name: 'Spree::TaxCategory'
belongs_to :shipping_category, class_name: 'Spree::ShippingCategory', optional: false

delegate_belongs_to :product, :name, :description, :meta_keywords
delegate :name, :name=, :description, :description=, :meta_keywords, to: :product

has_many :inventory_units, inverse_of: :variant
has_many :line_items, inverse_of: :variant
Expand All @@ -51,8 +51,8 @@ class Variant < ApplicationRecord
has_many :prices,
class_name: 'Spree::Price',
dependent: :destroy
delegate_belongs_to :default_price, :display_price, :display_amount,
:price, :price=, :currency
delegate :display_price, :display_amount, :price, :price=, :currency, :currency=,
to: :find_or_build_default_price

has_many :exchange_variants
has_many :exchanges, through: :exchange_variants
Expand Down Expand Up @@ -221,6 +221,10 @@ def save_default_price
default_price.save if default_price && (default_price.changed? || default_price.new_record?)
end

def find_or_build_default_price
default_price || build_default_price
end

def set_cost_currency
self.cost_currency = Spree::Config[:currency] if cost_currency.blank?
end
Expand Down
1 change: 0 additions & 1 deletion lib/spree/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def self.config
require 'spree/i18n'
require 'spree/money'

require 'spree/core/delegate_belongs_to'
require 'spree/core/permalinks'
require 'spree/core/token_resource'
require 'spree/core/product_duplicator'
Expand Down
92 changes: 0 additions & 92 deletions lib/spree/core/delegate_belongs_to.rb

This file was deleted.

0 comments on commit 8150a8b

Please sign in to comment.