Delete dead code

This commit is contained in:
Matt-Yorkley
2023-05-06 00:26:24 +01:00
parent 896e4c45f2
commit bfcf1203ac

View File

@@ -87,7 +87,6 @@ module Spree
delegate :images_attributes=, :display_as=, to: :master
after_create :set_master_variant_defaults
after_create :build_variants_from_option_values_hash, if: :option_values_hash
after_save :save_master
delegate :images, to: :master, prefix: true
@@ -116,16 +115,12 @@ module Spree
presence: { if: ->(p) { p.variant_unit == 'items' } }
validate :validate_image_for_master
attr_accessor :option_values_hash
accepts_nested_attributes_for :product_properties,
allow_destroy: true,
reject_if: lambda { |pp| pp[:property_name].blank? }
make_permalink order: :name
alias :options :product_option_types
after_initialize :ensure_master
after_initialize :set_available_on_to_now, if: :new_record?
@@ -260,32 +255,12 @@ module Spree
end
end
# Ensures option_types and product_option_types exist for keys in option_values_hash
def ensure_option_types_exist_for_values_hash
return if option_values_hash.nil?
option_values_hash.keys.map(&:to_i).each do |id|
option_type_ids << id unless option_type_ids.include?(id)
unless product_option_types.pluck(:option_type_id).include?(id)
product_option_types.create(option_type_id: id)
end
end
end
# for adding products which are closely related to existing ones
def duplicate
duplicator = Spree::Core::ProductDuplicator.new(self)
duplicator.duplicate
end
# split variants list into hash which shows mapping of opt value onto matching variants
# eg categorise_variants_from_option(color) => {"red" -> [...], "blue" -> [...]}
def categorise_variants_from_option(opt_type)
return {} unless option_types.include?(opt_type)
variants.active.group_by { |v| v.option_values.detect { |o| o.option_type == opt_type } }
end
def self.like_any(fields, values)
where fields.map { |field|
values.map { |value|
@@ -376,21 +351,6 @@ module Spree
private
# Builds variants from a hash of option types & values
def build_variants_from_option_values_hash
ensure_option_types_exist_for_values_hash
values = option_values_hash.values
values = values.inject(values.shift) { |memo, value| memo.product(value).map(&:flatten) }
values.each do |ids|
variants.create(
option_value_ids: ids,
price: master.price
)
end
save
end
# ensures the master variant is flagged as such
def set_master_variant_defaults
master.is_master = true