Move primary taxon to variant

This commit is contained in:
Matt-Yorkley
2023-08-07 11:03:15 +01:00
committed by Gaetan Craig-Riou
parent d8641bf576
commit 2ef266390d
4 changed files with 17 additions and 9 deletions

View File

@@ -28,16 +28,11 @@ module Spree
acts_as_paranoid
after_create :ensure_standard_variant
around_destroy :destruction
after_save :update_units
searchable_attributes :supplier_id, :primary_taxon_id, :meta_keywords, :sku
searchable_associations :supplier, :properties, :primary_taxon, :variants
searchable_attributes :supplier_id, :meta_keywords, :sku
searchable_associations :supplier, :properties, :variants
searchable_scopes :active, :with_properties
belongs_to :supplier, class_name: 'Enterprise', optional: false, touch: true
belongs_to :primary_taxon, class_name: 'Spree::Taxon', optional: false, touch: true
has_one :image, class_name: "Spree::Image", as: :viewable, dependent: :destroy
@@ -79,6 +74,10 @@ module Spree
attr_accessor :price, :display_as, :unit_value, :unit_description, :tax_category_id,
:shipping_category_id
after_create :ensure_standard_variant
around_destroy :destruction
after_save :update_units
scope :with_properties, ->(*property_ids) {
left_outer_joins(:product_properties).
left_outer_joins(:supplier_properties).

View File

@@ -13,8 +13,8 @@ module Spree
acts_as_paranoid
searchable_attributes :sku, :display_as, :display_name
searchable_associations :product, :default_price
searchable_attributes :sku, :display_as, :display_name, :primary_taxon_id
searchable_associations :product, :default_price, :primary_taxon
searchable_scopes :active, :deleted
NAME_FIELDS = ["display_name", "display_as", "weight", "unit_value", "unit_description"].freeze
@@ -28,6 +28,7 @@ module Spree
belongs_to :product, -> { with_deleted }, touch: true, class_name: 'Spree::Product'
belongs_to :tax_category, class_name: 'Spree::TaxCategory'
belongs_to :shipping_category, class_name: 'Spree::ShippingCategory', optional: false
belongs_to :primary_taxon, class_name: 'Spree::Taxon', touch: true, optional: false
delegate :name, :name=, :description, :description=, :meta_keywords, to: :product

View File

@@ -0,0 +1,5 @@
class AddTaxonsToVariants < ActiveRecord::Migration[7.0]
def change
add_reference :spree_variants, :primary_taxon, foreign_key: { to_table: :spree_taxons }
end
end

View File

@@ -979,6 +979,8 @@ ActiveRecord::Schema[7.0].define(version: 2024_02_13_044159) do
t.datetime "updated_at", default: -> { "now()" }, null: false
t.bigint "tax_category_id"
t.bigint "shipping_category_id"
t.bigint "primary_taxon_id"
t.index ["primary_taxon_id"], name: "index_spree_variants_on_primary_taxon_id"
t.index ["product_id"], name: "index_variants_on_product_id"
t.index ["shipping_category_id"], name: "index_spree_variants_on_shipping_category_id"
t.index ["sku"], name: "index_spree_variants_on_sku"
@@ -1225,6 +1227,7 @@ ActiveRecord::Schema[7.0].define(version: 2024_02_13_044159) do
add_foreign_key "spree_variants", "spree_products", column: "product_id", name: "spree_variants_product_id_fk"
add_foreign_key "spree_variants", "spree_shipping_categories", column: "shipping_category_id"
add_foreign_key "spree_variants", "spree_tax_categories", column: "tax_category_id"
add_foreign_key "spree_variants", "spree_taxons", column: "primary_taxon_id"
add_foreign_key "spree_zone_members", "spree_zones", column: "zone_id", name: "spree_zone_members_zone_id_fk"
add_foreign_key "subscription_line_items", "spree_variants", column: "variant_id", name: "subscription_line_items_variant_id_fk"
add_foreign_key "subscription_line_items", "subscriptions", name: "subscription_line_items_subscription_id_fk"