From a69ab2ef715efe45872419b0571a528bbe5180bf Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 7 Aug 2023 14:29:02 +0100 Subject: [PATCH] Remove multiple taxons on products functionality --- app/models/spree/classification.rb | 21 --------------------- app/models/spree/product.rb | 15 --------------- 2 files changed, 36 deletions(-) delete mode 100644 app/models/spree/classification.rb diff --git a/app/models/spree/classification.rb b/app/models/spree/classification.rb deleted file mode 100644 index 696595a033..0000000000 --- a/app/models/spree/classification.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -module Spree - class Classification < ApplicationRecord - self.table_name = 'spree_products_taxons' - belongs_to :product, class_name: "Spree::Product", touch: true - belongs_to :taxon, class_name: "Spree::Taxon", touch: true - - before_destroy :dont_destroy_if_primary_taxon - - private - - def dont_destroy_if_primary_taxon - return unless product.primary_taxon == taxon - - errors.add :base, I18n.t(:spree_classification_primary_taxon_error, taxon: taxon.name, - product: product.name) - throw :abort - end - end -end diff --git a/app/models/spree/product.rb b/app/models/spree/product.rb index 17f354513d..fad2d606dd 100755 --- a/app/models/spree/product.rb +++ b/app/models/spree/product.rb @@ -39,8 +39,6 @@ module Spree has_many :product_properties, dependent: :destroy has_many :properties, through: :product_properties - has_many :classifications, dependent: :delete_all - has_many :taxons, through: :classifications has_many :variants, -> { order("spree_variants.position ASC") }, class_name: 'Spree::Variant', dependent: :destroy @@ -78,10 +76,7 @@ module Spree # these values are persisted on the product's variant attr_accessor :price, :display_as, :unit_value, :unit_description, :tax_category_id - before_save :add_primary_taxon_to_taxons - after_create :ensure_standard_variant - after_save :remove_previous_primary_taxon_from_taxons after_save :update_units scope :with_properties, ->(*property_ids) { @@ -290,16 +285,6 @@ module Spree Enterprise.distributing_products(id).each(&:touch) end - def add_primary_taxon_to_taxons - taxons << primary_taxon unless taxons.include? primary_taxon - end - - def remove_previous_primary_taxon_from_taxons - return unless saved_change_to_primary_taxon_id? && primary_taxon_id_before_last_save - - taxons.destroy(primary_taxon_id_before_last_save) - end - def ensure_standard_variant return unless variants.empty?