Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

refactor(core): rename Taxon classes to Category and de-rule the model

Łukasz Adamczyk3e8d8bd622a0
diff --git a/packages/admin-sdk/src/types/generated/Product.ts b/packages/admin-sdk/src/types/generated/Product.ts
index 9ee24ccf74..71129f92cd 100644
--- a/packages/admin-sdk/src/types/generated/Product.ts
+++ b/packages/admin-sdk/src/types/generated/Product.ts
@@ -1,4 +1,4 @@
-// Typelizer digest d8c7e2d1a99bf854b06e5868a89fb592
+// Typelizer digest cb42889c9b73f728609a007abb834f28
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {Price, PriceHistory, Media, Variant, OptionType, OptionValue, Category, CustomField, ProductPublication, Channel} from '@/types'
diff --git a/packages/admin-sdk/src/types/generated/PromotionRule.ts b/packages/admin-sdk/src/types/generated/PromotionRule.ts
index 296526ca6f..eb9fc21a43 100644
--- a/packages/admin-sdk/src/types/generated/PromotionRule.ts
+++ b/packages/admin-sdk/src/types/generated/PromotionRule.ts
@@ -1,4 +1,4 @@
-// Typelizer digest d0302c436cdf25cfa7b737c2c8bf25d9
+// Typelizer digest 2abc4070a19a02daecd2c482e72d9e88
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {Product, Category, Customer, CustomerGroup, Country, Channel, Market} from '@/types'
diff --git a/packages/sdk/src/types/generated/Product.ts b/packages/sdk/src/types/generated/Product.ts
index a00c757737..3f65ae1496 100644
--- a/packages/sdk/src/types/generated/Product.ts
+++ b/packages/sdk/src/types/generated/Product.ts
@@ -1,4 +1,4 @@
-// Typelizer digest a1b4f36ab287f3abedd4060df2a63032
+// Typelizer digest b2e948164151b01e23a6d84ad624195b
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {Price, PriceHistory, Media, Variant, OptionType, OptionValue, Category, CustomField} from '@/types'
diff --git a/spree/admin/app/controllers/spree/admin/classifications_controller.rb b/spree/admin/app/controllers/spree/admin/classifications_controller.rb
index 7dbd4c82a5..cf06d39865 100644
--- a/spree/admin/app/controllers/spree/admin/classifications_controller.rb
+++ b/spree/admin/app/controllers/spree/admin/classifications_controller.rb
@@ -10,7 +10,7 @@ module Spree
# create classifications in bulk
def create
products = current_store.products.accessible_by(current_ability, :update).where(id: params[:ids].compact.uniq)
- Spree::Taxons::AddProducts.call(taxons: Spree::Taxon.where(id: parent.id), products: products)
+ Spree::Categories::AddProducts.call(categories: Spree::Category.where(id: parent.id), products: products)
parent.reload
@classifications = collection
diff --git a/spree/admin/app/controllers/spree/admin/products_controller.rb b/spree/admin/app/controllers/spree/admin/products_controller.rb
index 5bcf729380..c96649593a 100644
--- a/spree/admin/app/controllers/spree/admin/products_controller.rb
+++ b/spree/admin/app/controllers/spree/admin/products_controller.rb
@@ -103,14 +103,14 @@ module Spree
def bulk_remove_from_taxons
taxons = current_store.taxons.accessible_by(current_ability, :manage).where(id: params[:taxon_ids])
- Spree::Taxons::RemoveProducts.call(taxons: taxons, products: bulk_collection)
+ Spree::Categories::RemoveProducts.call(categories: taxons, products: bulk_collection)
handle_bulk_operation_response
end
def bulk_add_to_taxons
taxons = current_store.taxons.accessible_by(current_ability, :manage).where(id: params[:taxon_ids])
- Spree::Taxons::AddProducts.call(taxons: taxons, products: bulk_collection)
+ Spree::Categories::AddProducts.call(categories: taxons, products: bulk_collection)
handle_bulk_operation_response
end
diff --git a/spree/admin/app/helpers/spree/admin/products_helper.rb b/spree/admin/app/helpers/spree/admin/products_helper.rb
index 6883c53325..b9b1ba68fd 100644
--- a/spree/admin/app/helpers/spree/admin/products_helper.rb
+++ b/spree/admin/app/helpers/spree/admin/products_helper.rb
@@ -68,7 +68,7 @@ module Spree
def map_categories(product)
category_tree = ['n/a', 'n/a']
- category = product.main_taxon&.pretty_name.to_s
+ category = product.primary_category&.pretty_name.to_s
return category_tree if category.blank?
category.split('->').map(&:strip).map.with_index { |c, index| category_tree[index] = c }
diff --git a/spree/admin/app/helpers/spree/admin/taxons_helper.rb b/spree/admin/app/helpers/spree/admin/taxons_helper.rb
index de9be18a4b..f740b8975d 100644
--- a/spree/admin/app/helpers/spree/admin/taxons_helper.rb
+++ b/spree/admin/app/helpers/spree/admin/taxons_helper.rb
@@ -15,7 +15,7 @@ module Spree
end
def taxon_sort_options_for_select
- @taxon_sort_options_for_select ||= Spree::Taxon::SORT_ORDERS.map do |sort_order|
+ @taxon_sort_options_for_select ||= Spree::Category::SORT_ORDERS.map do |sort_order|
[
Spree.t("products_sort_options.#{sort_order.underscore}"),
sort_order
diff --git a/spree/admin/app/views/spree/admin/classifications/index.html.erb b/spree/admin/app/views/spree/admin/classifications/index.html.erb
index f6d0aa9186..2dec814c07 100644
--- a/spree/admin/app/views/spree/admin/classifications/index.html.erb
+++ b/spree/admin/app/views/spree/admin/classifications/index.html.erb
@@ -6,14 +6,14 @@
data-sortable-response-kind-value="turbo-stream">
<%= render partial: 'spree/admin/classifications/classification',
collection: @sorted_classifications,
- cached: can?(:delete, Spree::Classification) ? spree_base_cache_scope : false %>
+ cached: can?(:delete, Spree::ProductCategory) ? spree_base_cache_scope : false %>
</div>
<% else %>
<p class="text-center text-gray-600 px-12 pt-12 pb-2">
<%= Spree.t(:no_products_added) %>
</p>
<p class="text-center">
- <% if can?(:create, Spree::Classification) && @taxon.manual? %>
+ <% if can?(:create, Spree::ProductCategory) && @taxon.manual? %>
<%= link_to_with_icon 'plus', Spree.t(:add_products), spree.new_admin_taxon_classification_path(@taxon), class: 'btn btn-secondary', data: { turbo_frame: 'dialog', action: 'dialog#open' } %>
<% end %>
<% end %>
diff --git a/spree/admin/app/views/spree/admin/products/form/_categorization.html.erb b/spree/admin/app/views/spree/admin/products/form/_categorization.html.erb
index 90cc57ca2d..b9cb3ba0a9 100644
--- a/spree/admin/app/views/spree/admin/products/form/_categorization.html.erb
+++ b/spree/admin/app/views/spree/admin/products/form/_categorization.html.erb
@@ -1,4 +1,4 @@
-<% if can?(:manage, Spree::Classification) || can?(:manage, ActsAsTaggableOn::Tag) %>
+<% if can?(:manage, Spree::ProductCategory) || can?(:manage, ActsAsTaggableOn::Tag) %>
<div class="card mb-6">
<div class="card-header">
<h5 class="card-title">
@@ -7,7 +7,7 @@
</div>
<div class="card-body">
<div class="form-group">
- <% if can? :manage, Spree::Classification %>
+ <% if can? :manage, Spree::ProductCategory %>
<%= f.label :taxon_ids, Spree.t(:taxonomies) %>
<%= tom_select_tag 'product[taxon_ids]',
diff --git a/spree/admin/app/views/spree/admin/shared/sortable_tree/_taxonomy.html.erb b/spree/admin/app/views/spree/admin/shared/sortable_tree/_taxonomy.html.erb
index e30698a737..633221bd7c 100644
--- a/spree/admin/app/views/spree/admin/shared/sortable_tree/_taxonomy.html.erb
+++ b/spree/admin/app/views/spree/admin/shared/sortable_tree/_taxonomy.html.erb
@@ -34,7 +34,7 @@
<%= icon('dots-vertical', class: 'mr-0') %>
<% end %>
<%= dropdown_menu do %>
- <% if can?(:create, Spree::Taxon) %>
+ <% if can?(:create, Spree::Category) %>
<%= link_to_with_icon 'plus', Spree.t(:new_nested_taxon), spree.new_admin_taxonomy_taxon_path(taxonomy, taxon: { parent_id: taxon.id }), class: 'dropdown-item' %>
<div class="dropdown-divider"></div>
<% end %>
diff --git a/spree/admin/app/views/spree/admin/taxonomies/show.html.erb b/spree/admin/app/views/spree/admin/taxonomies/show.html.erb
index c74be67e8a..c1be28b9c9 100644
--- a/spree/admin/app/views/spree/admin/taxonomies/show.html.erb
+++ b/spree/admin/app/views/spree/admin/taxonomies/show.html.erb
@@ -5,7 +5,7 @@
<% content_for :page_actions do %>
<%= link_to_with_icon 'plus', Spree.t(:new_taxon), spree.new_admin_taxonomy_taxon_path(@taxonomy), class: 'btn btn-primary' %>
-<% end if can?(:create, Spree::Taxon) %>
+<% end if can?(:create, Spree::Category) %>
<% content_for :page_actions_dropdown do %>
<%= link_to_edit(@taxonomy.root, url: spree.edit_admin_taxonomy_taxon_path(@taxonomy, @taxonomy.root), class: 'text-left dropdown-item') %>
diff --git a/spree/admin/app/views/spree/admin/taxons/_form.html.erb b/spree/admin/app/views/spree/admin/taxons/_form.html.erb
index 0abba2e676..eab506e043 100644
--- a/spree/admin/app/views/spree/admin/taxons/_form.html.erb
+++ b/spree/admin/app/views/spree/admin/taxons/_form.html.erb
@@ -53,7 +53,7 @@
</span>
</h5>
- <% if @taxon.manual? && can?(:create, Spree::Classification) %>
+ <% if @taxon.manual? && can?(:create, Spree::ProductCategory) %>
<%= link_to_with_icon 'plus', Spree.t(:add_products), spree.new_admin_taxon_classification_path(@taxon), class: 'btn btn-secondary btn-sm', data: { turbo_frame: 'dialog', action: 'dialog#open' } %>
<% end %>
</div>
diff --git a/spree/admin/config/initializers/spree_admin_tables.rb b/spree/admin/config/initializers/spree_admin_tables.rb
index 897cc34789..4e50550267 100644
--- a/spree/admin/config/initializers/spree_admin_tables.rb
+++ b/spree/admin/config/initializers/spree_admin_tables.rb
@@ -171,7 +171,7 @@ Rails.application.config.after_initialize do
body: 'admin.bulk_ops.products.body.add_to_taxons',
form_partial: 'spree/admin/bulk_operations/forms/taxon_picker',
position: 40,
- condition: -> { can?(:manage, Spree::Classification) }
+ condition: -> { can?(:manage, Spree::ProductCategory) }
Spree.admin.tables.products.add_bulk_action :remove_from_taxons,
label: 'admin.bulk_ops.products.title.remove_from_taxons',
@@ -180,7 +180,7 @@ Rails.application.config.after_initialize do
body: 'admin.bulk_ops.products.body.remove_from_taxons',
form_partial: 'spree/admin/bulk_operations/forms/taxon_picker',
position: 50,
- condition: -> { can?(:manage, Spree::Classification) }
+ condition: -> { can?(:manage, Spree::ProductCategory) }
Spree.admin.tables.products.add_bulk_action :add_tags,
label: 'admin.bulk_ops.products.title.add_tags',
diff --git a/spree/admin/spec/controllers/spree/admin/classifications_controller_spec.rb b/spree/admin/spec/controllers/spree/admin/classifications_controller_spec.rb
index e6d96d61ae..8811db93d7 100644
--- a/spree/admin/spec/controllers/spree/admin/classifications_controller_spec.rb
+++ b/spree/admin/spec/controllers/spree/admin/classifications_controller_spec.rb
@@ -50,7 +50,7 @@ RSpec.describe Spree::Admin::ClassificationsController, type: :controller do
subject { post :create, params: { taxon_id: taxon.to_param, ids: [product1.id, product2.id], format: :turbo_stream } }
it 'creates classifications' do
- expect { subject }.to change(Spree::Classification, :count).by(2)
+ expect { subject }.to change(Spree::ProductCategory, :count).by(2)
end
it 'returns a successful response' do
@@ -80,7 +80,7 @@ RSpec.describe Spree::Admin::ClassificationsController, type: :controller do
subject { delete :destroy, params: { taxon_id: taxon.to_param, id: classification.to_param, format: :turbo_stream } }
it 'destroys the classification' do
- expect { subject }.to change(Spree::Classification, :count).by(-1)
+ expect { subject }.to change(Spree::ProductCategory, :count).by(-1)
end
it 'returns a successful response' do
diff --git a/spree/admin/spec/controllers/spree/admin/metafield_definitions_controller_spec.rb b/spree/admin/spec/controllers/spree/admin/metafield_definitions_controller_spec.rb
index cfb46db8c1..99a6c39955 100644
--- a/spree/admin/spec/controllers/spree/admin/metafield_definitions_controller_spec.rb
+++ b/spree/admin/spec/controllers/spree/admin/metafield_definitions_controller_spec.rb
@@ -27,7 +27,7 @@ RSpec.describe Spree::Admin::MetafieldDefinitionsController, type: :controller d
describe 'GET #index' do
let!(:metafield_definitions) { create_list(:metafield_definition, 3) }
- let!(:taxon_rich_text_field) { create(:metafield_definition, :rich_text_field, resource_type: 'Spree::Taxon') }
+ let!(:taxon_rich_text_field) { create(:metafield_definition, :rich_text_field, resource_type: 'Spree::Category') }
it 'renders the index template' do
get :index
@@ -38,7 +38,7 @@ RSpec.describe Spree::Admin::MetafieldDefinitionsController, type: :controller d
context 'filtering by resource type' do
it 'renders the index template' do
- get :index, params: { q: { resource_type_eq: 'Spree::Taxon' } }
+ get :index, params: { q: { resource_type_eq: 'Spree::Category' } }
expect(response).to render_template(:index)
expect(assigns[:collection]).to eq([taxon_rich_text_field])
end
diff --git a/spree/admin/spec/controllers/spree/admin/products_controller_spec.rb b/spree/admin/spec/controllers/spree/admin/products_controller_spec.rb
index 422ba60106..08aca370b9 100644
--- a/spree/admin/spec/controllers/spree/admin/products_controller_spec.rb
+++ b/spree/admin/spec/controllers/spree/admin/products_controller_spec.rb
@@ -52,7 +52,7 @@ RSpec.describe Spree::Admin::ProductsController, type: :controller do
product_1 = create(:product, taxons: [category_1])
product_2 = create(:product, taxons: [category_2])
- get :index, params: { q: { taxons_id_in: [category_1.id, category_2.id] } }
+ get :index, params: { q: { categories_id_in: [category_1.id, category_2.id] } }
expect(assigns[:collection]).to contain_exactly(product_1, product_2)
end
@@ -65,7 +65,7 @@ RSpec.describe Spree::Admin::ProductsController, type: :controller do
'q' => {
'status_eq' => 'active',
'search' => 'anchor',
- 'classifications_category_id_in' => ['8b03b40e-094f-4803-8704-20ac02f9c167', '42e63c13-dbe7-483f-8237-3b0207145fed'],
+ 'product_categories_category_id_in' => ['8b03b40e-094f-4803-8704-20ac02f9c167', '42e63c13-dbe7-483f-8237-3b0207145fed'],
'shipping_category_id_eq' => '8b03b40e-094f-4803-8704-20ac02f9c167',
'tags_name_in' => ['awesome'],
'deleted_at_null' => '1',
@@ -1508,7 +1508,7 @@ RSpec.describe Spree::Admin::ProductsController, type: :controller do
let!(:product4) { create(:product, status: :draft, deleted_at: Time.current) }
before do
- Spree::Taxon.delete_all
+ Spree::Category.delete_all
end
context 'on a store with automatic taxons' do
@@ -1518,7 +1518,7 @@ RSpec.describe Spree::Admin::ProductsController, type: :controller do
it 'auto matches taxons in bulk' do
expect { send_request }.
to have_enqueued_job(Spree::Products::AutoMatchTaxonsJob).
- on_queue(Spree.queues.taxons).
+ on_queue(Spree.queues.categories).
exactly(:twice)
jobs = Spree::Products::AutoMatchTaxonsJob.queue_adapter.enqueued_jobs.last(2)
@@ -1566,8 +1566,8 @@ RSpec.describe Spree::Admin::ProductsController, type: :controller do
send_request
positions = [
- product.reload.classifications.find_by(taxon: category).position,
- product2.reload.classifications.find_by(taxon: category).position
+ product.reload.classifications.find_by(category: category).position,
+ product2.reload.classifications.find_by(category: category).position
]
expect(positions).to contain_exactly(1, 2)
end
@@ -1610,7 +1610,7 @@ RSpec.describe Spree::Admin::ProductsController, type: :controller do
product
product2
- Spree::Taxon.delete_all
+ Spree::Category.delete_all
end
context 'on a store with automatic taxons' do
@@ -1620,7 +1620,7 @@ RSpec.describe Spree::Admin::ProductsController, type: :controller do
it 'auto matches taxons in bulk' do
expect { send_request }.
to have_enqueued_job(Spree::Products::AutoMatchTaxonsJob).
- on_queue(Spree.queues.taxons).
+ on_queue(Spree.queues.categories).
exactly(:twice)
jobs = Spree::Products::AutoMatchTaxonsJob.queue_adapter.enqueued_jobs.last(2)
diff --git a/spree/admin/spec/controllers/spree/admin/taxons_controller_spec.rb b/spree/admin/spec/controllers/spree/admin/taxons_controller_spec.rb
index f1534ac9a0..0a61064f96 100644
--- a/spree/admin/spec/controllers/spree/admin/taxons_controller_spec.rb
+++ b/spree/admin/spec/controllers/spree/admin/taxons_controller_spec.rb
@@ -39,9 +39,9 @@ RSpec.describe Spree::Admin::TaxonsController, type: :controller do
]
}
}
- }.to change(Spree::Taxon, :count).by(1).and change(Spree::TaxonRule, :count).by(1)
+ }.to change(Spree::Category, :count).by(1).and change(Spree::TaxonRule, :count).by(1)
- taxon = Spree::Taxon.last
+ taxon = Spree::Category.last
expect(taxon.automatic).to be_truthy
expect(taxon.taxon_rules.count).to eq(1)
expect(taxon.taxon_rules.first.type).to eq('Spree::TaxonRules::AvailableOn')
@@ -147,13 +147,13 @@ RSpec.describe Spree::Admin::TaxonsController, type: :controller do
let!(:taxon) { create(:taxon, taxonomy: taxonomy) }
it 'removes the taxon from the database' do
- expect { delete :destroy, params: { taxonomy_id: taxonomy.to_param, id: taxon.to_param }, format: :turbo_stream }.to change(Spree::Taxon, :count).by(-1)
+ expect { delete :destroy, params: { taxonomy_id: taxonomy.to_param, id: taxon.to_param }, format: :turbo_stream }.to change(Spree::Category, :count).by(-1)
end
end
describe 'GET #select_options' do
before do
- Spree::Taxon.delete_all
+ Spree::Category.delete_all
end
context 'with automatic taxons param' do
diff --git a/spree/api/app/controllers/concerns/spree/api/v3/params_normalizer.rb b/spree/api/app/controllers/concerns/spree/api/v3/params_normalizer.rb
index 54645ee3a9..09cb04bcef 100644
--- a/spree/api/app/controllers/concerns/spree/api/v3/params_normalizer.rb
+++ b/spree/api/app/controllers/concerns/spree/api/v3/params_normalizer.rb
@@ -6,8 +6,8 @@ module Spree
# 1. **Prefixed ID resolution** — decodes Stripe-style prefixed IDs (e.g. "prod_86Rf07xd4z")
# to integer primary keys for any param ending in `_id` or `_ids`.
#
- # 2. **Nested attributes normalization** — converts flat arrays (e.g. `taxon_rules: [...]`)
- # to Rails `_attributes` format (e.g. `taxon_rules_attributes: [...]`) based on
+ # 2. **Nested attributes normalization** — converts flat arrays (e.g. `variants: [...]`)
+ # to Rails `_attributes` format (e.g. `variants_attributes: [...]`) based on
# the model's `accepts_nested_attributes_for` declarations.
#
# Uses `prepend` so it always wraps `permitted_params` regardless of which
diff --git a/spree/api/app/controllers/spree/api/v3/admin/categories/products_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/categories/products_controller.rb
index 3c3afdedad..db9d2e7767 100644
--- a/spree/api/app/controllers/spree/api/v3/admin/categories/products_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/admin/categories/products_controller.rb
@@ -19,7 +19,7 @@ module Spree
# Body: { product_id: 'prod_…' }
def create
product = product_scope.find_by_prefix_id!(params[:product_id])
- Spree::Taxons::AddProducts.call(taxons: [@category], products: [product])
+ Spree::Categories::AddProducts.call(categories: [@category], products: [product])
render json: serialize_resource(product), status: :created
end
@@ -27,7 +27,7 @@ module Spree
# Bulk removal goes through the existing
# POST /products/bulk_remove_from_categories ({ ids, category_ids }).
def destroy
- Spree::Taxons::RemoveProducts.call(taxons: [@category], products: [@product])
+ Spree::Categories::RemoveProducts.call(categories: [@category], products: [@product])
head :no_content
end
@@ -56,9 +56,9 @@ module Spree
# The category's products, ordered by classification position.
def scope
product_scope.
- joins(:classifications).
- where(Spree::Classification.table_name => { category_id: @category.id }).
- order(Spree::Classification.table_name => { position: :asc })
+ joins(:product_categories).
+ where(Spree::ProductCategory.table_name => { category_id: @category.id }).
+ order(Spree::ProductCategory.table_name => { position: :asc })
end
# A product is classified at most once per taxon (unique [taxon_id,
@@ -88,7 +88,7 @@ module Spree
end
def classification_for(product)
- Spree::Classification.find_by(category_id: @category.id, product_id: product.id)
+ Spree::ProductCategory.find_by(category_id: @category.id, product_id: product.id)
end
end
end
diff --git a/spree/api/app/controllers/spree/api/v3/admin/categories_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/categories_controller.rb
index 66e7b30d17..0bee46a7ba 100644
--- a/spree/api/app/controllers/spree/api/v3/admin/categories_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/admin/categories_controller.rb
@@ -52,6 +52,13 @@ module Spree
Spree.api.admin_category_serializer
end
+ # Categories exclude automatic (rule-based) rows, which still live in
+ # spree_categories until the Phase 4 migration moves them to Collections.
+ # No-op after migration; the .manual scope is removed in 6.1.
+ def scope
+ super.manual
+ end
+
# Category-half attributes only. Deliberately excludes the
# collection-bound fields (automatic, sort_order, rules_match_policy,
# taxon_rules) and taxonomy_id — those belong to Spree::Collection
diff --git a/spree/api/app/controllers/spree/api/v3/admin/custom_fields_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/custom_fields_controller.rb
index b76114505b..d43490340f 100644
--- a/spree/api/app/controllers/spree/api/v3/admin/custom_fields_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/admin/custom_fields_controller.rb
@@ -106,7 +106,7 @@ module Spree
def parent_route_map
@parent_route_map ||= Spree.metafields.enabled_resources.each_with_object({}) do |klass, m|
m[klass.model_name.element.to_s] = klass.name
- end.merge('customer' => Spree.user_class.name, 'category' => 'Spree::Taxon')
+ end.merge('customer' => Spree.user_class.name, 'category' => 'Spree::Category')
end
# Returns the first segment whose `<segment>_id` is present in params,
diff --git a/spree/api/app/controllers/spree/api/v3/admin/products_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/products_controller.rb
index 8f71b24e40..88a82f9b1e 100644
--- a/spree/api/app/controllers/spree/api/v3/admin/products_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/admin/products_controller.rb
@@ -54,13 +54,13 @@ module Spree
# POST /api/v3/admin/products/bulk_add_to_categories
# Body: { ids: [...], category_ids: [...] }
def bulk_add_to_categories
- apply_categories(Spree::Taxons::AddProducts)
+ apply_categories(Spree::Categories::AddProducts)
end
# POST /api/v3/admin/products/bulk_remove_from_categories
# Body: { ids: [...], category_ids: [...] }
def bulk_remove_from_categories
- apply_categories(Spree::Taxons::RemoveProducts)
+ apply_categories(Spree::Categories::RemoveProducts)
end
# POST /api/v3/admin/products/bulk_add_to_collections
@@ -234,7 +234,7 @@ module Spree
categories = current_store.categories.
accessible_by(current_ability, :update).where(id: category_ids)
- service.call(taxons: categories, products: bulk_collection)
+ service.call(categories: categories, products: bulk_collection)
render json: { product_count: bulk_collection.size, category_count: categories.size }
end
diff --git a/spree/api/app/controllers/spree/api/v3/admin/translations_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/translations_controller.rb
index 0ecc1d765c..4252ce8feb 100644
--- a/spree/api/app/controllers/spree/api/v3/admin/translations_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/admin/translations_controller.rb
@@ -56,14 +56,14 @@ module Spree
end
# Translatable by class hierarchy, not strict equality, so a subclass
- # instance (e.g. Spree::Category < Spree::Taxon) passes when its base
+ # instance (e.g. Spree::Category < Spree::Category) passes when its base
# is registered.
def ensure_translatable!
# Compare by class NAME, not object identity: in dev the registry is
# populated at boot, but the model constants are reloaded on edits,
# so `is_a?(registered_class)` fails against a stale class object even
# when @parent's live class (or an ancestor) matches by name. Walk the
- # ancestor names so a subclass (Spree::Category < Spree::Taxon) passes.
+ # ancestor names so a subclass (Spree::Category < Spree::Category) passes.
registered = Spree.translatable_resources.map(&:name).to_set
translatable = @parent.class.ancestors.any? { |ancestor| registered.include?(ancestor.name) }
raise ActiveRecord::RecordNotFound unless translatable
@@ -78,7 +78,7 @@ module Spree
def parent_route_map
@parent_route_map ||= Spree.translatable_resources.each_with_object({}) do |klass, m|
m[klass.model_name.element.to_s] = klass.name
- end.merge('category' => 'Spree::Taxon')
+ end.merge('category' => 'Spree::Category')
end
def parent_lookup
diff --git a/spree/api/app/controllers/spree/api/v3/store/categories_controller.rb b/spree/api/app/controllers/spree/api/v3/store/categories_controller.rb
index e9332e6b17..a90fd44068 100644
--- a/spree/api/app/controllers/spree/api/v3/store/categories_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/store/categories_controller.rb
@@ -15,6 +15,12 @@ module Spree
Spree.api.category_serializer
end
+ # Exclude automatic (rule-based) rows still living in spree_categories
+ # until the Phase 4 migration moves them to Collections (removed in 6.1).
+ def scope
+ super.manual
+ end
+
# Find category by permalink or prefixed ID with i18n scope for SEO-friendly URLs
# Falls back to default locale if category is not found in the current locale
def find_resource
diff --git a/spree/api/app/serializers/spree/api/v3/admin/product_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/product_serializer.rb
index 09b262bb0c..7a87a62a8f 100644
--- a/spree/api/app/serializers/spree/api/v3/admin/product_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/admin/product_serializer.rb
@@ -63,11 +63,11 @@ module Spree
resource: proc { Spree.api.admin_option_value_serializer },
if: proc { expand?('option_values') }
- many :taxons,
- proc { |taxons, params|
- taxons.select { |t| t.taxonomy.store_id == params[:store].id }
+ many :categories,
+ proc { |categories, params|
+ store_id = params[:store].id
+ categories.select { |c| c.store_id == store_id || c.taxonomy&.store_id == store_id }
},
- key: :categories,
resource: proc { Spree.api.admin_category_serializer },
if: proc { expand?('categories') }
diff --git a/spree/api/app/serializers/spree/api/v3/admin/promotion_rule_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/promotion_rule_serializer.rb
index 49adce8164..d2518ccdf0 100644
--- a/spree/api/app/serializers/spree/api/v3/admin/promotion_rule_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/admin/promotion_rule_serializer.rb
@@ -45,7 +45,7 @@ module Spree
end
attribute :category_ids do |rule|
- rule.taxons.map(&:prefixed_id) if rule.respond_to?(:taxons)
+ rule.categories.map(&:prefixed_id) if rule.respond_to?(:categories)
end
attribute :customer_ids do |rule|
@@ -61,10 +61,9 @@ module Spree
resource: proc { Spree.api.admin_product_serializer },
if: proc { |rule| rule.respond_to?(:products) }
- many :taxons,
- key: :categories,
+ many :categories,
resource: proc { Spree.api.admin_category_serializer },
- if: proc { |rule| rule.respond_to?(:taxons) }
+ if: proc { |rule| rule.respond_to?(:categories) }
many :users,
key: :customers,
diff --git a/spree/api/app/serializers/spree/api/v3/product_serializer.rb b/spree/api/app/serializers/spree/api/v3/product_serializer.rb
index 8494f1ffcd..134373c46a 100644
--- a/spree/api/app/serializers/spree/api/v3/product_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/product_serializer.rb
@@ -112,11 +112,11 @@ module Spree
resource: proc { Spree.api.option_value_serializer },
if: proc { expand?('option_values') }
- many :taxons,
- proc { |taxons, params|
- taxons.select { |t| t.taxonomy.store_id == params[:store].id }
+ many :categories,
+ proc { |categories, params|
+ store_id = params[:store].id
+ categories.select { |c| c.store_id == store_id || c.taxonomy&.store_id == store_id }
},
- key: :categories,
resource: proc { Spree.api.category_serializer },
if: proc { expand?('categories') }
diff --git a/spree/api/app/services/spree/api/v3/filters_aggregator.rb b/spree/api/app/services/spree/api/v3/filters_aggregator.rb
index 3a5f2432d9..9c0f132379 100644
--- a/spree/api/app/services/spree/api/v3/filters_aggregator.rb
+++ b/spree/api/app/services/spree/api/v3/filters_aggregator.rb
@@ -38,7 +38,7 @@ module Spree
end
def sort_options
- Spree::Taxon::SORT_ORDERS.map { |id| { id: to_api_sort(id) } }
+ Spree::Collection::SORT_ORDERS.map { |id| { id: to_api_sort(id) } }
end
# Converts internal sort format ('price asc') to API format ('price', '-price')
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/categories/products_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/categories/products_controller_spec.rb
index 1177324338..5483e4ca41 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/categories/products_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/categories/products_controller_spec.rb
@@ -10,7 +10,7 @@ RSpec.describe Spree::Api::V3::Admin::Categories::ProductsController, type: :con
before { request.headers.merge!(headers) }
def classified_ids
- Spree::Classification.where(category_id: category.id).order(:position).pluck(:product_id)
+ Spree::ProductCategory.where(category_id: category.id).order(:position).pluck(:product_id)
end
describe 'GET #index' do
@@ -21,11 +21,11 @@ RSpec.describe Spree::Api::V3::Admin::Categories::ProductsController, type: :con
let!(:other_category) { Spree::Category.create!(name: 'Other', store: store) }
before do
- Spree::Classification.create!(taxon: category, product: product_b, position: 1)
- Spree::Classification.create!(taxon: category, product: product_a, position: 2)
- Spree::Classification.create!(taxon: category, product: product_c, position: 3)
+ Spree::ProductCategory.create!(taxon: category, product: product_b, position: 1)
+ Spree::ProductCategory.create!(taxon: category, product: product_a, position: 2)
+ Spree::ProductCategory.create!(taxon: category, product: product_c, position: 3)
# A product in a different category must not leak into this list.
- Spree::Classification.create!(taxon: other_category, product: other_category_product, position: 1)
+ Spree::ProductCategory.create!(taxon: other_category, product: other_category_product, position: 1)
end
it 'lists only the category products, ordered by classification position' do
@@ -69,7 +69,7 @@ RSpec.describe Spree::Api::V3::Admin::Categories::ProductsController, type: :con
describe 'DELETE #destroy' do
let!(:product) { create(:product, stores: [store]) }
- before { Spree::Classification.create!(taxon: category, product: product, position: 1) }
+ before { Spree::ProductCategory.create!(taxon: category, product: product, position: 1) }
it 'removes the product from the category' do
delete :destroy, params: { category_id: category.prefixed_id, id: product.prefixed_id }, as: :json
@@ -92,9 +92,9 @@ RSpec.describe Spree::Api::V3::Admin::Categories::ProductsController, type: :con
let!(:third) { create(:product, stores: [store]) }
before do
- Spree::Classification.create!(taxon: category, product: first, position: 1)
- Spree::Classification.create!(taxon: category, product: second, position: 2)
- Spree::Classification.create!(taxon: category, product: third, position: 3)
+ Spree::ProductCategory.create!(taxon: category, product: first, position: 1)
+ Spree::ProductCategory.create!(taxon: category, product: second, position: 2)
+ Spree::ProductCategory.create!(taxon: category, product: third, position: 3)
end
it 'moves a product to the requested index' do
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/categories_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/categories_controller_spec.rb
index d321ce3a4a..26fda8ed1b 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/categories_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/categories_controller_spec.rb
@@ -120,20 +120,20 @@ RSpec.describe Spree::Api::V3::Admin::CategoriesController, type: :controller do
expect(imaged.reload.image).not_to be_attached
end
- # Category custom-field definitions are stored under Spree::Taxon (the
+ # Category custom-field definitions are stored under Spree::Category (the
# category route maps to the Taxon class). The dashboard ships values inline
# with the category form, persisted via Spree::Metafields#custom_fields=.
context 'with inline custom fields' do
let!(:fabric_definition) do
create(:metafield_definition,
- resource_type: 'Spree::Taxon',
+ resource_type: 'Spree::Category',
namespace: 'category',
key: 'fabric',
metafield_type: 'Spree::Metafields::ShortText')
end
let!(:specs_definition) do
create(:metafield_definition,
- resource_type: 'Spree::Taxon',
+ resource_type: 'Spree::Category',
namespace: 'category',
key: 'specs',
metafield_type: 'Spree::Metafields::Json')
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/custom_fields_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/custom_fields_controller_spec.rb
index c838ccb8b2..ce3e5c9b6f 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/custom_fields_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/custom_fields_controller_spec.rb
@@ -294,7 +294,7 @@ RSpec.describe Spree::Api::V3::Admin::CustomFieldsController, type: :controller
let(:granted_scope) { 'write_categories' }
let(:category) { create(:taxon) }
let(:category_definition) do
- create(:metafield_definition, :short_text_field, resource_type: 'Spree::Taxon')
+ create(:metafield_definition, :short_text_field, resource_type: 'Spree::Category')
end
it 'resolves the parent and gates by the categories scope' do
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/products_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/products_controller_spec.rb
index 77a2483dee..621728acaf 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/products_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/products_controller_spec.rb
@@ -1467,8 +1467,8 @@ RSpec.describe Spree::Api::V3::Admin::ProductsController, type: :controller do
}, as: :json
positions = [
- product.reload.classifications.find_by(taxon: category).position,
- second_product.reload.classifications.find_by(taxon: category).position
+ product.reload.classifications.find_by(category: category).position,
+ second_product.reload.classifications.find_by(category: category).position
]
expect(positions).to contain_exactly(1, 2)
end
@@ -1583,8 +1583,8 @@ RSpec.describe Spree::Api::V3::Admin::ProductsController, type: :controller do
}, as: :json
positions = [
- survivor.reload.classifications.find_by(taxon: category)&.position,
- latecomer.reload.classifications.find_by(taxon: category)&.position
+ survivor.reload.classifications.find_by(category: category)&.position,
+ latecomer.reload.classifications.find_by(category: category)&.position
].compact.sort
expect(positions).to eq([1, 2])
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/promotions_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/promotions_controller_spec.rb
index 587a2b60f5..9c0adc97b7 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/promotions_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/promotions_controller_spec.rb
@@ -135,7 +135,7 @@ RSpec.describe Spree::Api::V3::Admin::PromotionsController, type: :controller do
expect(response).to have_http_status(:created)
rule = Spree::Promotion.find_by_prefix_id(json_response['id']).rules.first
- expect(rule).to be_a(Spree::Promotion::Rules::Taxon)
+ expect(rule).to be_a(Spree::Promotion::Rules::Category)
expect(rule.taxon_ids).to eq([taxon.id])
end
@@ -271,7 +271,7 @@ RSpec.describe Spree::Api::V3::Admin::PromotionsController, type: :controller do
expect(response).to have_http_status(:created)
rule = Spree::Promotion.find_by_prefix_id(json_response['id']).rules.first
- expect(rule).to be_a(Spree::Promotion::Rules::Taxon)
+ expect(rule).to be_a(Spree::Promotion::Rules::Category)
expect(rule.taxon_ids).to eq([taxon.id])
end
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/translations_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/translations_controller_spec.rb
index f00009829a..0948ed7d1d 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/translations_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/translations_controller_spec.rb
@@ -57,7 +57,7 @@ RSpec.describe Spree::Api::V3::Admin::TranslationsController, type: :controller
end
end
- context 'when the parent is a category (Spree::Category < Spree::Taxon)' do
+ context 'when the parent is a category (Spree::Category < Spree::Category)' do
let!(:taxonomy) { create(:taxonomy, store: store) }
let!(:category) { create(:taxon, name: 'Clothing', taxonomy: taxonomy, parent: taxonomy.root) }
diff --git a/spree/api/spec/controllers/spree/api/v3/params_normalizer_spec.rb b/spree/api/spec/controllers/spree/api/v3/params_normalizer_spec.rb
index 2ae2652f3d..15d5235f41 100644
--- a/spree/api/spec/controllers/spree/api/v3/params_normalizer_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/params_normalizer_spec.rb
@@ -9,7 +9,7 @@ RSpec.describe Spree::Api::V3::ParamsNormalizer do
public :resolve_prefixed_ids, :normalize_nested_attributes, :prefixed_id?, :decode_prefixed_id
def model_class
- Spree::Taxon
+ Spree::Collection
end
end
end
@@ -86,15 +86,15 @@ RSpec.describe Spree::Api::V3::ParamsNormalizer do
describe '#normalize_nested_attributes' do
it 'converts flat nested keys to _attributes format' do
hash = {
- 'name' => 'Categories',
- 'taxon_rules' => [{ 'type' => 'Spree::TaxonRule::IncludeTag', 'value' => 'sale' }]
+ 'name' => 'On Sale',
+ 'rules' => [{ 'type' => 'Spree::CollectionRules::Tag', 'value' => 'sale' }]
}.with_indifferent_access
result = controller.normalize_nested_attributes(hash)
- expect(result).not_to have_key('taxon_rules')
- expect(result['taxon_rules_attributes']).to eq([{ 'type' => 'Spree::TaxonRule::IncludeTag', 'value' => 'sale' }])
- expect(result['name']).to eq('Categories')
+ expect(result).not_to have_key('rules')
+ expect(result['rules_attributes']).to eq([{ 'type' => 'Spree::CollectionRules::Tag', 'value' => 'sale' }])
+ expect(result['name']).to eq('On Sale')
end
it 'does not rename keys that already have _attributes suffix' do
diff --git a/spree/api/spec/controllers/spree/api/v3/store/categories_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/store/categories_controller_spec.rb
index b92acce447..fd33e1bb45 100644
--- a/spree/api/spec/controllers/spree/api/v3/store/categories_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/store/categories_controller_spec.rb
@@ -188,7 +188,7 @@ RSpec.describe Spree::Api::V3::Store::CategoriesController, type: :controller do
end
end
- context 'with translations', if: Spree::Taxon.include?(Spree::TranslatableResource) do
+ context 'with translations', if: Spree::Category.include?(Spree::TranslatableResource) do
let!(:translated_taxon) do
create(:taxon, taxonomy: taxonomy, name: 'Clothing', permalink: 'clothing').tap do |t|
Mobility.with_locale(:fr) do
diff --git a/spree/api/spec/integration/spree/api/v3/admin/categories_spec.rb b/spree/api/spec/integration/spree/api/v3/admin/categories_spec.rb
index 8c419ecfad..f7ab24a959 100644
--- a/spree/api/spec/integration/spree/api/v3/admin/categories_spec.rb
+++ b/spree/api/spec/integration/spree/api/v3/admin/categories_spec.rb
@@ -299,7 +299,7 @@ RSpec.describe 'Admin Categories API', type: :request, swagger_doc: 'api-referen
let(:id) { product.prefixed_id }
let(:body) { { new_position: 0 } }
- before { Spree::Classification.create!(taxon: category, product: product, position: 1) }
+ before { Spree::ProductCategory.create!(taxon: category, product: product, position: 1) }
run_test!
end
diff --git a/spree/core/app/finders/spree/products/find.rb b/spree/core/app/finders/spree/products/find.rb
index 8721d3c093..5d437c1c37 100644
--- a/spree/core/app/finders/spree/products/find.rb
+++ b/spree/core/app/finders/spree/products/find.rb
@@ -142,15 +142,15 @@ module Spree
def by_taxons(products)
return products unless taxons?
- products.joins(:classifications).where(Classification.table_name => { category_id: taxons })
+ products.joins(:product_categories).where(Spree::ProductCategory.table_name => { category_id: taxons })
end
def by_concat_taxons(products)
return products unless concat_taxons?
product_ids = Spree::Product.
- joins(:classifications).
- where(Classification.table_name => { category_id: concat_taxons }).
+ joins(:product_categories).
+ where(Spree::ProductCategory.table_name => { category_id: concat_taxons }).
group("#{Spree::Product.table_name}.id").
having("COUNT(#{Spree::Product.table_name}.id) = ?", concat_taxons.length).
ids
@@ -165,7 +165,7 @@ module Spree
return products if taxon_groups.empty?
- taxonomies_products = products.joins(:classifications).where(Classification.table_name => { category_id: taxon_groups.flatten.uniq })
+ taxonomies_products = products.joins(:product_categories).where(Spree::ProductCategory.table_name => { category_id: taxon_groups.flatten.uniq })
# No need to filter if there is only one taxonomy
return taxonomies_products if taxonomies.size == 1
@@ -296,7 +296,7 @@ module Spree
def taxon_ids(taxons_ids)
return if taxons_ids.nil? || taxons_ids.to_s.blank?
- taxons = Spree::Taxon.for_store(store).where(id: taxons_ids.to_s.split(','))
+ taxons = Spree::Category.for_store(store).where(id: taxons_ids.to_s.split(','))
taxons.map(&:cached_self_and_descendants_ids).flatten.compact.uniq.map(&:to_s)
end
@@ -315,7 +315,7 @@ module Spree
end
def products_matching_all_taxonomies_ids(products_ids, taxon_groups)
- classifications = Spree::Classification.grouped_taxon_ids_for_products(products_ids, taxon_groups.flatten)
+ classifications = Spree::ProductCategory.grouped_category_ids_for_products(products_ids, taxon_groups.flatten)
classifications_hash = classifications.to_h.transform_values { |taxon_ids| taxon_ids.split(',') }
# Find products ids that match all taxonomies to tighten filter results
diff --git a/spree/core/app/helpers/spree/base_helper.rb b/spree/core/app/helpers/spree/base_helper.rb
index b46ad6935c..74bbda8f2d 100644
--- a/spree/core/app/helpers/spree/base_helper.rb
+++ b/spree/core/app/helpers/spree/base_helper.rb
@@ -27,7 +27,7 @@ module Spree
end
# returns the URL of an object on the storefront
- # @param resource [Spree::Product, Spree::Taxon, Spree::Page] the resource to get the URL for
+ # @param resource [Spree::Product, Spree::Category, Spree::Page] the resource to get the URL for
# @param options [Hash] the options for the URL
# @option options [String] :locale the locale of the resource, defaults to I18n.locale
# @option options [String] :store the store of the resource, defaults to current_store
@@ -61,7 +61,7 @@ module Spree
params = "?#{params}" if params.present?
"#{base_url + localize}/products/#{resource.slug}#{params}"
- elsif resource.is_a?(Spree::Taxon)
+ elsif resource.is_a?(Spree::Category)
"#{base_url + localize}/t/#{resource.permalink}"
elsif defined?(Spree::Page) && (resource.is_a?(Spree::Page) || resource.is_a?(Spree::Policy))
"#{base_url + localize}#{resource.page_builder_url}"
diff --git a/spree/core/app/jobs/spree/products/touch_categories_job.rb b/spree/core/app/jobs/spree/products/touch_categories_job.rb
new file mode 100644
index 0000000000..5756280cbf
--- /dev/null
+++ b/spree/core/app/jobs/spree/products/touch_categories_job.rb
@@ -0,0 +1,12 @@
+module Spree
+ module Products
+ class TouchCategoriesJob < ::Spree::BaseJob
+ queue_as Spree.queues.categories
+
+ def perform(category_ids, taxonomy_ids)
+ Spree::Category.where(id: category_ids).update_all(updated_at: Time.current)
+ Spree::Taxonomy.where(id: taxonomy_ids).update_all(updated_at: Time.current)
+ end
+ end
+ end
+end
diff --git a/spree/core/app/jobs/spree/products/touch_taxons_job.rb b/spree/core/app/jobs/spree/products/touch_taxons_job.rb
index 6762daf911..3287b9b1ff 100644
--- a/spree/core/app/jobs/spree/products/touch_taxons_job.rb
+++ b/spree/core/app/jobs/spree/products/touch_taxons_job.rb
@@ -1,12 +1,8 @@
module Spree
module Products
- class TouchTaxonsJob < ::Spree::BaseJob
- queue_as Spree.queues.taxons
-
- def perform(taxon_ids, taxonomy_ids)
- Spree::Taxon.where(id: taxon_ids).update_all(updated_at: Time.current)
- Spree::Taxonomy.where(id: taxonomy_ids).update_all(updated_at: Time.current)
- end
- end
+ # Deprecation alias for Spree::Products::TouchCategoriesJob, renamed in 6.0.
+ # Kept so any job enqueued under the old class name before the deploy still
+ # deserializes; removed in 6.1.
+ TouchTaxonsJob = TouchCategoriesJob
end
end
diff --git a/spree/core/app/models/concerns/spree/prefixed_id.rb b/spree/core/app/models/concerns/spree/prefixed_id.rb
index 680a2dabe9..54920c54fc 100644
--- a/spree/core/app/models/concerns/spree/prefixed_id.rb
+++ b/spree/core/app/models/concerns/spree/prefixed_id.rb
@@ -114,7 +114,7 @@ module Spree
end
# Resolve an array of prefixed IDs for a has_many _ids setter.
- # Infers the target class from the association name (e.g., taxon_ids → taxons → Spree::Taxon).
+ # Infers the target class from the association name (e.g., taxon_ids → taxons → Spree::Category).
# Only resolves when a matching association exists.
def resolve_prefixed_ids_for_attribute(attribute_name, values)
association_name = attribute_name.sub(/_ids$/, '').pluralize
diff --git a/spree/core/app/models/concerns/spree/product_scopes.rb b/spree/core/app/models/concerns/spree/product_scopes.rb
index 6d56169a19..b7b63b865f 100644
--- a/spree/core/app/models/concerns/spree/product_scopes.rb
+++ b/spree/core/app/models/concerns/spree/product_scopes.rb
@@ -143,14 +143,14 @@ module Spree
#
# Spree::Product.in_taxon(taxon).count(distinct: true)
scope :in_taxon, ->(taxon) {
- joins(:classifications).
- where("#{Classification.table_name}.category_id" => taxon.cached_self_and_descendants_ids).distinct
+ joins(:product_categories).
+ where("#{Spree::ProductCategory.table_name}.category_id" => taxon.cached_self_and_descendants_ids).distinct
}
# Products in a category AND all its descendants.
# Accepts a Category record or a prefixed ID string (e.g. 'ctg_xxx').
def self.in_category(category_or_id)
- category = category_or_id.is_a?(String) ? Spree::Taxon.find_by_prefix_id(category_or_id) : category_or_id
+ category = category_or_id.is_a?(String) ? Spree::Category.find_by_prefix_id(category_or_id) : category_or_id
return none unless category
in_taxon(category)
@@ -164,14 +164,14 @@ module Spree
ids, records = categories_or_ids.partition { |c| c.is_a?(String) }
if ids.any?
- decoded = ids.filter_map { |id| Spree::Taxon.decode_prefixed_id(id) }
- records += Spree::Taxon.where(id: decoded).to_a if decoded.any?
+ decoded = ids.filter_map { |id| Spree::Category.decode_prefixed_id(id) }
+ records += Spree::Category.where(id: decoded).to_a if decoded.any?
end
return none if records.empty?
taxon_ids = records.flat_map(&:cached_self_and_descendants_ids).uniq
- joins(:classifications).where(Classification.table_name => { category_id: taxon_ids }).distinct
+ joins(:product_categories).where(Spree::ProductCategory.table_name => { category_id: taxon_ids }).distinct
end
# Products in a collection (flat — collections have no hierarchy).
@@ -183,18 +183,11 @@ module Spree
joins(:product_collections).where(Spree::ProductCollection.table_name => { collection_id: collection.id }).distinct
end
- # Deprecated — remove in 6.0. Use in_taxon instead.
- def self.in_taxons(*taxons)
- Spree::Deprecation.warn('in_taxons is deprecated and will be removed in Spree 6.0. Use in_taxon instead.')
- taxons = get_taxons(taxons)
- taxons.first ? prepare_taxon_conditions(taxons) : where(nil)
- end
-
scope :ascend_by_taxons_min_position, ->(taxon_ids) {
- min_position_sql = "MIN(#{Classification.table_name}.position)"
+ min_position_sql = "MIN(#{Spree::ProductCategory.table_name}.position)"
- joins(:classifications).
- where(Classification.table_name => { category_id: taxon_ids }).
+ joins(:product_categories).
+ where(Spree::ProductCategory.table_name => { category_id: taxon_ids }).
select("#{Product.table_name}.*", "#{min_position_sql} AS min_taxon_position").
group("#{Product.table_name}.id").
order(Arel.sql("#{min_position_sql} ASC"))
@@ -366,14 +359,6 @@ module Spree
available(nil, currency)
end
- # Deprecated — remove in 6.0. Use active(currency).in_taxon(taxon) directly.
- def self.for_filters(currency, taxon: nil)
- Spree::Deprecation.warn('for_filters is deprecated and will be removed in Spree 6.0. Use active(currency).in_taxon(taxon) instead.')
- scope = active(currency)
- scope = scope.in_taxon(taxon) if taxon.present?
- scope
- end
-
# Deprecated — remove in 6.0. Not used internally.
def self.for_user(user = nil)
Spree::Deprecation.warn('for_user is deprecated and will be removed in Spree 6.0.')
@@ -384,12 +369,6 @@ module Spree
end
end
- # Deprecated — remove in 6.0. Not used internally.
- def self.taxons_name_eq(name)
- Spree::Deprecation.warn('taxons_name_eq is deprecated and will be removed in Spree 6.0.')
- group('spree_products.id').joins(:taxons).where(Taxon.arel_table[:name].eq(name))
- end
-
# Orders products by best-selling metrics (+units_sold_count+, +revenue+)
# tracked directly on +spree_products+. Uses Arel::Nodes::As so that
# ORDER BY expressions appear in SELECT and work with DISTINCT (same
@@ -438,13 +417,6 @@ module Spree
end
private_class_method :price_table_name
- # specifically avoid having an order for taxon search (conflicts with main order)
- def self.prepare_taxon_conditions(taxons)
- ids = taxons.map(&:cached_self_and_descendants_ids).flatten.uniq
- joins(:classifications).where(Classification.table_name => { category_id: ids })
- end
- private_class_method :prepare_taxon_conditions
-
# Produce an array of keywords for use in scopes.
# Always return array with at least an empty string to avoid SQL errors
def self.prepare_words(words)
@@ -454,20 +426,6 @@ module Spree
a.any? ? a : ['']
end
private_class_method :prepare_words
-
- def self.get_taxons(*ids_or_records_or_names)
- ids_or_records_or_names.flatten.map do |t|
- case t
- when ApplicationRecord then t
- else
- Taxon.where(name: t).
- or(Taxon.where(Taxon.arel_table[:id].eq(t))).
- or(Taxon.where(Taxon.arel_table[:permalink].matches("%/#{t}/"))).
- or(Taxon.where(Taxon.arel_table[:permalink].matches("#{t}/"))).first
- end
- end.compact.flatten.uniq
- end
- private_class_method :get_taxons
end
end
end
diff --git a/spree/core/app/models/spree/base_analytics_event_handler.rb b/spree/core/app/models/spree/base_analytics_event_handler.rb
index 5bb6b7de80..91e998c8f9 100644
--- a/spree/core/app/models/spree/base_analytics_event_handler.rb
+++ b/spree/core/app/models/spree/base_analytics_event_handler.rb
@@ -24,7 +24,7 @@ module Spree
# Handles the event
# @param event_name [String] eg. 'order_completed'
- # @param properties [Hash] eg. { product: Spree::Product, taxon: Spree::Taxon, query: String }
+ # @param properties [Hash] eg. { product: Spree::Product, taxon: Spree::Category, query: String }
# rubocop:disable Lint/UnusedMethodArgument
def handle_event(event_name, properties = {})
raise NotImplementedError, 'Subclasses must implement the handle method'
diff --git a/spree/core/app/models/spree/category.rb b/spree/core/app/models/spree/category.rb
index 4b7d25567c..122fad15a3 100644
--- a/spree/core/app/models/spree/category.rb
+++ b/spree/core/app/models/spree/category.rb
@@ -1,16 +1,460 @@
+# frozen_string_literal: true
+
+require 'stringex'
+
module Spree
- # Public API name for Taxon, used by the admin dashboard. Unlike a legacy
- # +Spree::Taxon+, a Category does not require a +Spree::Taxonomy+ — it is
- # owned directly via +store_id+, so a parentless category is a genuine
- # top-level node. (Legacy taxonomy-backed taxons are unaffected.) Will become
- # the base class in 6.0 when +Spree::Taxonomy+ is dropped and +spree_taxons+
- # is renamed to +spree_categories+.
- class Category < Taxon
- default_scope { manual }
-
- # A category is owned directly via +store_id+ and never needs a taxonomy.
+ # The hierarchical product category (formerly Spree::Taxon), on spree_categories,
+ # owned directly via store_id — a parentless category is a genuine top-level node.
+ # Spree::Taxon is retained as a deprecation alias for one release. Rule-based
+ # (automatic) membership now lives on Spree::Collection.
+ class Category < Spree.base_class
+ include Spree::SingleStoreResource
+
+ has_prefix_id :ctg
+
+ include Spree::TranslatableResource
+ include Spree::TranslatableResourceSlug
+ include Spree::Metafields
+ include Spree::Metadata
+ include Spree::MemoizedData
+
+ MEMOIZED_METHODS = %w[cached_self_and_descendants_ids].freeze
+
+ #
+ # Magic methods
+ #
+ extend FriendlyId
+ friendly_id :permalink, slug_column: :permalink, use: :history
+ acts_as_nested_set dependent: :destroy, counter_cache: :children_count
+
+ #
+ # Associations
+ #
+ belongs_to :taxonomy, class_name: 'Spree::Taxonomy', inverse_of: :taxons
+ belongs_to :store, class_name: 'Spree::Store', optional: true
+ has_many :product_categories, -> { order(:position) }, class_name: 'Spree::ProductCategory', dependent: :destroy_async, inverse_of: :category
+ has_many :products, through: :product_categories
+
+ # @deprecated Use #product_categories; removed in 6.1.
+ def classifications
+ product_categories
+ end
+
+ # spree_prototype_taxons keeps its taxon_id column (the prototype join is
+ # renamed by 6.0-product-types), so pin the foreign key there.
+ has_many :prototype_taxons, class_name: 'Spree::PrototypeTaxon', foreign_key: :taxon_id, dependent: :destroy
+ has_many :prototypes, through: :prototype_taxons, class_name: 'Spree::Prototype'
+
+ has_many :promotion_rule_categories, class_name: 'Spree::PromotionRuleCategory', dependent: :destroy
+ has_many :promotion_rules, through: :promotion_rule_categories, class_name: 'Spree::PromotionRule'
+
+ #
+ # Attachments
+ #
+ has_one_attached :image, service: Spree.public_storage_service_name
+ has_one_attached :square_image, service: Spree.public_storage_service_name
+
+ #
+ # Validations
+ #
+ validates :name, presence: true
+ validates :taxonomy, presence: true, if: :requires_taxonomy?
+ validates :store, presence: true
+ # Taxonomy-backed categories are unique within their taxonomy; taxonomy-less
+ # categories (store-owned) are unique within their store, so two stores can
+ # each have a top-level "Shoes".
+ validates :name, uniqueness: { scope: %i[parent_id taxonomy_id], case_sensitive: false }, if: :requires_taxonomy?
+ validates :permalink, uniqueness: { scope: %i[parent_id taxonomy_id], case_sensitive: false }, if: :requires_taxonomy?
+ validates :name, uniqueness: { scope: %i[parent_id store_id], case_sensitive: false }, unless: :requires_taxonomy?
+ validates :permalink, uniqueness: { scope: %i[parent_id store_id], case_sensitive: false }, unless: :requires_taxonomy?
+ validates :hide_from_nav, inclusion: { in: [true, false] }
+ validate :check_for_root, on: :create
+ validate :parent_belongs_to_same_taxonomy
+ with_options length: { maximum: 255 }, allow_blank: true do
+ validates :meta_keywords
+ validates :meta_description
+ validates :meta_title
+ end
+ validates :image, :square_image, content_type: Rails.application.config.active_storage.web_image_content_types
+
+ #
+ # Callbacks
+ #
+ before_validation :set_permalink, if: :name
+ before_validation :copy_taxonomy_from_parent
+ before_save :set_pretty_name
+ after_save :touch_ancestors_and_taxonomy
+ after_update :sync_taxonomy_name
+ after_touch :touch_ancestors_and_taxonomy
+ after_commit :regenerate_pretty_name_and_permalink, on: :update, if: :should_regenerate_pretty_name_and_permalink?
+ after_move :regenerate_pretty_name_and_permalink
+ after_move :regenerate_translations_pretty_name_and_permalink
+ # Moving a subtree shifts its products under a new ancestor chain (and away
+ # from the old one), so recompute both branches' inclusive products_count.
+ # Capture the old parent before the move; recompute both chains after.
+ before_move :capture_parent_before_move
+ after_move :recalculate_products_count_after_move
+ # Destroying a category drops its subtree's products from every ancestor's
+ # inclusive count. Recompute the ancestors here (while the doomed subtree's
+ # rows still exist) excluding that subtree, since the ProductCategory destroy
+ # callbacks can't help: product_categories are removed via destroy_async, so
+ # they outlive this callback and their category may already be gone.
+ before_destroy :recalculate_ancestors_before_destroy, prepend: true
+
+ #
+ # Scopes
+ #
+ # Prefer the direct store_id column; fall back to the taxonomy join for rows
+ # not yet backfilled (store_id IS NULL) so legacy behaviour is preserved.
+ scope :for_store, ->(store) { for_stores([store]) }
+ scope :for_stores, lambda { |stores|
+ store_ids = Array(stores).map(&:id)
+ taxonomy_ids = Spree::Taxonomy.where(store_id: store_ids).select(:id)
+ where(store_id: store_ids).or(where(store_id: nil, taxonomy_id: taxonomy_ids))
+ }
+ scope :for_taxonomy, lambda { |taxonomy_name|
+ Spree::Deprecation.warn('Spree::Category.for_taxonomy is deprecated and will be removed in Spree 6. Please use for_store instead.')
+
+ if Spree.use_translations?
+ joins(:taxonomy)
+ .join_translation_table(Taxonomy)
+ .where(
+ Taxonomy.arel_table_alias[:name].lower.matches(taxonomy_name.downcase.strip)
+ )
+ else
+ joins(:taxonomy).where(Spree::Taxonomy.arel_table[:name].lower.matches(taxonomy_name.downcase.strip))
+ end
+ }
+
+ #
+ # Search
+ #
+ def self.search_by_name(query)
+ i18n { name.lower.matches("%#{query.downcase}%") }
+ end
+
+ scope :with_matching_name, lambda { |name_to_match|
+ value = name_to_match.to_s.strip.downcase
+
+ if Spree.use_translations?
+ i18n { name.lower.eq(value) }
+ else
+ where(arel_table[:name].lower.eq(value))
+ end
+ }
+
+ #
+ # Ransack
+ #
+ self.whitelisted_ransackable_associations = %w[taxonomy parent]
+ self.whitelisted_ransackable_attributes = %w[name permalink automatic depth is_root children_count
+ products_count pretty_name hide_from_nav parent_id]
+
+ #
+ # Translations
+ #
+ TRANSLATABLE_FIELDS = %i[name pretty_name description permalink].freeze
+ RICH_TEXT_TRANSLATABLE_FIELDS = %i[description].freeze
+ translates(*TRANSLATABLE_FIELDS, column_fallback: !Spree.always_use_translations?)
+
+ #
+ # Action Text
+ #
+ translates :description, backend: :action_text
+
+ # Categories are manual only in 6.0 — rule-based (automatic) membership lives on
+ # Spree::Collection. The automatic/rules_match_policy/sort_order columns and the
+ # spree_taxon_rules table are retained for the Phase 4 data migration and dropped
+ # in 6.1. The manual scope stays as a guard against any stray automatic row on the
+ # category surfaces (a no-op once the migration clears them).
+ scope :manual, -> { where.not(automatic: true) }
+
+ def manual?
+ !automatic?
+ end
+
+ # The owning store. Prefers the direct +store_id+; falls back to the
+ # taxonomy's store for legacy rows not yet backfilled.
+ def store
+ super || taxonomy&.store
+ end
+
+ # Categories are owned directly via +store_id+ and never require a taxonomy.
+ # (Legacy taxonomy-backed rows still carry their taxonomy until it is dropped
+ # in 6.1; they simply aren't validated as requiring one.)
def requires_taxonomy?
false
end
+
+ def active_products_with_descendants
+ @active_products_with_descendants ||= store.products
+ .joins(:product_categories)
+ .active
+ .where(
+ Spree::ProductCategory.table_name => {
+ category_id: descendants.ids + [id]
+ }
+ )
+ end
+
+ # Recomputes the stored, descendant-inclusive +products_count+ for the given
+ # categories AND all of their ancestors — the nodes whose inclusive count can
+ # shift when a product_category changes. Counts unique products classified
+ # under each node or its descendants (a product reachable through several
+ # nodes is counted once per ancestor). Call after any product_category change.
+ #
+ # @param category_ids [Array<Integer>] categories whose branch counts changed
+ def self.recalculate_products_count(category_ids)
+ changed = unscoped.where(id: Array(category_ids).compact.uniq)
+
+ # The affected nodes are each changed category plus its ancestors.
+ affected = changed.flat_map { |category| category.self_and_ancestors.to_a }.uniq(&:id)
+
+ affected.each do |category|
+ count = Spree::ProductCategory.where(category_id: category.self_and_descendants.select(:id))
+ .distinct.count(:product_id)
+ category.update_column(:products_count, count) if category.products_count != count
+ end
+ end
+
+ def slug
+ permalink
+ end
+
+ def slug=(value)
+ self.permalink = value
+ end
+
+ self::Translation.class_eval do
+ before_save :set_permalink
+ before_save :set_pretty_name
+ after_save :regenerate_pretty_name_and_permalink, if: :should_regenerate_pretty_name_and_permalink?
+
+ def slug
+ permalink
+ end
+
+ def slug=(value)
+ self.permalink = value
+ end
+
+ def set_permalink
+ self.permalink = generate_slug
+ end
+
+ def set_pretty_name
+ self.pretty_name = generate_pretty_name
+ end
+
+ def name_with_fallback
+ name.blank? ? translated_model[:name] : name
+ end
+
+ def pretty_name_with_fallback
+ pretty_name.blank? ? translated_model[:pretty_name] : pretty_name
+ end
+
+ def regenerate_pretty_name_and_permalink
+ Spree::Category::Translation.where(spree_category_id: translated_model.cached_self_and_descendants_ids).each(&:update_pretty_name_and_permalink)
+ end
+
+ def update_pretty_name_and_permalink
+ update_columns(pretty_name: generate_pretty_name, permalink: generate_slug, updated_at: Time.current)
+ end
+
+ private
+
+ def generate_slug
+ if parent.present?
+ generate_permalink_including_parent
+ elsif permalink.blank?
+ name_with_fallback.to_url
+ else
+ permalink.to_url
+ end
+ end
+
+ def generate_pretty_name
+ if parent.present?
+ generate_pretty_name_including_parent
+ elsif pretty_name.blank?
+ name_with_fallback
+ else
+ pretty_name
+ end
+ end
+
+ def generate_permalink_including_parent
+ [parent_permalink_with_fallback,
+ (permalink.blank? ? name_with_fallback.to_url : permalink.split('/').last.to_url)].join('/')
+ end
+
+ def generate_pretty_name_including_parent
+ [parent_pretty_name_with_fallback, (name.blank? ? name_with_fallback : name)].compact.join(' -> ')
+ end
+
+ def parent
+ translated_model.parent
+ end
+
+ def parent_permalink_with_fallback
+ localized_parent = parent.translations.find_by(locale: locale)
+ localized_parent.present? ? localized_parent.permalink : parent[:permalink]
+ end
+
+ def parent_pretty_name_with_fallback
+ localized_parent = parent.translations.find_by(locale: locale)
+ localized_parent.present? ? localized_parent.pretty_name : parent[:pretty_name]
+ end
+
+ def should_regenerate_pretty_name_and_permalink?
+ saved_changes.key?(:name) || saved_changes.key?(:permalink)
+ end
+ end
+
+ # Return meta_title if set otherwise generates from category name
+ def seo_title
+ meta_title.blank? ? name : meta_title
+ end
+
+ def set_pretty_name
+ self.pretty_name = generate_pretty_name
+ end
+
+ def generate_pretty_name
+ [parent&.pretty_name, name].compact.join(' -> ')
+ end
+
+ def generate_slug
+ if parent.present?
+ [parent.permalink, (permalink.blank? ? name.to_url : permalink.split('/').last.to_url)].join('/')
+ elsif permalink.blank?
+ name.to_url
+ else
+ permalink.to_url
+ end
+ end
+
+ def set_permalink
+ if Spree.use_translations?
+ translations.each(&:set_permalink)
+ else
+ self.permalink = generate_slug
+ end
+ end
+
+ def regenerate_pretty_name_and_permalink
+ Mobility.with_locale(nil) do
+ update_columns(pretty_name: generate_pretty_name, permalink: generate_slug, updated_at: Time.current)
+ end
+
+ children.reload.each(&:regenerate_pretty_name_and_permalink_as_child)
+ end
+
+ def regenerate_pretty_name_and_permalink_as_child
+ Mobility.with_locale(nil) do
+ update_columns(pretty_name: generate_pretty_name, permalink: generate_slug, updated_at: Time.current)
+ end
+
+ children.reload.each(&:regenerate_pretty_name_and_permalink_as_child)
+ end
+
+ def cached_self_and_descendants_ids
+ @cached_self_and_descendants_ids ||= Rails.cache.fetch("#{cache_key_with_version}/descendant-ids") do
+ self_and_descendants.ids
+ end
+ end
+
+ # awesome_nested_set sorts by :lft and :rgt. This call re-inserts the child
+ # node so that its resulting position matches the observable 0-indexed position.
+ # ** Note ** no :position column needed - a_n_s doesn't handle the reordering if
+ # you bring your own :order_column.
+ #
+ # See #3390 for background.
+ def child_index=(idx)
+ move_to_child_with_index(parent, idx.to_i) unless new_record?
+ end
+
+ private
+
+ def should_regenerate_pretty_name_and_permalink?
+ saved_changes.key?(:name) || saved_changes.key?(:permalink)
+ end
+
+ def sync_taxonomy_name
+ return unless taxonomy.present?
+ return unless saved_changes.key?(:name) && root?
+ return if taxonomy.name.to_s == name.to_s
+
+ taxonomy.update(name: name)
+ end
+
+ def touch_ancestors_and_taxonomy
+ # Touches all ancestors at once to avoid recursive taxonomy touch, and reduce queries.
+ ancestors.update_all(updated_at: Time.current)
+ # Have taxonomy touch happen in #touch_ancestors_and_taxonomy rather than association option in order for imports to override.
+ taxonomy.touch if taxonomy.present?
+ end
+
+ def capture_parent_before_move
+ @parent_id_before_move = parent_id_in_database
+ end
+
+ # Recompute the inclusive products_count for the moved node's new ancestor
+ # chain and the previous parent's chain too (whose subtree just lost this
+ # node's products).
+ def recalculate_products_count_after_move
+ affected = [id, @parent_id_before_move].compact
+ @parent_id_before_move = nil
+ self.class.recalculate_products_count(affected)
+ end
+
+ # Recomputes each ancestor's inclusive products_count as if this subtree were
+ # already gone (its product_categories are destroyed asynchronously, so they're
+ # still present here). Excludes self_and_descendants from the count.
+ def recalculate_ancestors_before_destroy
+ doomed_ids = self_and_descendants.ids
+ ancestors.each do |ancestor|
+ remaining = Spree::ProductCategory.
+ where(category_id: ancestor.self_and_descendants.where.not(id: doomed_ids).select(:id)).
+ distinct.count(:product_id)
+ ancestor.update_column(:products_count, remaining) if ancestor.products_count != remaining
+ end
+ end
+
+ def check_for_root
+ return unless taxonomy.try(:root).present? && parent_id.nil?
+
+ errors.add(:root_conflict, 'this taxonomy already has a root category')
+ end
+
+ def parent_belongs_to_same_taxonomy
+ return unless parent.present? && parent.taxonomy_id != taxonomy_id
+
+ errors.add(:parent, 'must belong to the same taxonomy')
+ end
+
+ def copy_taxonomy_from_parent
+ self.taxonomy = parent.taxonomy if parent.present? && taxonomy.blank?
+ end
+
+ def set_store
+ Spree::Deprecation.warn('Spree::Category#set_store is deprecated and will be removed in Spree 6.0. ensure_store instead.')
+ ensure_store
+ end
+
+ # Every category is store-owned. Resolve the store from the taxonomy, then the
+ # parent, finally the current store — so the direct column is always
+ # populated for new records. Guards on the raw +store_id+ column rather than
+ # +#store+, whose reader masks an unset column with the taxonomy fallback.
+ def ensure_store
+ return if store_id.present?
+
+ self.store = taxonomy&.store || parent&.store || Spree::Store.current
+ end
+
+ def regenerate_translations_pretty_name_and_permalink
+ translations.each(&:regenerate_pretty_name_and_permalink)
+ end
end
end
diff --git a/spree/core/app/models/spree/classification.rb b/spree/core/app/models/spree/classification.rb
index 136d542c7d..a3ee0b943c 100644
--- a/spree/core/app/models/spree/classification.rb
+++ b/spree/core/app/models/spree/classification.rb
@@ -1,57 +1,7 @@
-module Spree
- class Classification < Spree.base_class
- # Phase 2 transitional: table + FK column renamed (spree_products_taxons ->
- # spree_product_categories, taxon_id -> category_id). The class rename to
- # Spree::ProductCategory is Phase 4; the :taxon association stays, pointed at
- # the renamed FK. The taxon-side counter_cache (classification_count) is gone —
- # the descendant-inclusive products_count is kept up to date separately.
- self.table_name = 'spree_product_categories'
- acts_as_list scope: :category_id
-
- with_options inverse_of: :classifications, touch: true do
- belongs_to :product, class_name: 'Spree::Product', counter_cache: :categories_count
- belongs_to :taxon, class_name: 'Spree::Taxon', foreign_key: :category_id
- end
-
- validates :taxon, :product, presence: true
- validates :position, numericality: { only_integer: true, allow_blank: true, allow_nil: true }
- # For #3494
- validates :category_id, uniqueness: { scope: :product_id, message: :already_linked, allow_blank: true }
-
- # Keep the taxon's descendant-inclusive products_count (and its ancestors')
- # in sync on direct create/destroy. Bulk Taxons::AddProducts/RemoveProducts
- # skip these callbacks and recompute explicitly.
- after_create :recalculate_taxon_products_count
- after_destroy :recalculate_taxon_products_count
-
- self.whitelisted_ransackable_attributes = ['category_id', 'product_id']
+# frozen_string_literal: true
- scope :by_best_selling, lambda { |order_direction = :desc|
- left_joins(product: :orders).
- select("#{Spree::Classification.table_name}.*, COUNT(#{Spree::Order.table_name}.id) AS completed_orders_count, SUM(#{Spree::Order.table_name}.total) AS completed_orders_total").
- where(Spree::Order.table_name => { id: nil }).
- or(where.not(Spree::Order.table_name => { completed_at: nil })).
- group("#{Spree::Classification.table_name}.id").
- reorder(completed_orders_count: order_direction, completed_orders_total: order_direction)
- }
-
- scope :grouped_taxon_ids_for_products, lambda { |product_ids, taxon_groups|
- where(product_id: product_ids, category_id: taxon_groups).
- group(:product_id).
- then do |query|
- case ActiveRecord::Base.connection.adapter_name
- when 'PostgreSQL'
- query.pluck(:product_id, Arel.sql("STRING_AGG(category_id::text, ',')"))
- when 'Mysql2', 'SQLite'
- query.pluck(:product_id, Arel.sql('GROUP_CONCAT(category_id)'))
- end
- end
- }
-
- private
-
- def recalculate_taxon_products_count
- Spree::Taxon.recalculate_products_count(category_id)
- end
- end
+module Spree
+ # Deprecation alias for Spree::ProductCategory, renamed from Spree::Classification
+ # in 6.0. Kept for one release so existing references keep resolving; removed in 6.1.
+ Classification = ProductCategory
end
diff --git a/spree/core/app/models/spree/collection.rb b/spree/core/app/models/spree/collection.rb
index 7d8e924df7..ce2b8fab56 100644
--- a/spree/core/app/models/spree/collection.rb
+++ b/spree/core/app/models/spree/collection.rb
@@ -9,9 +9,18 @@ module Spree
has_prefix_id :coll
RULES_MATCH_POLICIES = %w[all any].freeze
- # Same values/format as Spree::Taxon::SORT_ORDERS — required by the search sort
- # pipeline (FiltersAggregator#to_api_sort splits on a space; apply_sort maps to 'price'/etc.).
- SORT_ORDERS = Spree::Taxon::SORT_ORDERS
+ # Space format (e.g. 'price asc') is required by the search sort pipeline:
+ # FiltersAggregator#to_api_sort splits on a space, and apply_sort maps to 'price'/etc.
+ SORT_ORDERS = [
+ 'manual',
+ 'best_selling',
+ 'price asc',
+ 'price desc',
+ 'available_on desc',
+ 'available_on asc',
+ 'name asc',
+ 'name desc'
+ ].freeze
include Spree::TranslatableResource
include Spree::TranslatableResourceSlug
@@ -19,7 +28,7 @@ module Spree
include Spree::Metadata
#
- # Slug / permalink — FriendlyId with history (mirrors Spree::Taxon; flat, no hierarchy).
+ # Slug / permalink — FriendlyId with history (mirrors Spree::Category; flat, no hierarchy).
# `use: :history` keeps old permalinks resolving via the shared friendly_id_slugs table
# after a rename. Declared before `translates` (as in Taxon). Within-store uniqueness is
# still enforced by the validation + DB index below — a collision errors (as in Taxon),
@@ -34,7 +43,7 @@ module Spree
#
# Action Text
#
- # Interim: description via ActionText (mirrors Spree::Taxon). 6.0-rich-text-descriptions.md
+ # Interim: description via ActionText (mirrors Spree::Category). 6.0-rich-text-descriptions.md
# migrates both Category and Collection off ActionText later.
translates :description, backend: :action_text
@@ -113,7 +122,7 @@ module Spree
self.marked_for_regenerate_products = false if !frozen? && only_once
end
- # Products matching the automatic rules (mirrors Spree::Taxon#products_matching_rules).
+ # Products matching the automatic rules (mirrors Spree::Category#products_matching_rules).
#
# @return [ActiveRecord::Relation]
def products_matching_rules(opts = {})
@@ -178,7 +187,7 @@ module Spree
end
end
- # Slug generation, flat (no parent hierarchy). Mirrors Spree::Taxon's dual set_permalink:
+ # Slug generation, flat (no parent hierarchy). Mirrors Spree::Category's dual set_permalink:
# with translations off, the model writes the base permalink column directly (which
# column_fallback routes the default locale to, bypassing the Translation before_save);
# with translations on, each Translation generates its own. An existing permalink is
diff --git a/spree/core/app/models/spree/exports/orders.rb b/spree/core/app/models/spree/exports/orders.rb
index dd14bf617c..d28998e481 100644
--- a/spree/core/app/models/spree/exports/orders.rb
+++ b/spree/core/app/models/spree/exports/orders.rb
@@ -8,7 +8,7 @@ module Spree
:shipments,
{ bill_address: [:state, :country] },
{ ship_address: [:state, :country] },
- { line_items: { variant: { product: [:taxons] } } },
+ { line_items: { variant: { product: [:categories] } } },
{ metafields: :metafield_definition }
]
end
diff --git a/spree/core/app/models/spree/permission_sets/default_customer.rb b/spree/core/app/models/spree/permission_sets/default_customer.rb
index 4c92404e96..7fd399a980 100644
--- a/spree/core/app/models/spree/permission_sets/default_customer.rb
+++ b/spree/core/app/models/spree/permission_sets/default_customer.rb
@@ -18,7 +18,7 @@ module Spree
can :read, Spree::Product
can :read, Spree::State
can :read, Spree::Store
- can :read, Spree::Taxon
+ can :read, Spree::Category
can :read, Spree::Taxonomy
can :read, Spree::Variant
can :read, Spree::Zone
diff --git a/spree/core/app/models/spree/permission_sets/product_display.rb b/spree/core/app/models/spree/permission_sets/product_display.rb
index 505fe1f100..ac3c7ee9b9 100644
--- a/spree/core/app/models/spree/permission_sets/product_display.rb
+++ b/spree/core/app/models/spree/permission_sets/product_display.rb
@@ -16,9 +16,9 @@ module Spree
can [:read, :admin], Spree::OptionValue
can [:read, :admin], Spree::Metafield
can [:read, :admin], Spree::Collection
- can [:read, :admin], Spree::Taxon
+ can [:read, :admin], Spree::Category
can [:read, :admin], Spree::Taxonomy
- can [:read, :admin], Spree::Classification
+ can [:read, :admin], Spree::ProductCategory
can [:read, :admin], Spree::Price
can [:read, :admin], Spree::PriceList
can [:read, :admin], Spree::PriceRule
diff --git a/spree/core/app/models/spree/permission_sets/product_management.rb b/spree/core/app/models/spree/permission_sets/product_management.rb
index 6a63350148..2e356959ec 100644
--- a/spree/core/app/models/spree/permission_sets/product_management.rb
+++ b/spree/core/app/models/spree/permission_sets/product_management.rb
@@ -14,9 +14,9 @@ module Spree
can :manage, Spree::Variant
can :manage, Spree::OptionType
can :manage, Spree::OptionValue
- can :manage, Spree::Taxon
+ can :manage, Spree::Category
can :manage, Spree::Taxonomy
- can :manage, Spree::Classification
+ can :manage, Spree::ProductCategory
can :manage, Spree::Collection
can :manage, Spree::ProductCollection
can :manage, Spree::CollectionRule
diff --git a/spree/core/app/models/spree/product.rb b/spree/core/app/models/spree/product.rb
index cac9a011aa..45860a66f4 100644
--- a/spree/core/app/models/spree/product.rb
+++ b/spree/core/app/models/spree/product.rb
@@ -42,9 +42,9 @@ module Spree
publishes_lifecycle_events
- MEMOIZED_METHODS = %w[total_on_hand taxonomy_ids taxon_and_ancestors
+ MEMOIZED_METHODS = %w[total_on_hand taxonomy_ids category_and_ancestors
default_variant_id tax_category default_variant variant_for_images
- brand_taxon main_taxon
+ primary_category
purchasable? in_stock? backorderable? digital?]
STATUSES = %w[draft active archived].freeze
@@ -69,10 +69,34 @@ module Spree
has_many :product_option_types, -> { order(:position) }, dependent: :destroy, inverse_of: :product
has_many :option_types, through: :product_option_types
- has_many :classifications, -> { order(created_at: :asc) }, dependent: :delete_all, inverse_of: :product
- has_many :taxons, through: :classifications, before_remove: :remove_taxon
- has_many :categories, through: :classifications, class_name: 'Spree::Category', source: :taxon
- has_many :taxonomies, through: :taxons
+ has_many :product_categories, -> { order(created_at: :asc) }, class_name: 'Spree::ProductCategory', dependent: :delete_all, inverse_of: :product
+ has_many :categories, -> { manual }, through: :product_categories, class_name: 'Spree::Category', source: :category, before_remove: :remove_category
+ has_many :taxonomies, through: :categories
+
+ # @deprecated The classification_count column was renamed to categories_count in 6.0.
+ alias_attribute :classification_count, :categories_count
+
+ # @deprecated Use #product_categories; removed in 6.1.
+ def classifications
+ product_categories
+ end
+
+ # @deprecated Use #categories / #category_ids; removed in 6.1.
+ def taxons
+ categories
+ end
+
+ def taxons=(value)
+ self.categories = value
+ end
+
+ def taxon_ids
+ category_ids
+ end
+
+ def taxon_ids=(ids)
+ self.category_ids = ids
+ end
has_many :product_collections, class_name: 'Spree::ProductCollection', dependent: :destroy_async, inverse_of: :product
has_many :collections, through: :product_collections
@@ -142,7 +166,7 @@ module Spree
after_save :save_master
after_save :run_touch_callbacks, if: :anything_changed?
after_save :reset_nested_changes
- after_touch :touch_taxons
+ after_touch :touch_categories
after_commit :auto_match_collections, if: :eligible_for_collection_matching?
@@ -214,21 +238,20 @@ module Spree
find_or_build_master.prices = prices_params
end
- # Maps 6.0 API name (category_ids) to model column (taxon_ids).
- # Accepts both prefixed IDs and raw integer IDs. Only taxons belonging to
- # the product's own store are assigned — ids from another store's
- # taxonomies are dropped, preventing cross-store category attachment.
+ # Accepts both prefixed IDs and raw integer IDs. Only categories belonging to
+ # the product's own store are assigned — ids from another store are dropped,
+ # preventing cross-store category attachment. Decodes prefixed IDs, then calls
+ # the generated setter via super.
def category_ids=(ids)
decoded_ids = Array(ids).filter_map do |id|
- id.to_s.include?('_') ? Spree::Taxon.decode_prefixed_id(id) : id
+ id.to_s.include?('_') ? Spree::Category.decode_prefixed_id(id) : id
end
- self.taxon_ids = Spree::Taxon.for_store(assignable_store).where(id: decoded_ids).ids
+ super(Spree::Category.for_store(assignable_store).where(id: decoded_ids).ids)
end
# Accepts both prefixed IDs and raw integer IDs. Only collections belonging
- # to the product's own store are assigned. `collections` is a direct
- # has_many :through, so this overrides the generated setter and calls super
- # (unlike #category_ids=, which writes through to the sibling taxon_ids).
+ # to the product's own store are assigned; this overrides the generated setter
+ # and calls super.
def collection_ids=(ids)
decoded_ids = Array(ids).filter_map do |id|
id.to_s.include?('_') ? Spree::Collection.decode_prefixed_id(id) : id
@@ -280,8 +303,8 @@ module Spree
end
self.whitelisted_ransackable_attributes = %w[description name slug discontinue_on status available_on created_at updated_at]
- self.whitelisted_ransackable_associations = %w[taxons categories collections store channels variants_including_master master variants tags labels
- shipping_category classifications option_types]
+ self.whitelisted_ransackable_associations = %w[categories collections store channels variants_including_master master variants tags labels
+ shipping_category product_categories option_types]
self.whitelisted_ransackable_scopes = %w[not_discontinued search_by_name in_taxon in_category in_categories in_collection price_between
price_lte price_gte
search multi_search in_stock out_of_stock with_option_value_ids
@@ -612,45 +635,17 @@ module Spree
super || variants_including_master.with_deleted.find_by(is_master: true)
end
- # Returns the brand taxon for the product
- # @return [Spree::Taxon]
- def brand_taxon
- @brand_taxon ||= if categories_count.zero?
- nil
- elsif Spree.use_translations?
- taxons.joins(:taxonomy).
- join_translation_table(Taxonomy).
- find_by(Taxonomy.translation_table_alias => { name: Spree.t(:taxonomy_brands_name) })
- elsif taxons.loaded?
- taxons.find { |taxon| taxon.taxonomy.name == Spree.t(:taxonomy_brands_name) }
- else
- taxons.joins(:taxonomy).find_by(Taxonomy.table_name => { name: Spree.t(:taxonomy_brands_name) })
- end
- end
-
- # Returns the brand name for the product
- # @return [String]
- def brand_name
- brand_taxon&.name
- end
-
- def main_taxon
+ # The product's primary category — the first manually-assigned category.
+ # Renamed from #main_taxon in 6.0.
+ def primary_category
return if categories_count.zero?
- @main_taxon ||= taxons.first
- end
-
- # First category (the main_taxon -> primary_category rename). main_taxon is
- # retained until the Phase 4 taxon->category sweep — reports and CSV
- # presenters still call it.
- def primary_category
@primary_category ||= categories.first
end
- def taxons_for_store(store)
- return if categories_count.zero?
-
- taxons.loaded? ? taxons.find_all { |taxon| taxon.taxonomy.store_id == store.id } : taxons.for_store(store)
+ # @deprecated Use {#primary_category}.
+ def main_taxon
+ primary_category
end
def any_variant_in_stock_or_backorderable?
@@ -693,8 +688,8 @@ module Spree
metafields_for_csv ||= Spree::MetafieldDefinition.for_resource_type('Spree::Product').order(:namespace, :key).map do |mf_def|
metafields.find { |mf| mf.metafield_definition_id == mf_def.id }&.csv_value
end
- taxons_for_csv ||= taxons.manual.reorder(depth: :desc).first(3).pluck(:pretty_name)
- taxons_for_csv.fill(nil, taxons_for_csv.size...3)
+ categories_for_csv ||= categories.reorder(depth: :desc).first(3).pluck(:pretty_name)
+ categories_for_csv.fill(nil, categories_for_csv.size...3)
csv_lines = []
all_variants = has_variants? ? variants_including_master.to_a : [master]
@@ -703,7 +698,7 @@ module Spree
# Primary rows in the store's default currency
all_variants.each_with_index do |variant, index|
- csv_lines << Spree::CSV::ProductVariantPresenter.new(self, variant, index, properties_for_csv, taxons_for_csv, store,
+ csv_lines << Spree::CSV::ProductVariantPresenter.new(self, variant, index, properties_for_csv, categories_for_csv, store,
metafields_for_csv).call
end
@@ -870,7 +865,7 @@ module Spree
def add_associations_from_prototype
if prototype_id && prototype = Spree::Prototype.find_by(id: prototype_id)
self.option_types = prototype.option_types
- self.taxons = prototype.taxons
+ self.categories = prototype.taxons
end
end
@@ -975,16 +970,16 @@ module Spree
run_callbacks(:touch)
end
- def taxon_and_ancestors
- @taxon_and_ancestors ||= taxons.map(&:self_and_ancestors).flatten.uniq
+ def category_and_ancestors
+ @category_and_ancestors ||= categories.map(&:self_and_ancestors).flatten.uniq
end
- # Iterate through this products taxons and taxonomies and touch their timestamps in a batch
- def touch_taxons
- if taxons.any?
- Spree::Products::TouchTaxonsJob.
+ # Iterate through this product's categories and taxonomies and touch their timestamps in a batch
+ def touch_categories
+ if categories.any?
+ Spree::Products::TouchCategoriesJob.
set(wait: 5.seconds).
- perform_later(taxon_and_ancestors.map(&:id), taxonomy_ids.uniq)
+ perform_later(category_and_ancestors.map(&:id), taxonomy_ids.uniq)
end
end
@@ -995,9 +990,9 @@ module Spree
end
end
- def remove_taxon(taxon)
- removed_classifications = classifications.where(taxon: taxon)
- removed_classifications.each(&:remove_from_list)
+ def remove_category(category)
+ removed_product_categories = product_categories.where(category: category)
+ removed_product_categories.each(&:remove_from_list)
end
def discontinue_on_must_be_later_than_make_active_at
diff --git a/spree/core/app/models/spree/product_category.rb b/spree/core/app/models/spree/product_category.rb
new file mode 100644
index 0000000000..e3e1236148
--- /dev/null
+++ b/spree/core/app/models/spree/product_category.rb
@@ -0,0 +1,64 @@
+module Spree
+ # Join model between Spree::Product and Spree::Category. Renamed from
+ # Spree::Classification in 6.0 (Spree::Classification kept as a deprecation
+ # alias). The category_id column was renamed in 6.0, so the association is a
+ # plain #category with no foreign_key override.
+ class ProductCategory < Spree.base_class
+ acts_as_list scope: :category_id
+
+ with_options inverse_of: :product_categories, touch: true do
+ belongs_to :product, class_name: 'Spree::Product', counter_cache: :categories_count
+ belongs_to :category, class_name: 'Spree::Category'
+ end
+
+ validates :category, :product, presence: true
+ validates :position, numericality: { only_integer: true, allow_blank: true, allow_nil: true }
+ # For #3494
+ validates :category_id, uniqueness: { scope: :product_id, message: :already_linked, allow_blank: true }
+
+ # Keep the category's descendant-inclusive products_count (and its ancestors')
+ # in sync on direct create/destroy. Bulk Categories::AddProducts/RemoveProducts
+ # skip these callbacks and recompute explicitly.
+ after_create :recalculate_category_products_count
+ after_destroy :recalculate_category_products_count
+
+ self.whitelisted_ransackable_attributes = ['category_id', 'product_id']
+
+ scope :by_best_selling, lambda { |order_direction = :desc|
+ left_joins(product: :orders).
+ select("#{Spree::ProductCategory.table_name}.*, COUNT(#{Spree::Order.table_name}.id) AS completed_orders_count, SUM(#{Spree::Order.table_name}.total) AS completed_orders_total").
+ where(Spree::Order.table_name => { id: nil }).
+ or(where.not(Spree::Order.table_name => { completed_at: nil })).
+ group("#{Spree::ProductCategory.table_name}.id").
+ reorder(completed_orders_count: order_direction, completed_orders_total: order_direction)
+ }
+
+ scope :grouped_category_ids_for_products, lambda { |product_ids, category_groups|
+ where(product_id: product_ids, category_id: category_groups).
+ group(:product_id).
+ then do |query|
+ case ActiveRecord::Base.connection.adapter_name
+ when 'PostgreSQL'
+ query.pluck(:product_id, Arel.sql("STRING_AGG(category_id::text, ',')"))
+ when 'Mysql2', 'SQLite'
+ query.pluck(:product_id, Arel.sql('GROUP_CONCAT(category_id)'))
+ end
+ end
+ }
+
+ # @deprecated Use #category / #category=; removed in 6.1.
+ def taxon
+ category
+ end
+
+ def taxon=(value)
+ self.category = value
+ end
+
+ private
+
+ def recalculate_category_products_count
+ Spree::Category.recalculate_products_count(category_id)
+ end
+ end
+end
diff --git a/spree/core/app/models/spree/promotion/rules/category.rb b/spree/core/app/models/spree/promotion/rules/category.rb
new file mode 100644
index 0000000000..c50f8ffc62
--- /dev/null
+++ b/spree/core/app/models/spree/promotion/rules/category.rb
@@ -0,0 +1,170 @@
+module Spree
+ class Promotion
+ module Rules
+ # Promotion rule matching an order against a set of Spree::Category records.
+ # Renamed from Spree::Promotion::Rules::Taxon in 6.0 (alias kept for one
+ # release). Existing spree_promotion_rules.type strings are backfilled by the
+ # Phase 4 data migration; the alias keeps old rows resolving until then.
+ class Category < PromotionRule
+ #
+ # Associations
+ #
+ has_many :promotion_rule_categories, class_name: 'Spree::PromotionRuleCategory',
+ foreign_key: 'promotion_rule_id',
+ dependent: :destroy
+ has_many :categories, through: :promotion_rule_categories, class_name: 'Spree::Category', source: :category
+
+ def self.additional_permitted_attributes
+ [category_ids: []]
+ end
+
+ # Wire-format shorthand is `category`. `key` (instance) cascades through `api_type`.
+ def self.api_type
+ 'category'
+ end
+
+ # Decode prefixed IDs before delegating to the generated setter (direct
+ # calls bypass PrefixedId's assign_attributes auto-resolver).
+ def category_ids=(ids)
+ super(Array(ids).map do |id|
+ Spree::PrefixedId.prefixed_id?(id) ? Spree::Category.find_by_param!(id).id : id
+ end)
+ end
+
+ #
+ # Preferences
+ #
+ MATCH_POLICIES = %w(any all)
+ preference :match_policy, :string, default: MATCH_POLICIES.first
+
+ #
+ # Attributes
+ #
+ attr_accessor :category_ids_to_add
+
+ #
+ # Callbacks
+ #
+ after_save :add_categories
+
+ def applicable?(promotable)
+ promotable.is_a?(Spree::Order)
+ end
+
+ def eligible_category_ids
+ @eligible_category_ids ||= promotion_rule_categories.pluck(:category_id)
+ end
+
+ def eligible?(order, _options = {})
+ return true if eligible_category_ids.empty?
+
+ order_category_ids_with_ancestors = category_ids_in_order_including_ancestors(order)
+
+ if preferred_match_policy == 'all'
+ unless eligible_category_ids.all? { |id| order_category_ids_with_ancestors.include?(id) }
+ eligibility_errors.add(:base, eligibility_error_message(:missing_taxon))
+ end
+ else
+ unless eligible_category_ids.any? { |id| order_category_ids_with_ancestors.include?(id) }
+ eligibility_errors.add(:base, eligibility_error_message(:no_matching_taxons))
+ end
+ end
+
+ eligibility_errors.empty?
+ end
+
+ def actionable?(line_item)
+ Spree::ProductCategory.where(category_id: eligible_category_ids_including_children, product_id: line_item.product_id).exists?
+ end
+
+ #
+ # Deprecated aliases (removed in 6.1)
+ #
+ # @deprecated Use #categories.
+ def taxons
+ categories
+ end
+
+ # @deprecated Use #categories=.
+ def taxons=(value)
+ self.categories = value
+ end
+
+ # @deprecated Use #category_ids.
+ def taxon_ids
+ category_ids
+ end
+
+ # @deprecated Use #category_ids=.
+ def taxon_ids=(ids)
+ self.category_ids = ids
+ end
+
+ # @deprecated Use #eligible_category_ids.
+ alias eligible_taxon_ids eligible_category_ids
+
+ # @deprecated Use #category_ids_to_add.
+ def taxon_ids_to_add
+ category_ids_to_add
+ end
+
+ def taxon_ids_to_add=(ids)
+ self.category_ids_to_add = ids
+ end
+
+ def taxon_ids_string
+ ActiveSupport::Deprecation.warn(
+ 'Please use `category_ids=` instead.'
+ )
+ categories.pluck(:id).join(',')
+ end
+
+ def taxon_ids_string=(s)
+ ActiveSupport::Deprecation.warn(
+ 'Please use `category_ids=` instead.'
+ )
+ ids = s.to_s.split(',').map(&:strip)
+ self.categories = Spree::Category.for_stores(stores).find(ids)
+ end
+
+ private
+
+ # IDs of categories in rule including all their children
+ def eligible_category_ids_including_children
+ @eligible_category_ids_including_children ||= begin
+ return [] if eligible_category_ids.empty?
+
+ Spree::Category.where(id: eligible_category_ids).flat_map(&:cached_self_and_descendants_ids).uniq
+ end
+ end
+
+ # IDs of categories in order that match rule categories (or their children), plus all ancestors
+ def category_ids_in_order_including_ancestors(order)
+ # Get category IDs from order products that are within rule categories or their children
+ order_category_ids = Spree::ProductCategory.where(product_id: order.product_ids, category_id: eligible_category_ids_including_children).pluck(:category_id).uniq
+
+ return [] if order_category_ids.empty?
+
+ # Get those categories plus all their ancestors
+ Spree::Category.where(id: order_category_ids).flat_map { |category| category.self_and_ancestors.ids }.uniq
+ end
+
+ def add_categories
+ return if category_ids_to_add.nil?
+
+ promotion_rule_categories.delete_all
+
+ if category_ids_to_add.any?
+ Spree::PromotionRuleCategory.insert_all(
+ category_ids_to_add.map { |category_id| { category_id: category_id, promotion_rule_id: id } }
+ )
+ end
+
+ # Clear memoized values
+ @eligible_category_ids = nil
+ @eligible_category_ids_including_children = nil
+ end
+ end
+ end
+ end
+end
diff --git a/spree/core/app/models/spree/promotion/rules/taxon.rb b/spree/core/app/models/spree/promotion/rules/taxon.rb
index 038822ca2d..6aa93c03de 100644
--- a/spree/core/app/models/spree/promotion/rules/taxon.rb
+++ b/spree/core/app/models/spree/promotion/rules/taxon.rb
@@ -1,137 +1,12 @@
+# frozen_string_literal: true
+
module Spree
class Promotion
module Rules
- class Taxon < PromotionRule
- #
- # Associations
- #
- has_many :promotion_rule_taxons, class_name: 'Spree::PromotionRuleTaxon',
- foreign_key: 'promotion_rule_id',
- dependent: :destroy
- has_many :taxons, through: :promotion_rule_taxons, class_name: 'Spree::Taxon'
-
- def self.additional_permitted_attributes
- [category_ids: []]
- end
-
- # Wire-format shorthand is `category` (the model is still `Taxon`
- # pre-6.0 rename). `key` (instance) cascades through `api_type`.
- def self.api_type
- 'category'
- end
-
- # PrefixedId's auto-resolver in `assign_attributes` only fires
- # when the `_ids` stem matches an association — `categories`
- # doesn't, so decode prefixed IDs explicitly here.
- def category_ids=(ids)
- self.taxon_ids = Array(ids).map do |id|
- Spree::PrefixedId.prefixed_id?(id) ? Spree::Taxon.find_by_param!(id).id : id
- end
- end
-
- def category_ids
- taxon_ids
- end
-
- #
- # Preferences
- #
- MATCH_POLICIES = %w(any all)
- preference :match_policy, :string, default: MATCH_POLICIES.first
-
- #
- # Attributes
- #
- attr_accessor :taxon_ids_to_add
-
- #
- # Callbacks
- #
- after_save :add_taxons
-
- def applicable?(promotable)
- promotable.is_a?(Spree::Order)
- end
-
- def eligible_taxon_ids
- @eligible_taxon_ids ||= promotion_rule_taxons.pluck(:taxon_id)
- end
-
- def eligible?(order, _options = {})
- return true if eligible_taxon_ids.empty?
-
- if preferred_match_policy == 'all'
- order_taxon_ids_with_ancestors = taxon_ids_in_order_including_ancestors(order)
- unless eligible_taxon_ids.all? { |id| order_taxon_ids_with_ancestors.include?(id) }
- eligibility_errors.add(:base, eligibility_error_message(:missing_taxon))
- end
- else
- order_taxon_ids_with_ancestors = taxon_ids_in_order_including_ancestors(order)
- unless eligible_taxon_ids.any? { |id| order_taxon_ids_with_ancestors.include?(id) }
- eligibility_errors.add(:base, eligibility_error_message(:no_matching_taxons))
- end
- end
-
- eligibility_errors.empty?
- end
-
- def actionable?(line_item)
- Spree::Classification.where(category_id: eligible_taxon_ids_including_children, product_id: line_item.product_id).exists?
- end
-
- def taxon_ids_string
- ActiveSupport::Deprecation.warn(
- 'Please use `taxon_ids=` instead.'
- )
- taxons.pluck(:id).join(',')
- end
-
- def taxon_ids_string=(s)
- ActiveSupport::Deprecation.warn(
- 'Please use `taxon_ids=` instead.'
- )
- ids = s.to_s.split(',').map(&:strip)
- self.taxons = Spree::Taxon.for_stores(stores).find(ids)
- end
-
- private
-
- # IDs of taxons in rule including all their children
- def eligible_taxon_ids_including_children
- @eligible_taxon_ids_including_children ||= begin
- return [] if eligible_taxon_ids.empty?
-
- Spree::Taxon.where(id: eligible_taxon_ids).flat_map(&:cached_self_and_descendants_ids).uniq
- end
- end
-
- # IDs of taxons in order that match rule taxons (or their children), plus all ancestors
- def taxon_ids_in_order_including_ancestors(order)
- # Get taxon IDs from order products that are within rule taxons or their children
- order_taxon_ids = Spree::Classification.where(product_id: order.product_ids, category_id: eligible_taxon_ids_including_children).pluck(:category_id).uniq
-
- return [] if order_taxon_ids.empty?
-
- # Get those taxons plus all their ancestors
- Spree::Taxon.where(id: order_taxon_ids).flat_map { |taxon| taxon.self_and_ancestors.ids }.uniq
- end
-
- def add_taxons
- return if taxon_ids_to_add.nil?
-
- promotion_rule_taxons.delete_all
-
- if taxon_ids_to_add.any?
- Spree::PromotionRuleTaxon.insert_all(
- taxon_ids_to_add.map { |taxon_id| { taxon_id: taxon_id, promotion_rule_id: id } }
- )
- end
-
- # Clear memoized values
- @eligible_taxon_ids = nil
- @eligible_taxon_ids_including_children = nil
- end
- end
+ # Deprecation alias for Spree::Promotion::Rules::Category, renamed from
+ # Spree::Promotion::Rules::Taxon in 6.0. Old STI type strings still resolve
+ # through this alias until the Phase 4 data migration rewrites them. Removed in 6.1.
+ Taxon = Category
end
end
end
diff --git a/spree/core/app/models/spree/promotion_handler/promotion_duplicator.rb b/spree/core/app/models/spree/promotion_handler/promotion_duplicator.rb
index eef82afe36..0d92b9253f 100644
--- a/spree/core/app/models/spree/promotion_handler/promotion_duplicator.rb
+++ b/spree/core/app/models/spree/promotion_handler/promotion_duplicator.rb
@@ -31,7 +31,7 @@ module Spree
new_rule.save!
new_rule.users = rule.users if rule.try(:users)
- new_rule.taxons = rule.taxons if rule.try(:taxons)
+ new_rule.categories = rule.categories if rule.try(:categories)
new_rule.products = rule.products if rule.try(:products)
end
end
diff --git a/spree/core/app/models/spree/promotion_rule_category.rb b/spree/core/app/models/spree/promotion_rule_category.rb
new file mode 100644
index 0000000000..158f91acb4
--- /dev/null
+++ b/spree/core/app/models/spree/promotion_rule_category.rb
@@ -0,0 +1,21 @@
+module Spree
+ # Join model between a Spree::Promotion::Rules::Category rule and a
+ # Spree::Category. Renamed from Spree::PromotionRuleTaxon in 6.0 (alias kept for
+ # one release).
+ class PromotionRuleCategory < Spree.base_class
+ belongs_to :promotion_rule, class_name: 'Spree::PromotionRule'
+ belongs_to :category, class_name: 'Spree::Category'
+
+ validates :promotion_rule, :category, presence: true
+ validates :promotion_rule_id, uniqueness: { scope: :category_id }, allow_nil: true
+
+ # @deprecated Use #category / #category=; removed in 6.1.
+ def taxon
+ category
+ end
+
+ def taxon=(value)
+ self.category = value
+ end
+ end
+end
diff --git a/spree/core/app/models/spree/promotion_rule_taxon.rb b/spree/core/app/models/spree/promotion_rule_taxon.rb
index be4e686ecd..52f8aa38e4 100644
--- a/spree/core/app/models/spree/promotion_rule_taxon.rb
+++ b/spree/core/app/models/spree/promotion_rule_taxon.rb
@@ -1,9 +1,7 @@
-module Spree
- class PromotionRuleTaxon < Spree.base_class
- belongs_to :promotion_rule, class_name: 'Spree::PromotionRule'
- belongs_to :taxon, class_name: 'Spree::Taxon'
+# frozen_string_literal: true
- validates :promotion_rule, :taxon, presence: true
- validates :promotion_rule_id, uniqueness: { scope: :taxon_id }, allow_nil: true
- end
+module Spree
+ # Deprecation alias for Spree::PromotionRuleCategory, renamed from
+ # Spree::PromotionRuleTaxon in 6.0. Kept for one release; removed in 6.1.
+ PromotionRuleTaxon = PromotionRuleCategory
end
diff --git a/spree/core/app/models/spree/prototype.rb b/spree/core/app/models/spree/prototype.rb
index aacb86e4d8..2ea73ef021 100644
--- a/spree/core/app/models/spree/prototype.rb
+++ b/spree/core/app/models/spree/prototype.rb
@@ -8,7 +8,7 @@ module Spree
has_many :option_types, through: :option_type_prototypes, class_name: 'Spree::OptionType'
has_many :prototype_taxons, class_name: 'Spree::PrototypeTaxon'
- has_many :taxons, through: :prototype_taxons, class_name: 'Spree::Taxon'
+ has_many :taxons, through: :prototype_taxons, class_name: 'Spree::Category'
validates :name, presence: true
end
diff --git a/spree/core/app/models/spree/prototype_taxon.rb b/spree/core/app/models/spree/prototype_taxon.rb
index f302bc6b9d..519b520c81 100644
--- a/spree/core/app/models/spree/prototype_taxon.rb
+++ b/spree/core/app/models/spree/prototype_taxon.rb
@@ -1,6 +1,6 @@
module Spree
class PrototypeTaxon < Spree.base_class
- belongs_to :taxon, class_name: 'Spree::Taxon'
+ belongs_to :taxon, class_name: 'Spree::Category'
belongs_to :prototype, class_name: 'Spree::Prototype'
validates :prototype, :taxon, presence: true
diff --git a/spree/core/app/models/spree/report_line_items/products_performance.rb b/spree/core/app/models/spree/report_line_items/products_performance.rb
index 550aaa8aa1..967dedf044 100644
--- a/spree/core/app/models/spree/report_line_items/products_performance.rb
+++ b/spree/core/app/models/spree/report_line_items/products_performance.rb
@@ -4,7 +4,6 @@ module Spree
attribute :sku, :string
attribute :name, :string
attribute :vendor, :string
- attribute :brand, :string
attribute :category_lvl0, :string
attribute :category_lvl1, :string
attribute :category_lvl2, :string
@@ -22,10 +21,6 @@ module Spree
record.try(:vendor_name)
end
- def brand
- record.try(:brand_name)
- end
-
def category_lvl0
mapped_categories&.first
end
@@ -69,7 +64,7 @@ module Spree
end
def mapped_categories
- @mapped_categories ||= record.main_taxon&.pretty_name&.split('->')&.map(&:strip)
+ @mapped_categories ||= record.primary_category&.pretty_name&.split('->')&.map(&:strip)
end
end
end
diff --git a/spree/core/app/models/spree/reports/products_performance.rb b/spree/core/app/models/spree/reports/products_performance.rb
index 0f669d8ba1..7a854d1aa0 100644
--- a/spree/core/app/models/spree/reports/products_performance.rb
+++ b/spree/core/app/models/spree/reports/products_performance.rb
@@ -28,7 +28,7 @@ module Spree
product_scope = store.products
product_scope = product_scope.where(vendor_id: vendor.id) if defined?(vendor) && vendor.present?
- product_scope.includes(:taxons, :tax_category, variants: :prices, master: :prices).
+ product_scope.includes(:categories, :tax_category, variants: :prices, master: :prices).
joins("LEFT JOIN (#{line_items_sql}) AS line_items ON #{Spree::Product.table_name}.id = line_items.product_id").
select("
spree_products.*,
diff --git a/spree/core/app/models/spree/search_provider/meilisearch.rb b/spree/core/app/models/spree/search_provider/meilisearch.rb
index ae3ce6022a..4c0832a947 100644
--- a/spree/core/app/models/spree/search_provider/meilisearch.rb
+++ b/spree/core/app/models/spree/search_provider/meilisearch.rb
@@ -464,8 +464,8 @@ module Spree
def build_category_facet(distribution)
prefixed_ids = distribution.keys
- raw_ids = prefixed_ids.filter_map { |pid| Spree::Taxon.decode_prefixed_id(pid) }
- categories = Spree::Taxon.where(id: raw_ids).index_by(&:prefixed_id)
+ raw_ids = prefixed_ids.filter_map { |pid| Spree::Category.decode_prefixed_id(pid) }
+ categories = Spree::Category.where(id: raw_ids).index_by(&:prefixed_id)
{
id: 'categories',
diff --git a/spree/core/app/models/spree/store.rb b/spree/core/app/models/spree/store.rb
index 24eaf61a87..c151e3be7e 100644
--- a/spree/core/app/models/spree/store.rb
+++ b/spree/core/app/models/spree/store.rb
@@ -96,10 +96,20 @@ module Spree
has_many :store_credit_events, through: :store_credits, class_name: 'Spree::StoreCreditEvent'
has_many :taxonomies, class_name: 'Spree::Taxonomy'
- has_many :taxons, class_name: 'Spree::Taxon'
- has_many :categories, class_name: 'Spree::Category'
+ # Category surfaces exclude automatic (rule-based) rows. The manual scope is a
+ # no-op once the Phase 4 migration moves them to Collections; removed in 6.1.
+ has_many :categories, -> { manual }, class_name: 'Spree::Category'
has_many :collections, class_name: 'Spree::Collection', dependent: :destroy_async
+ # @deprecated Use #categories; removed in 6.1.
+ def taxons
+ categories
+ end
+
+ def taxons=(value)
+ self.categories = value
+ end
+
has_many :promotions, class_name: 'Spree::Promotion', dependent: :nullify
has_many :wishlists, class_name: 'Spree::Wishlist'
diff --git a/spree/core/app/models/spree/taxon.rb b/spree/core/app/models/spree/taxon.rb
index f3d8c49232..ec36541f43 100644
--- a/spree/core/app/models/spree/taxon.rb
+++ b/spree/core/app/models/spree/taxon.rb
@@ -1,514 +1,12 @@
# frozen_string_literal: true
-require 'stringex'
-
module Spree
- class Taxon < Spree.base_class
- # Phase 2 transitional: the table was renamed to spree_categories (the class
- # rename to Spree::Category is Phase 4). Point the model at the renamed table
- # so the app and the Phase 3 data migration work in the interim state.
- self.table_name = 'spree_categories'
-
- include Spree::SingleStoreResource
-
- has_prefix_id :ctg
-
- RULES_MATCH_POLICIES = %w[all any].freeze
- SORT_ORDERS = [
- 'manual',
- 'best_selling',
- 'price asc',
- 'price desc',
- 'available_on desc',
- 'available_on asc',
- 'name asc',
- 'name desc'
- ].freeze
-
- include Spree::TranslatableResource
- include Spree::TranslatableResourceSlug
- include Spree::Metafields
- include Spree::Metadata
- include Spree::MemoizedData
-
- MEMOIZED_METHODS = %w[cached_self_and_descendants_ids].freeze
-
- #
- # Magic methods
- #
- extend FriendlyId
- friendly_id :permalink, slug_column: :permalink, use: :history
- acts_as_nested_set dependent: :destroy, counter_cache: :children_count
-
- #
- # Associations
- #
- belongs_to :taxonomy, class_name: 'Spree::Taxonomy', inverse_of: :taxons
- belongs_to :store, class_name: 'Spree::Store', optional: true
- has_many :classifications, -> { order(:position) }, dependent: :destroy_async, inverse_of: :taxon
- has_many :products, through: :classifications
-
- has_many :prototype_taxons, class_name: 'Spree::PrototypeTaxon', dependent: :destroy
- has_many :prototypes, through: :prototype_taxons, class_name: 'Spree::Prototype'
-
- has_many :promotion_rule_taxons, class_name: 'Spree::PromotionRuleTaxon', dependent: :destroy
- has_many :promotion_rules, through: :promotion_rule_taxons, class_name: 'Spree::PromotionRule'
-
- #
- # Attachments
- #
- has_one_attached :image, service: Spree.public_storage_service_name
- has_one_attached :square_image, service: Spree.public_storage_service_name
-
- #
- # Validations
- #
- validates :name, presence: true
- validates :taxonomy, presence: true, if: :requires_taxonomy?
- validates :store, presence: true
- # Taxonomy-backed taxons are unique within their taxonomy; taxonomy-less
- # categories (store-owned) are unique within their store, so two stores can
- # each have a top-level "Shoes".
- validates :name, uniqueness: { scope: %i[parent_id taxonomy_id], case_sensitive: false }, if: :requires_taxonomy?
- validates :permalink, uniqueness: { scope: %i[parent_id taxonomy_id], case_sensitive: false }, if: :requires_taxonomy?
- validates :name, uniqueness: { scope: %i[parent_id store_id], case_sensitive: false }, unless: :requires_taxonomy?
- validates :permalink, uniqueness: { scope: %i[parent_id store_id], case_sensitive: false }, unless: :requires_taxonomy?
- validates :hide_from_nav, inclusion: { in: [true, false] }
- validate :check_for_root, on: :create
- validate :parent_belongs_to_same_taxonomy
- with_options length: { maximum: 255 }, allow_blank: true do
- validates :meta_keywords
- validates :meta_description
- validates :meta_title
- end
- validates :image, :square_image, content_type: Rails.application.config.active_storage.web_image_content_types
-
- #
- # Callbacks
- #
- before_validation :set_permalink, if: :name
- before_validation :copy_taxonomy_from_parent
- before_save :set_pretty_name
- after_save :touch_ancestors_and_taxonomy
- after_update :sync_taxonomy_name
- after_touch :touch_ancestors_and_taxonomy
- after_commit :regenerate_pretty_name_and_permalink, on: :update, if: :should_regenerate_pretty_name_and_permalink?
- after_move :regenerate_pretty_name_and_permalink
- after_move :regenerate_translations_pretty_name_and_permalink
- # Moving a subtree shifts its products under a new ancestor chain (and away
- # from the old one), so recompute both branches' inclusive products_count.
- # Capture the old parent before the move; recompute both chains after.
- before_move :capture_parent_before_move
- after_move :recalculate_products_count_after_move
- # Destroying a taxon drops its subtree's products from every ancestor's
- # inclusive count. Recompute the ancestors here (while the doomed subtree's
- # rows still exist) excluding that subtree, since the Classification destroy
- # callbacks can't help: classifications are removed via destroy_async, so
- # they outlive this callback and their taxon may already be gone.
- before_destroy :recalculate_ancestors_before_destroy, prepend: true
-
- #
- # Scopes
- #
- # Prefer the direct store_id column; fall back to the taxonomy join for rows
- # not yet backfilled (store_id IS NULL) so legacy behaviour is preserved.
- scope :for_store, ->(store) { for_stores([store]) }
- scope :for_stores, lambda { |stores|
- store_ids = Array(stores).map(&:id)
- taxonomy_ids = Spree::Taxonomy.where(store_id: store_ids).select(:id)
- where(store_id: store_ids).or(where(store_id: nil, taxonomy_id: taxonomy_ids))
- }
- scope :for_taxonomy, lambda { |taxonomy_name|
- Spree::Deprecation.warn('Spree::Taxon.for_taxonomy is deprecated and will be removed in Spree 6. Please use for_store instead.')
-
- if Spree.use_translations?
- joins(:taxonomy)
- .join_translation_table(Taxonomy)
- .where(
- Taxonomy.arel_table_alias[:name].lower.matches(taxonomy_name.downcase.strip)
- )
- else
- joins(:taxonomy).where(Spree::Taxonomy.arel_table[:name].lower.matches(taxonomy_name.downcase.strip))
- end
- }
-
- #
- # Search
- #
- def self.search_by_name(query)
- i18n { name.lower.matches("%#{query.downcase}%") }
- end
-
- scope :with_matching_name, lambda { |name_to_match|
- value = name_to_match.to_s.strip.downcase
-
- if Spree.use_translations?
- i18n { name.lower.eq(value) }
- else
- where(arel_table[:name].lower.eq(value))
- end
- }
-
- #
- # Ransack
- #
- self.whitelisted_ransackable_associations = %w[taxonomy parent]
- self.whitelisted_ransackable_attributes = %w[name permalink automatic depth is_root children_count
- products_count pretty_name hide_from_nav parent_id]
-
- #
- # Translations
- #
- TRANSLATABLE_FIELDS = %i[name pretty_name description permalink].freeze
- RICH_TEXT_TRANSLATABLE_FIELDS = %i[description].freeze
- # Phase 2 transitional: table_name is now spree_categories, but the Mobility
- # translation table + FK are NOT renamed until Phase 4. Pin them so Mobility
- # doesn't derive spree_category_translations/spree_category_id from table_name.
- translates(*TRANSLATABLE_FIELDS, column_fallback: !Spree.always_use_translations?,
- table_name: 'spree_taxon_translations', foreign_key: 'spree_taxon_id')
-
- #
- # Action Text
- #
- translates :description, backend: :action_text
-
- # Automatic taxons
- validates :rules_match_policy, inclusion: { in: RULES_MATCH_POLICIES }, presence: true
- validates :sort_order, inclusion: { in: SORT_ORDERS }, presence: true
-
- has_many :taxon_rules, class_name: 'Spree::TaxonRule', dependent: :destroy
- accepts_nested_attributes_for :taxon_rules, allow_destroy: true, reject_if: proc { |attributes|
- attributes['value'].blank?
- }
- alias rules taxon_rules
-
- scope :manual, -> { where.not(automatic: true) }
- scope :automatic, -> { where(automatic: true) }
-
- def manual?
- !automatic?
- end
-
- # The owning store. Prefers the direct +store_id+; falls back to the
- # taxonomy's store for legacy rows not yet backfilled.
- def store
- super || taxonomy&.store
- end
-
- # Whether a taxonomy is mandatory. Legacy +Spree::Taxon+ requires one;
- # +Spree::Category+ overrides this to false (it is owned via +store_id+).
- def requires_taxonomy?
- true
- end
-
- def manual_sort_order?
- sort_order == 'manual'
- end
-
- def active_products_with_descendants
- @active_products_with_descendants ||= store.products
- .joins(:classifications)
- .active
- .where(
- Spree::Classification.table_name => {
- category_id: descendants.ids + [id]
- }
- )
- end
-
- # Recomputes the stored, descendant-inclusive +products_count+ for the given
- # taxons AND all of their ancestors — the nodes whose inclusive count can
- # shift when a classification changes. Counts unique products classified
- # under each node or its descendants (a product reachable through several
- # nodes is counted once per ancestor). Call after any classification change.
- #
- # @param taxon_ids [Array<Integer>] taxons whose branch counts changed
- def self.recalculate_products_count(taxon_ids)
- changed = unscoped.where(id: Array(taxon_ids).compact.uniq)
-
- # The affected nodes are each changed taxon plus its ancestors.
- affected = changed.flat_map { |taxon| taxon.self_and_ancestors.to_a }.uniq(&:id)
-
- affected.each do |taxon|
- count = Spree::Classification.where(category_id: taxon.self_and_descendants.select(:id))
- .distinct.count(:product_id)
- taxon.update_column(:products_count, count) if taxon.products_count != count
- end
- end
-
- def products_matching_rules(opts = {})
- return Spree::Product.none if manual? || rules.empty?
-
- storefront = opts[:storefront] || false
- currency = opts[:currency] || store.default_currency
-
- all_products = store.products.not_archived
-
- products_matcher_cache_key = [
- 'products_matching_rules',
- cache_key_with_version,
- storefront,
- currency,
- all_products.cache_key_with_version
- ]
-
- all_products = all_products.active(currency: currency) if storefront
-
- any_rules_match_policy = rules_match_policy == 'any'
- products = any_rules_match_policy ? Spree::Product.none : all_products
-
- rules.each do |rule|
- if any_rules_match_policy
- product_ids = rule.apply(all_products).ids
- # it's safer to use this approach with ids as it will not break if the rule is not a simple where clause
- # and we will avoid `ArgumentError (Relation passed to #or must be structurally compatible. Incompatible values: [:group, :order, :joins, :readonly])` error
- products = products.or(all_products.where(id: product_ids)) if product_ids.any?
- else
- products = rule.apply(products)
- end
- end
-
- products
- end
-
- def slug
- permalink
- end
-
- def slug=(value)
- self.permalink = value
- end
-
- self::Translation.class_eval do
- before_save :set_permalink
- before_save :set_pretty_name
- after_save :regenerate_pretty_name_and_permalink, if: :should_regenerate_pretty_name_and_permalink?
-
- def slug
- permalink
- end
-
- def slug=(value)
- self.permalink = value
- end
-
- def set_permalink
- self.permalink = generate_slug
- end
-
- def set_pretty_name
- self.pretty_name = generate_pretty_name
- end
-
- def name_with_fallback
- name.blank? ? translated_model[:name] : name
- end
-
- def pretty_name_with_fallback
- pretty_name.blank? ? translated_model[:pretty_name] : pretty_name
- end
-
- def regenerate_pretty_name_and_permalink
- Spree::Taxon::Translation.where(spree_taxon_id: translated_model.cached_self_and_descendants_ids).each(&:update_pretty_name_and_permalink)
- end
-
- def update_pretty_name_and_permalink
- update_columns(pretty_name: generate_pretty_name, permalink: generate_slug, updated_at: Time.current)
- end
-
- private
-
- def generate_slug
- if parent.present?
- generate_permalink_including_parent
- elsif permalink.blank?
- name_with_fallback.to_url
- else
- permalink.to_url
- end
- end
-
- def generate_pretty_name
- if parent.present?
- generate_pretty_name_including_parent
- elsif pretty_name.blank?
- name_with_fallback
- else
- pretty_name
- end
- end
-
- def generate_permalink_including_parent
- [parent_permalink_with_fallback,
- (permalink.blank? ? name_with_fallback.to_url : permalink.split('/').last.to_url)].join('/')
- end
-
- def generate_pretty_name_including_parent
- [parent_pretty_name_with_fallback, (name.blank? ? name_with_fallback : name)].compact.join(' -> ')
- end
-
- def parent
- translated_model.parent
- end
-
- def parent_permalink_with_fallback
- localized_parent = parent.translations.find_by(locale: locale)
- localized_parent.present? ? localized_parent.permalink : parent[:permalink]
- end
-
- def parent_pretty_name_with_fallback
- localized_parent = parent.translations.find_by(locale: locale)
- localized_parent.present? ? localized_parent.pretty_name : parent[:pretty_name]
- end
-
- def should_regenerate_pretty_name_and_permalink?
- saved_changes.key?(:name) || saved_changes.key?(:permalink)
- end
- end
-
- # Return meta_title if set otherwise generates from taxon name
- def seo_title
- meta_title.blank? ? name : meta_title
- end
-
- def set_pretty_name
- self.pretty_name = generate_pretty_name
- end
-
- def generate_pretty_name
- [parent&.pretty_name, name].compact.join(' -> ')
- end
-
- def generate_slug
- if parent.present?
- [parent.permalink, (permalink.blank? ? name.to_url : permalink.split('/').last.to_url)].join('/')
- elsif permalink.blank?
- name.to_url
- else
- permalink.to_url
- end
- end
-
- def set_permalink
- if Spree.use_translations?
- translations.each(&:set_permalink)
- else
- self.permalink = generate_slug
- end
- end
-
- def regenerate_pretty_name_and_permalink
- Mobility.with_locale(nil) do
- update_columns(pretty_name: generate_pretty_name, permalink: generate_slug, updated_at: Time.current)
- end
-
- children.reload.each(&:regenerate_pretty_name_and_permalink_as_child)
- end
-
- def regenerate_pretty_name_and_permalink_as_child
- Mobility.with_locale(nil) do
- update_columns(pretty_name: generate_pretty_name, permalink: generate_slug, updated_at: Time.current)
- end
-
- children.reload.each(&:regenerate_pretty_name_and_permalink_as_child)
- end
-
- def cached_self_and_descendants_ids
- @cached_self_and_descendants_ids ||= Rails.cache.fetch("#{cache_key_with_version}/descendant-ids") do
- self_and_descendants.ids
- end
- end
-
- # awesome_nested_set sorts by :lft and :rgt. This call re-inserts the child
- # node so that its resulting position matches the observable 0-indexed position.
- # ** Note ** no :position column needed - a_n_s doesn't handle the reordering if
- # you bring your own :order_column.
- #
- # See #3390 for background.
- def child_index=(idx)
- move_to_child_with_index(parent, idx.to_i) unless new_record?
- end
-
- private
-
- def should_regenerate_pretty_name_and_permalink?
- saved_changes.key?(:name) || saved_changes.key?(:permalink)
- end
-
- def sync_taxonomy_name
- return unless taxonomy.present?
- return unless saved_changes.key?(:name) && root?
- return if taxonomy.name.to_s == name.to_s
-
- taxonomy.update(name: name)
- end
-
- def touch_ancestors_and_taxonomy
- # Touches all ancestors at once to avoid recursive taxonomy touch, and reduce queries.
- ancestors.update_all(updated_at: Time.current)
- # Have taxonomy touch happen in #touch_ancestors_and_taxonomy rather than association option in order for imports to override.
- taxonomy.touch if taxonomy.present?
- end
-
- def capture_parent_before_move
- @parent_id_before_move = parent_id_in_database
- end
-
- # Recompute the inclusive products_count for the moved node's new ancestor
- # chain and the previous parent's chain too (whose subtree just lost this
- # node's products).
- def recalculate_products_count_after_move
- affected = [id, @parent_id_before_move].compact
- @parent_id_before_move = nil
- self.class.recalculate_products_count(affected)
- end
-
- # Recomputes each ancestor's inclusive products_count as if this subtree were
- # already gone (its classifications are destroyed asynchronously, so they're
- # still present here). Excludes self_and_descendants from the count.
- def recalculate_ancestors_before_destroy
- doomed_ids = self_and_descendants.ids
- ancestors.each do |ancestor|
- remaining = Spree::Classification.
- where(category_id: ancestor.self_and_descendants.where.not(id: doomed_ids).select(:id)).
- distinct.count(:product_id)
- ancestor.update_column(:products_count, remaining) if ancestor.products_count != remaining
- end
- end
-
- def check_for_root
- return unless taxonomy.try(:root).present? && parent_id.nil?
-
- errors.add(:root_conflict, 'this taxonomy already has a root taxon')
- end
-
- def parent_belongs_to_same_taxonomy
- return unless parent.present? && parent.taxonomy_id != taxonomy_id
-
- errors.add(:parent, 'must belong to the same taxonomy')
- end
-
- def copy_taxonomy_from_parent
- self.taxonomy = parent.taxonomy if parent.present? && taxonomy.blank?
- end
-
- def set_store
- Spree::Deprecation.warn('Spree::Taxon#set_store is deprecated and will be removed in Spree 6.0. ensure_store instead.')
- ensure_store
- end
-
- # Every taxon is store-owned. Resolve the store from the taxonomy, then the
- # parent, finally the current store — so the direct column is always
- # populated for new records. Guards on the raw +store_id+ column rather than
- # +#store+, whose reader masks an unset column with the taxonomy fallback.
- def ensure_store
- return if store_id.present?
-
- self.store = taxonomy&.store || parent&.store || Spree::Store.current
- end
-
- def regenerate_translations_pretty_name_and_permalink
- translations.each(&:regenerate_pretty_name_and_permalink)
- end
- end
+ # Deprecation alias for Spree::Category, renamed from Spree::Taxon in 6.0.
+ # Retained for one release so existing code and extensions that reference
+ # Spree::Taxon keep working; the canonical class is Spree::Category. Removed
+ # in 6.1 (along with the spree_taxonomies table and the automatic-taxon columns).
+ #
+ # This is a true constant alias — the underlying class, table (spree_categories),
+ # prefix (ctg), and model_name are all Spree::Category. Only the constant differs.
+ Taxon = Category
end
diff --git a/spree/core/app/models/spree/taxon_rule.rb b/spree/core/app/models/spree/taxon_rule.rb
index 05f48ce2b3..f7228d585d 100644
--- a/spree/core/app/models/spree/taxon_rule.rb
+++ b/spree/core/app/models/spree/taxon_rule.rb
@@ -9,7 +9,9 @@ module Spree
does_not_contain
].freeze
- belongs_to :taxon, class_name: 'Spree::Taxon', inverse_of: :taxon_rules, touch: true
+ # Category no longer declares the has_many :taxon_rules inverse (categories are
+ # manual in 6.0), so this is a plain belongs_to. Data-only until 6.1.
+ belongs_to :taxon, class_name: 'Spree::Category', touch: true
validates :taxon, :type, :value, presence: true
validates :match_policy, inclusion: { in: MATCH_POLICIES }, presence: true
diff --git a/spree/core/app/models/spree/taxonomy.rb b/spree/core/app/models/spree/taxonomy.rb
index 076423d8c3..2b26b26e2d 100644
--- a/spree/core/app/models/spree/taxonomy.rb
+++ b/spree/core/app/models/spree/taxonomy.rb
@@ -1,4 +1,7 @@
module Spree
+ # @deprecated Taxonomy is retained in 6.0 only to back not-yet-migrated
+ # categories (the taxonomy_id fallback). Categories are now store-owned via
+ # store_id; Taxonomy and the spree_taxonomies table are dropped in 6.1.
class Taxonomy < Spree.base_class
has_prefix_id :txnmy # Spree-specific: taxonomy
@@ -15,8 +18,8 @@ module Spree
validates :name, presence: true, uniqueness: { case_sensitive: false, scope: :store_id }
validates :store, presence: true
- has_many :taxons, inverse_of: :taxonomy
- has_one :root, -> { where parent_id: nil }, class_name: 'Spree::Taxon', dependent: :destroy
+ has_many :taxons, class_name: 'Spree::Category', inverse_of: :taxonomy
+ has_one :root, -> { where parent_id: nil }, class_name: 'Spree::Category', dependent: :destroy
belongs_to :store, class_name: 'Spree::Store'
after_create :set_root
diff --git a/spree/core/app/presenters/spree/csv/order_line_item_presenter.rb b/spree/core/app/presenters/spree/csv/order_line_item_presenter.rb
index 3d2151df05..dba9c50716 100644
--- a/spree/core/app/presenters/spree/csv/order_line_item_presenter.rb
+++ b/spree/core/app/presenters/spree/csv/order_line_item_presenter.rb
@@ -97,11 +97,11 @@ module Spree
!line_item.product.digital?,
line_item.product.tax_category_id.present?,
line_item.product.try(:vendor_name),
- taxon_dict(line_item.product.main_taxon)[0],
- taxon_dict(line_item.product.main_taxon)[1],
- taxon_dict(line_item.product.main_taxon)[2],
- taxon_dict(line_item.product.main_taxon)[3],
- taxon_dict(line_item.product.main_taxon)[4],
+ taxon_dict(line_item.product.primary_category)[0],
+ taxon_dict(line_item.product.primary_category)[1],
+ taxon_dict(line_item.product.primary_category)[2],
+ taxon_dict(line_item.product.primary_category)[3],
+ taxon_dict(line_item.product.primary_category)[4],
index.zero? ? order.bill_address&.full_name : nil,
index.zero? ? order.bill_address&.address1 : nil,
index.zero? ? order.bill_address&.address2 : nil,
diff --git a/spree/core/app/presenters/spree/csv/product_variant_presenter.rb b/spree/core/app/presenters/spree/csv/product_variant_presenter.rb
index 46e4b0faa8..b7b5c119a9 100644
--- a/spree/core/app/presenters/spree/csv/product_variant_presenter.rb
+++ b/spree/core/app/presenters/spree/csv/product_variant_presenter.rb
@@ -10,7 +10,6 @@ module Spree
'slug',
'status',
'vendor_name',
- 'brand_name',
'description',
'meta_title',
'meta_description',
@@ -47,29 +46,29 @@ module Spree
'category3',
].freeze
- def initialize(product, variant, index = 0, properties = [], taxons = [], store = nil, metafields = [], currency = nil)
+ def initialize(product, variant, index = 0, properties = [], categories = [], store = nil, metafields = [], currency = nil)
@product = product
@variant = variant
@index = index
@properties = properties
- @taxons = taxons
+ @categories = categories
@store = store || product.store
@currency = currency || @store.default_currency
@price_only = @currency != @store.default_currency
@metafields = metafields
end
- attr_accessor :product, :variant, :index, :properties, :taxons, :store, :currency, :price_only, :metafields
+ attr_accessor :product, :variant, :index, :properties, :categories, :store, :currency, :price_only, :metafields
##
# Generates an array representing a CSV row of product variant data.
#
# For the primary variant row (when the index is zero), product-level details such as name,
- # slug, status, vendor and brand names, description, meta tags, and tag/label lists are included.
+ # slug, status, vendor name, description, meta tags, and tag/label lists are included.
# In all cases, variant-specific attributes (e.g., id, SKU, pricing, dimensions, weight,
# availability dates, inventory count, shipping category, tax category, image URLs via original_url,
# and the first three option types and corresponding option values) are appended.
- # Additionally, when the index is zero, associated taxons and properties are added.
+ # Additionally, when the index is zero, associated categories and properties are added.
#
# @return [Array] An array containing the combined product and variant CSV data.
def call
@@ -84,7 +83,6 @@ module Spree
product.slug,
index.zero? ? product.status : nil,
index.zero? ? product.try(:vendor_name) : nil,
- index.zero? ? product.try(:brand_name) : nil,
index.zero? ? product.description&.html_safe : nil,
index.zero? ? product.meta_title : nil,
index.zero? ? product.meta_description : nil,
@@ -119,7 +117,7 @@ module Spree
]
if index.zero?
- csv += taxons
+ csv += categories
csv += properties
csv += metafields
end
diff --git a/spree/core/app/services/spree/categories/add_products.rb b/spree/core/app/services/spree/categories/add_products.rb
new file mode 100644
index 0000000000..941801e131
--- /dev/null
+++ b/spree/core/app/services/spree/categories/add_products.rb
@@ -0,0 +1,51 @@
+module Spree
+ module Categories
+ class AddProducts
+ prepend Spree::ServiceModule::Base
+
+ # Creates product-category links for the given categories and products in bulk.
+ #
+ # @param categories [Array<Spree::Category>]
+ # @param products [Array<Spree::Product>]
+ # @return [Spree::ServiceModule::Base::Result]
+ def call(categories:, products:)
+ return if categories.blank? || products.blank?
+
+ # build the params for the insert_all
+ product_categories_params = categories.pluck(:id).flat_map do |category_id|
+ position = Spree::ProductCategory.where(category_id: category_id).count
+
+ products.pluck(:id).map do |product_id|
+ {
+ category_id: category_id,
+ product_id: product_id,
+ position: (position += 1),
+ created_at: Time.current,
+ updated_at: Time.current
+ }
+ end
+ end
+ # doing a quick insert_all here to avoid the overhead of instantiating
+ Spree::ProductCategory.insert_all(product_categories_params)
+
+ # update counter caches
+ category_ids = categories.pluck(:id)
+ product_ids = products.pluck(:id)
+ product_ids.each { |id| Spree::Product.reset_counters(id, :product_categories) }
+ # Recompute the descendant-inclusive products_count for the categories and
+ # their ancestors (bulk insert skips ProductCategory callbacks).
+ Spree::Category.recalculate_products_count(category_ids)
+
+ # clear cache & index products
+ Spree::Product.where(id: product_ids).touch_all
+ products.each(&:enqueue_search_index)
+
+ Spree::Category.where(id: category_ids).touch_all
+ # Optional external hook (e.g. storefront featured sections); namespace owned by that gem.
+ Spree::Taxons::TouchFeaturedSections.call(taxon_ids: category_ids) if defined?(Spree::Taxons::TouchFeaturedSections)
+
+ success(true)
+ end
+ end
+ end
+end
diff --git a/spree/core/app/services/spree/taxons/remove_products.rb b/spree/core/app/services/spree/categories/remove_products.rb
similarity index 50%
rename from spree/core/app/services/spree/taxons/remove_products.rb
rename to spree/core/app/services/spree/categories/remove_products.rb
index af03fbbb24..02ed6e3639 100644
--- a/spree/core/app/services/spree/taxons/remove_products.rb
+++ b/spree/core/app/services/spree/categories/remove_products.rb
@@ -1,31 +1,31 @@
module Spree
- module Taxons
+ module Categories
class RemoveProducts
prepend Spree::ServiceModule::Base
- # Removes the given products from the given taxons.
+ # Removes the given products from the given categories.
#
- # @param taxons [Array<Spree::Taxon>]
+ # @param categories [Array<Spree::Category>]
# @param products [Array<Spree::Product>]
# @return [Spree::ServiceModule::Base::Result]
- def call(taxons:, products:)
- return if taxons.blank? || products.blank?
+ def call(categories:, products:)
+ return if categories.blank? || products.blank?
- taxon_ids = taxons.pluck(:id)
+ category_ids = categories.pluck(:id)
product_ids = products.pluck(:id)
ApplicationRecord.transaction do
- taxon_ids.each do |taxon_id|
- Spree::Classification.where(category_id: taxon_id, product_id: product_ids).delete_all
+ category_ids.each do |category_id|
+ Spree::ProductCategory.where(category_id: category_id, product_id: product_ids).delete_all
end
- classifications_params = taxon_ids.flat_map do |taxon_id|
+ product_categories_params = category_ids.flat_map do |category_id|
position = 0
- existing_product_ids = Spree::Classification.where(category_id: taxon_id).pluck(:product_id)
+ existing_product_ids = Spree::ProductCategory.where(category_id: category_id).pluck(:product_id)
existing_product_ids.map do |product_id|
{
- category_id: taxon_id,
+ category_id: category_id,
product_id: product_id,
position: (position += 1),
created_at: Time.current,
@@ -34,29 +34,30 @@ module Spree
end
end
- if classifications_params.any?
+ if product_categories_params.any?
opts = {}
opts[:unique_by] = %i[product_id category_id] unless mysql_adapter?
- Spree::Classification.upsert_all(
- classifications_params,
+ Spree::ProductCategory.upsert_all(
+ product_categories_params,
**opts
)
end
end
# update counter caches
- product_ids.each { |id| Spree::Product.reset_counters(id, :classifications) }
- # Recompute the descendant-inclusive products_count for the taxons and
- # their ancestors (delete_all skips Classification callbacks).
- Spree::Taxon.recalculate_products_count(taxon_ids)
+ product_ids.each { |id| Spree::Product.reset_counters(id, :product_categories) }
+ # Recompute the descendant-inclusive products_count for the categories and
+ # their ancestors (delete_all skips ProductCategory callbacks).
+ Spree::Category.recalculate_products_count(category_ids)
# clear cache & index products
Spree::Product.where(id: product_ids).touch_all
products.each(&:enqueue_search_index)
- Spree::Taxon.where(id: taxon_ids).touch_all
- Spree::Taxons::TouchFeaturedSections.call(taxon_ids: taxon_ids) if defined?(Spree::Taxons::TouchFeaturedSections)
+ Spree::Category.where(id: category_ids).touch_all
+ # Optional external hook (e.g. storefront featured sections); namespace owned by that gem.
+ Spree::Taxons::TouchFeaturedSections.call(taxon_ids: category_ids) if defined?(Spree::Taxons::TouchFeaturedSections)
success(true)
end
diff --git a/spree/core/app/services/spree/taxons/add_products.rb b/spree/core/app/services/spree/taxons/add_products.rb
deleted file mode 100644
index dce3c21386..0000000000
--- a/spree/core/app/services/spree/taxons/add_products.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-module Spree
- module Taxons
- class AddProducts
- prepend Spree::ServiceModule::Base
-
- # Creates classifications for the given taxons and products in bulk.
- #
- # @param taxons [Array<Spree::Taxon>]
- # @param products [Array<Spree::Product>]
- # @return [Spree::ServiceModule::Base::Result]
- def call(taxons:, products:)
- return if taxons.blank? || products.blank?
-
- # build the params for the insert_all
- classifications_params = taxons.pluck(:id).flat_map do |taxon_id|
- position = Spree::Classification.where(category_id: taxon_id).count
-
- products.pluck(:id).map do |product_id|
- {
- category_id: taxon_id,
- product_id: product_id,
- position: (position += 1),
- created_at: Time.current,
- updated_at: Time.current
- }
- end
- end
- # doing a quick insert_all here to avoid the overhead of instantiating
- Spree::Classification.insert_all(classifications_params)
-
- # update counter caches
- taxon_ids = taxons.pluck(:id)
- product_ids = products.pluck(:id)
- product_ids.each { |id| Spree::Product.reset_counters(id, :classifications) }
- # Recompute the descendant-inclusive products_count for the taxons and
- # their ancestors (bulk insert skips Classification callbacks).
- Spree::Taxon.recalculate_products_count(taxon_ids)
-
- # clear cache & index products
- Spree::Product.where(id: product_ids).touch_all
- products.each(&:enqueue_search_index)
-
- Spree::Taxon.where(id: taxon_ids).touch_all
- Spree::Taxons::TouchFeaturedSections.call(taxon_ids: taxon_ids) if defined?(Spree::Taxons::TouchFeaturedSections)
-
- success(true)
- end
- end
- end
-end
diff --git a/spree/core/app/sorters/spree/classifications/sort.rb b/spree/core/app/sorters/spree/classifications/sort.rb
index ed9a9a73e0..fba1092d38 100644
--- a/spree/core/app/sorters/spree/classifications/sort.rb
+++ b/spree/core/app/sorters/spree/classifications/sort.rb
@@ -53,11 +53,11 @@ module Spree
return scope unless (value = sort_by?('price'))
scope.joins(product: { variants_including_master: :prices }).
- select("#{Spree::Classification.table_name}.*, min(#{Spree::Price.table_name}.amount)").
+ select("#{Spree::ProductCategory.table_name}.*, min(#{Spree::Price.table_name}.amount)").
distinct.
where(spree_prices: { currency: currency }).
order("min(#{Spree::Price.table_name}.amount) #{value[1]}").
- group("#{Spree::Classification.table_name}.id")
+ group("#{Spree::ProductCategory.table_name}.id")
end
def sort_by?(field)
diff --git a/spree/core/db/migrate/20260710000001_rename_taxons_to_categories.rb b/spree/core/db/migrate/20260710000001_rename_taxons_to_categories.rb
index 40f5dcb2a2..d47cfd4a5b 100644
--- a/spree/core/db/migrate/20260710000001_rename_taxons_to_categories.rb
+++ b/spree/core/db/migrate/20260710000001_rename_taxons_to_categories.rb
@@ -4,6 +4,16 @@ class RenameTaxonsToCategories < ActiveRecord::Migration[7.2]
rename_table :spree_products_taxons, :spree_product_categories
rename_column :spree_product_categories, :taxon_id, :category_id
+ # Promotion↔category join (Spree::PromotionRuleCategory) and the Mobility
+ # translations table follow the same rename now, so no class needs a
+ # table_name/foreign_key pin. (spree_taxon_rules + spree_prototype_taxons keep
+ # taxon_id: the former is dropped in 6.1, the latter renamed by 6.0-product-types.)
+ rename_table :spree_promotion_rule_taxons, :spree_promotion_rule_categories
+ rename_column :spree_promotion_rule_categories, :taxon_id, :category_id
+
+ rename_table :spree_taxon_translations, :spree_category_translations
+ rename_column :spree_category_translations, :spree_taxon_id, :spree_category_id
+
# store_id already exists on spree_taxons (shipped 5.6) and carries over on the
# rename — do NOT re-add it. Backfill first:
# bundle exec rake spree:taxons:backfill_store_id
diff --git a/spree/core/lib/spree/core.rb b/spree/core/lib/spree/core.rb
index f632d4bc24..feef1201e0 100644
--- a/spree/core/lib/spree/core.rb
+++ b/spree/core/lib/spree/core.rb
@@ -103,7 +103,7 @@ module Spree
products: :default,
reports: :default,
variants: :default,
- taxons: :default,
+ categories: :default,
collections: :default,
stock_location_stock_items: :default,
coupon_codes: :default,
diff --git a/spree/core/lib/spree/core/engine.rb b/spree/core/lib/spree/core/engine.rb
index e3bcdb69f0..12392a67ba 100644
--- a/spree/core/lib/spree/core/engine.rb
+++ b/spree/core/lib/spree/core/engine.rb
@@ -190,7 +190,7 @@ module Spree
Spree::Promotion::Rules::FirstOrder,
Spree::Promotion::Rules::UserLoggedIn,
Spree::Promotion::Rules::OneUsePerUser,
- Spree::Promotion::Rules::Taxon,
+ Spree::Promotion::Rules::Category,
Spree::Promotion::Rules::OptionValue,
]
@@ -267,7 +267,7 @@ module Spree
Spree::OptionValue,
Spree::Product,
Spree::Collection,
- Spree::Taxon,
+ Spree::Category,
Spree::Taxonomy,
Spree::Store,
Spree::Policy
@@ -320,7 +320,7 @@ module Spree
Spree::Store,
Spree::StoreCredit,
Spree::TaxRate,
- Spree::Taxon,
+ Spree::Category,
Spree::Taxonomy,
Spree::Variant,
Spree.user_class
diff --git a/spree/core/lib/spree/testing_support/factories/classification_factory.rb b/spree/core/lib/spree/testing_support/factories/classification_factory.rb
index 523c5a05b2..ce83fb9127 100644
--- a/spree/core/lib/spree/testing_support/factories/classification_factory.rb
+++ b/spree/core/lib/spree/testing_support/factories/classification_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :classification, class: Spree::Classification do
+ factory :classification, class: Spree::ProductCategory do
product
taxon
diff --git a/spree/core/lib/spree/testing_support/factories/promotion_rule_factory.rb b/spree/core/lib/spree/testing_support/factories/promotion_rule_factory.rb
index be758f3baf..bd4179ec46 100644
--- a/spree/core/lib/spree/testing_support/factories/promotion_rule_factory.rb
+++ b/spree/core/lib/spree/testing_support/factories/promotion_rule_factory.rb
@@ -11,7 +11,7 @@ FactoryBot.define do
association :promotion
end
- factory :promotion_rule_taxon, class: Spree::Promotion::Rules::Taxon do
+ factory :promotion_rule_taxon, class: Spree::Promotion::Rules::Category do
association :promotion
end
diff --git a/spree/core/lib/spree/testing_support/factories/taxon_factory.rb b/spree/core/lib/spree/testing_support/factories/taxon_factory.rb
index b5ff5720c0..2b1e1dac04 100644
--- a/spree/core/lib/spree/testing_support/factories/taxon_factory.rb
+++ b/spree/core/lib/spree/testing_support/factories/taxon_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :taxon, class: Spree::Taxon do
+ factory :taxon, class: Spree::Category, aliases: [:category] do
sequence(:name) { |n| "taxon_#{n}" }
association :taxonomy, strategy: :create
diff --git a/spree/core/lib/spree/translations.rb b/spree/core/lib/spree/translations.rb
index 9ff1d9de28..e8ca365af7 100644
--- a/spree/core/lib/spree/translations.rb
+++ b/spree/core/lib/spree/translations.rb
@@ -51,7 +51,7 @@ module Spree
#
# @return [String]
def public_resource_type(klass)
- return 'category' if klass <= Spree::Taxon
+ return 'category' if klass <= Spree::Category
resource_type(klass)
end
diff --git a/spree/core/lib/tasks/products.rake b/spree/core/lib/tasks/products.rake
index 2a6f708b57..a0b43108f3 100644
--- a/spree/core/lib/tasks/products.rake
+++ b/spree/core/lib/tasks/products.rake
@@ -9,7 +9,7 @@ namespace :spree do
product.update_columns(
variant_count: product.variants.count,
- categories_count: product.classifications.count,
+ categories_count: product.product_categories.count,
media_count: total_media,
updated_at: Time.current
)
diff --git a/spree/core/lib/tasks/taxons.rake b/spree/core/lib/tasks/taxons.rake
index b838443525..de53d454c8 100644
--- a/spree/core/lib/tasks/taxons.rake
+++ b/spree/core/lib/tasks/taxons.rake
@@ -11,14 +11,14 @@ namespace :spree do
# of scope in the SET and raising PG::UndefinedTable ("missing FROM-clause
# entry"). It fails at parse time, even when no rows need changing.
Spree::Taxonomy.where.not(store_id: nil).find_each do |taxonomy|
- Spree::Taxon.unscoped.where(store_id: nil, taxonomy_id: taxonomy.id).
+ Spree::Category.unscoped.where(store_id: nil, taxonomy_id: taxonomy.id).
in_batches(of: 1000).update_all(store_id: taxonomy.store_id)
print '.'
end
puts "\nResolving taxonomy-less taxons through the parent chain..."
- # Mirror Spree::Taxon#ensure_store: taxonomy-less rows inherit their parent's
+ # Mirror Spree::Category#ensure_store: taxonomy-less rows inherit their parent's
# store. Loop so a chain of unbackfilled ancestors resolves top-down — each
# pass pushes an already-resolved parent's store onto its children.
loop do
@@ -26,11 +26,11 @@ namespace :spree do
# Resolved parents that still have children missing a store form the
# frontier; push each store down in one UPDATE per (store, id batch).
- frontier = Spree::Taxon.unscoped.where.not(store_id: nil).
- where(id: Spree::Taxon.unscoped.where(store_id: nil).select(:parent_id))
+ frontier = Spree::Category.unscoped.where.not(store_id: nil).
+ where(id: Spree::Category.unscoped.where(store_id: nil).select(:parent_id))
frontier.pluck(:id, :store_id).group_by(&:last).each do |store_id, rows|
rows.map(&:first).each_slice(1000) do |parent_ids|
- updated += Spree::Taxon.unscoped.where(store_id: nil, parent_id: parent_ids).
+ updated += Spree::Category.unscoped.where(store_id: nil, parent_id: parent_ids).
update_all(store_id: store_id)
end
end
@@ -45,8 +45,8 @@ namespace :spree do
# Recomputes the descendant-inclusive products_count for every taxon, in
# batches. Shared by the dedicated task and reset_counter_caches.
backfill_products_count = lambda do
- Spree::Taxon.unscoped.in_batches(of: 1000) do |batch|
- Spree::Taxon.recalculate_products_count(batch.pluck(:id))
+ Spree::Category.unscoped.in_batches(of: 1000) do |batch|
+ Spree::Category.recalculate_products_count(batch.pluck(:id))
print '.'
end
end
@@ -62,7 +62,7 @@ namespace :spree do
task reset_counter_caches: :environment do |_t, _args|
puts 'Resetting taxon counter caches...'
- Spree::Taxon.find_each do |taxon|
+ Spree::Category.find_each do |taxon|
taxon.update_columns(
children_count: taxon.children.count,
updated_at: Time.current
diff --git a/spree/core/spec/finders/spree/products/find_spec.rb b/spree/core/spec/finders/spree/products/find_spec.rb
index 79efea1f3b..f5050cac5b 100644
--- a/spree/core/spec/finders/spree/products/find_spec.rb
+++ b/spree/core/spec/finders/spree/products/find_spec.rb
@@ -404,9 +404,9 @@ module Spree
product_3.taxons << child_taxon_2
# swap products positions
- product.classifications.find_by(taxon: child_taxon_1).update(position: 3)
- product_3.classifications.find_by(taxon: child_taxon_2).update(position: 2)
- product_2.classifications.find_by(taxon: child_taxon_1).update(position: 1)
+ product.classifications.find_by(category: child_taxon_1).update(position: 3)
+ product_3.classifications.find_by(category: child_taxon_2).update(position: 2)
+ product_2.classifications.find_by(category: child_taxon_1).update(position: 1)
end
it 'returns products ordered by associated taxon position' do
diff --git a/spree/core/spec/finders/spree/taxons/find_spec.rb b/spree/core/spec/finders/spree/taxons/find_spec.rb
index 077b04af3d..69bd1df662 100644
--- a/spree/core/spec/finders/spree/taxons/find_spec.rb
+++ b/spree/core/spec/finders/spree/taxons/find_spec.rb
@@ -9,7 +9,7 @@ module Spree
describe 'filtering by taxon property' do
subject do
described_class.new(
- scope: Spree::Taxon.all,
+ scope: Spree::Category.all,
params: params
).execute
end
diff --git a/spree/core/spec/jobs/spree/imports/create_categories_job_spec.rb b/spree/core/spec/jobs/spree/imports/create_categories_job_spec.rb
index ced0ab3bd7..856ccbe91c 100644
--- a/spree/core/spec/jobs/spree/imports/create_categories_job_spec.rb
+++ b/spree/core/spec/jobs/spree/imports/create_categories_job_spec.rb
@@ -45,7 +45,7 @@ RSpec.describe Spree::Imports::CreateCategoriesJob, type: :job do
it 'reuses existing taxonomies and taxons' do
expect {
described_class.perform_now(product.id, store.id, ['Men -> Clothing -> Shirts'])
- }.not_to change { Spree::Taxon.count }
+ }.not_to change { Spree::Category.count }
expect(product.reload.taxons.map(&:pretty_name)).to contain_exactly(
'Men -> Clothing -> Shirts'
diff --git a/spree/core/spec/jobs/spree/products/touch_categories_job_spec.rb b/spree/core/spec/jobs/spree/products/touch_categories_job_spec.rb
new file mode 100644
index 0000000000..ee19bb3d4e
--- /dev/null
+++ b/spree/core/spec/jobs/spree/products/touch_categories_job_spec.rb
@@ -0,0 +1,27 @@
+require 'spec_helper'
+
+describe Spree::Products::TouchCategoriesJob, type: :job do
+ describe '#perform' do
+ subject { described_class.perform_now(category_ids, taxonomy_ids) }
+
+ let!(:taxonomy) { create(:taxonomy) }
+ let!(:category_1) { create(:taxon, taxonomy: taxonomy) }
+ let!(:category_2) { create(:taxon, taxonomy: taxonomy) }
+ let!(:other_category) { create(:taxon) }
+
+ let(:category_ids) { [category_1.id, category_2.id] }
+ let(:taxonomy_ids) { [taxonomy.id] }
+
+ it 'touches all specified categories' do
+ expect { subject }.to change { Spree::Category.where(id: category_ids).pluck(:updated_at) }
+ end
+
+ it 'touches all specified taxonomies' do
+ expect { subject }.to change { Spree::Taxonomy.where(id: taxonomy_ids).pluck(:updated_at) }
+ end
+
+ it 'does not touch other categories' do
+ expect { subject }.not_to change { other_category.reload.updated_at }
+ end
+ end
+end
diff --git a/spree/core/spec/jobs/spree/products/touch_taxons_job_spec.rb b/spree/core/spec/jobs/spree/products/touch_taxons_job_spec.rb
deleted file mode 100644
index 69f01f6125..0000000000
--- a/spree/core/spec/jobs/spree/products/touch_taxons_job_spec.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-require 'spec_helper'
-
-describe Spree::Products::TouchTaxonsJob, type: :job do
- describe '#perform' do
- subject { described_class.perform_now(taxon_ids, taxonomy_ids) }
-
- let!(:taxonomy) { create(:taxonomy) }
- let!(:taxon_1) { create(:taxon, taxonomy: taxonomy) }
- let!(:taxon_2) { create(:taxon, taxonomy: taxonomy) }
- let!(:other_taxon) { create(:taxon) }
-
- let(:taxon_ids) { [taxon_1.id, taxon_2.id] }
- let(:taxonomy_ids) { [taxonomy.id] }
-
- it 'touches all specified taxons' do
- expect { subject }.to change { Spree::Taxon.where(id: taxon_ids).pluck(:updated_at) }
- end
-
- it 'touches all specified taxonomies' do
- expect { subject }.to change { Spree::Taxonomy.where(id: taxonomy_ids).pluck(:updated_at) }
- end
-
- it 'does not touch other taxons' do
- expect { subject }.not_to change { other_taxon.reload.updated_at }
- end
- end
-end
diff --git a/spree/core/spec/models/spree/ability_spec.rb b/spree/core/spec/models/spree/ability_spec.rb
index dba8921d35..8be4872c83 100644
--- a/spree/core/spec/models/spree/ability_spec.rb
+++ b/spree/core/spec/models/spree/ability_spec.rb
@@ -174,7 +174,7 @@ describe Spree::Ability, type: :model do
end
context 'for Taxons' do
- let(:resource) { Spree::Taxon.new }
+ let(:resource) { Spree::Category.new }
context 'requested by any user' do
it_behaves_like 'read only'
diff --git a/spree/core/spec/models/spree/category_spec.rb b/spree/core/spec/models/spree/category_spec.rb
index 318890e48a..a17e7cb844 100644
--- a/spree/core/spec/models/spree/category_spec.rb
+++ b/spree/core/spec/models/spree/category_spec.rb
@@ -24,7 +24,7 @@ RSpec.describe Spree::Category, type: :model do
it 'decrements ancestors when a subcategory is destroyed' do
parent = described_class.create!(name: 'Electronics', store: store)
child = described_class.create!(name: 'Phones', parent: parent)
- Spree::Classification.create!(taxon: child, product: create(:product, stores: [store]))
+ Spree::ProductCategory.create!(taxon: child, product: create(:product, stores: [store]))
expect(parent.reload.products_count).to eq(1)
child.destroy
@@ -36,8 +36,8 @@ RSpec.describe Spree::Category, type: :model do
parent = described_class.create!(name: 'Electronics', store: store)
phones = described_class.create!(name: 'Phones', parent: parent)
laptops = described_class.create!(name: 'Laptops', parent: parent)
- Spree::Classification.create!(taxon: phones, product: create(:product, stores: [store]))
- Spree::Classification.create!(taxon: laptops, product: create(:product, stores: [store]))
+ Spree::ProductCategory.create!(taxon: phones, product: create(:product, stores: [store]))
+ Spree::ProductCategory.create!(taxon: laptops, product: create(:product, stores: [store]))
expect(parent.reload.products_count).to eq(2)
phones.destroy
@@ -49,7 +49,7 @@ RSpec.describe Spree::Category, type: :model do
root = described_class.create!(name: 'Root', store: store)
mid = described_class.create!(name: 'Mid', parent: root)
leaf = described_class.create!(name: 'Leaf', parent: mid)
- Spree::Classification.create!(taxon: leaf, product: create(:product, stores: [store]))
+ Spree::ProductCategory.create!(taxon: leaf, product: create(:product, stores: [store]))
expect(root.reload.products_count).to eq(1)
mid.destroy # removes the mid + leaf subtree
@@ -62,8 +62,8 @@ RSpec.describe Spree::Category, type: :model do
a = described_class.create!(name: 'A', parent: root)
b = described_class.create!(name: 'B', parent: root)
product = create(:product, stores: [store])
- Spree::Classification.create!(taxon: a, product: product)
- Spree::Classification.create!(taxon: b, product: product)
+ Spree::ProductCategory.create!(taxon: a, product: product)
+ Spree::ProductCategory.create!(taxon: b, product: product)
expect(root.reload.products_count).to eq(1)
a.destroy
@@ -163,7 +163,7 @@ RSpec.describe Spree::Category, type: :model do
let(:laptops) { described_class.create!(name: 'Laptops', parent: electronics) }
def add(product, category)
- Spree::Taxons::AddProducts.call(taxons: [category], products: [product])
+ Spree::Categories::AddProducts.call(categories: [category], products: [product])
end
it 'counts a directly-assigned product on the category' do
@@ -196,7 +196,7 @@ RSpec.describe Spree::Category, type: :model do
add(product, phones)
expect(electronics.reload.products_count).to eq(1)
- Spree::Taxons::RemoveProducts.call(taxons: [phones], products: [product])
+ Spree::Categories::RemoveProducts.call(categories: [phones], products: [product])
expect(electronics.reload.products_count).to eq(0)
expect(phones.reload.products_count).to eq(0)
@@ -204,7 +204,7 @@ RSpec.describe Spree::Category, type: :model do
it 'maintains the count on a direct Classification create/destroy' do
product = create(:product, stores: [store])
- classification = Spree::Classification.create!(taxon: phones, product: product)
+ classification = Spree::ProductCategory.create!(taxon: phones, product: product)
expect(electronics.reload.products_count).to eq(1)
classification.destroy
diff --git a/spree/core/spec/models/spree/classification_spec.rb b/spree/core/spec/models/spree/classification_spec.rb
index 2f8d0d9727..6730da696f 100644
--- a/spree/core/spec/models/spree/classification_spec.rb
+++ b/spree/core/spec/models/spree/classification_spec.rb
@@ -28,7 +28,7 @@ module Spree
it 'has a valid fixtures' do
expect positions_to_be_valid(taxon_with_5_products)
- expect(Spree::Classification.count).to eq 5
+ expect(Spree::ProductCategory.count).to eq 5
end
context 'removing product from taxon' do
@@ -142,7 +142,7 @@ module Spree
end
end
- describe '.grouped_taxon_ids_for_products' do
+ describe '.grouped_category_ids_for_products' do
let(:taxon1) { create(:taxon) }
let(:taxon2) { create(:taxon) }
let(:taxon3) { create(:taxon) }
@@ -156,14 +156,14 @@ module Spree
let(:taxon_groups) { [taxon1.id, taxon2.id, taxon3.id] }
it 'returns the correct taxon ids' do
- expect(described_class.grouped_taxon_ids_for_products(product_ids, taxon_groups)).to eq(expected_result)
+ expect(described_class.grouped_category_ids_for_products(product_ids, taxon_groups)).to eq(expected_result)
end
context 'when empty taxon groups' do
let(:taxon_groups) { [] }
it 'returns an empty array' do
- expect(described_class.grouped_taxon_ids_for_products(product_ids, taxon_groups)).to eq([])
+ expect(described_class.grouped_category_ids_for_products(product_ids, taxon_groups)).to eq([])
end
end
@@ -171,7 +171,7 @@ module Spree
let(:product_ids) { [] }
it 'returns an empty array' do
- expect(described_class.grouped_taxon_ids_for_products(product_ids, taxon_groups)).to eq([])
+ expect(described_class.grouped_category_ids_for_products(product_ids, taxon_groups)).to eq([])
end
end
end
diff --git a/spree/core/spec/models/spree/concerns/ransackable_attributes_spec.rb b/spree/core/spec/models/spree/concerns/ransackable_attributes_spec.rb
index eb1204b2d0..d259bc4f5e 100644
--- a/spree/core/spec/models/spree/concerns/ransackable_attributes_spec.rb
+++ b/spree/core/spec/models/spree/concerns/ransackable_attributes_spec.rb
@@ -29,7 +29,7 @@ RSpec.describe Spree::RansackableAttributes do
describe '.ransackable_associations' do
it 'returns whitelisted associations' do
- expect(Spree::Product.ransackable_associations).to include('taxons', 'variants')
+ expect(Spree::Product.ransackable_associations).to include('categories', 'variants')
end
it 'merges custom associations from Spree.ransack' do
diff --git a/spree/core/spec/models/spree/exports/products_spec.rb b/spree/core/spec/models/spree/exports/products_spec.rb
index cd805f0c7a..f134a63b8b 100644
--- a/spree/core/spec/models/spree/exports/products_spec.rb
+++ b/spree/core/spec/models/spree/exports/products_spec.rb
@@ -35,7 +35,6 @@ RSpec.describe Spree::Exports::Products, type: :model do
'slug',
'status',
'vendor_name',
- 'brand_name',
'description',
'meta_title',
'meta_description',
@@ -86,7 +85,6 @@ RSpec.describe Spree::Exports::Products, type: :model do
'slug',
'status',
'vendor_name',
- 'brand_name',
'description',
'meta_title',
'meta_description',
diff --git a/spree/core/spec/models/spree/permission_sets/default_customer_spec.rb b/spree/core/spec/models/spree/permission_sets/default_customer_spec.rb
index b6e52d6d2c..f67f404408 100644
--- a/spree/core/spec/models/spree/permission_sets/default_customer_spec.rb
+++ b/spree/core/spec/models/spree/permission_sets/default_customer_spec.rb
@@ -24,7 +24,7 @@ RSpec.describe Spree::PermissionSets::DefaultCustomer do
end
it 'grants read access to Taxon' do
- expect(ability.can?(:read, Spree::Taxon)).to be true
+ expect(ability.can?(:read, Spree::Category)).to be true
end
it 'grants read access to Store' do
diff --git a/spree/core/spec/models/spree/permission_sets/product_management_spec.rb b/spree/core/spec/models/spree/permission_sets/product_management_spec.rb
index 8535d9cb4e..0f63a38764 100644
--- a/spree/core/spec/models/spree/permission_sets/product_management_spec.rb
+++ b/spree/core/spec/models/spree/permission_sets/product_management_spec.rb
@@ -27,7 +27,7 @@ RSpec.describe Spree::PermissionSets::ProductManagement do
end
it 'grants manage access to Taxon' do
- expect(ability.can?(:manage, Spree::Taxon)).to be true
+ expect(ability.can?(:manage, Spree::Category)).to be true
end
it 'grants manage access to Taxonomy' do
@@ -35,7 +35,7 @@ RSpec.describe Spree::PermissionSets::ProductManagement do
end
it 'grants manage access to Classification' do
- expect(ability.can?(:manage, Spree::Classification)).to be true
+ expect(ability.can?(:manage, Spree::ProductCategory)).to be true
end
it 'grants manage access to Price' do
diff --git a/spree/core/spec/models/spree/product/scopes_spec.rb b/spree/core/spec/models/spree/product/scopes_spec.rb
index 41538b1679..1847bb938e 100644
--- a/spree/core/spec/models/spree/product/scopes_spec.rb
+++ b/spree/core/spec/models/spree/product/scopes_spec.rb
@@ -38,28 +38,6 @@ describe 'Product scopes', type: :model do
end
end
- describe '.for_filters' do
- subject { Spree::Product.method(:for_filters) }
-
- let(:taxon_1) { create(:taxon) }
- let(:taxon_2) { create(:taxon) }
-
- let!(:product_1) { create(:product, currency: 'GBP', taxons: [taxon_1]) }
- let!(:product_2) { create(:product, currency: 'GBP', taxons: [taxon_2]) }
-
- before do
- create(:product, currency: 'USD', taxons: [create(:taxon)])
- end
-
- context 'when giving a taxon' do
- it { expect(subject.call('GBP', taxon: taxon_1)).to contain_exactly(product_1) }
- end
-
- context 'when giving a currency with no products' do
- it { expect(subject.call('PLN')).to be_empty }
- end
- end
-
context 'A product assigned to parent and child taxons' do
before do
@taxonomy = create(:taxonomy)
diff --git a/spree/core/spec/models/spree/product_spec.rb b/spree/core/spec/models/spree/product_spec.rb
index ad4add8826..9cc7eb7533 100644
--- a/spree/core/spec/models/spree/product_spec.rb
+++ b/spree/core/spec/models/spree/product_spec.rb
@@ -547,14 +547,14 @@ describe Spree::Product, type: :model do
end
# Regression tests for #2352
- context 'classifications and taxons' do
- it 'is joined through classifications' do
- reflection = Spree::Product.reflect_on_association(:taxons)
- expect(reflection.options[:through]).to eq(:classifications)
+ context 'product_categories and categories' do
+ it 'is joined through product_categories' do
+ reflection = Spree::Product.reflect_on_association(:categories)
+ expect(reflection.options[:through]).to eq(:product_categories)
end
- it 'will delete all classifications' do
- reflection = Spree::Product.reflect_on_association(:classifications)
+ it 'will delete all product_categories' do
+ reflection = Spree::Product.reflect_on_association(:product_categories)
expect(reflection.options[:dependent]).to eq(:delete_all)
end
end
@@ -634,24 +634,6 @@ describe Spree::Product, type: :model do
end
end
- describe '#brand_taxon' do
- let(:taxonomy) { store.taxonomies.find_by(name: Spree.t(:taxonomy_brands_name)) || create(:taxonomy, name: Spree.t(:taxonomy_brands_name), store: store) }
- let(:product) { create(:product, taxons: [taxonomy.taxons.first]) }
-
- it 'fetches Brand Taxon' do
- expect(product.brand_taxon).to eql(taxonomy.taxons.first)
- end
- end
-
- describe '#brand_name' do
- let(:taxonomy) { store.taxonomies.find_by(name: Spree.t(:taxonomy_brands_name)) || create(:taxonomy, name: Spree.t(:taxonomy_brands_name), store: store) }
- let(:product) { create(:product, taxons: [taxonomy.taxons.first]) }
-
- it 'returns the brand taxon name' do
- expect(product.brand_name).to eql(taxonomy.taxons.first.name)
- end
- end
-
describe '#backordered?' do
let!(:product) { create(:product) }
@@ -1093,21 +1075,6 @@ describe Spree::Product, type: :model do
end
end
- describe '#taxons_for_store' do
- let(:product) { create(:product, store: store, taxons: [taxon]) }
- let(:taxonomy) { create(:taxonomy, store: store) }
- let(:taxon) { create(:taxon, taxonomy: taxonomy) }
-
- it 'returns product taxons for the matching store' do
- expect(product.taxons_for_store(store)).to eq([taxon])
- end
-
- it 'returns an empty relation for an unrelated store' do
- other_store = create(:store)
- expect(product.taxons_for_store(other_store)).to be_empty
- end
- end
-
describe '#category_ids=' do
let(:product) { create(:product, store: store) }
let(:taxonomy) { create(:taxonomy, store: store) }
@@ -1819,7 +1786,7 @@ describe Spree::Product, type: :model do
end
end
- describe 'after_touch :touch_taxons' do
+ describe 'after_touch :touch_categories' do
subject { product.touch }
let!(:product) { create(:product, taxons: taxons) }
@@ -1828,7 +1795,7 @@ describe Spree::Product, type: :model do
let(:taxons) { [] }
it 'skips enqueuing a job for touching the taxons' do
- expect { subject }.not_to have_enqueued_job(Spree::Products::TouchTaxonsJob)
+ expect { subject }.not_to have_enqueued_job(Spree::Products::TouchCategoriesJob)
end
end
@@ -1841,7 +1808,7 @@ describe Spree::Product, type: :model do
let(:taxonomy) { create(:taxonomy) }
it 'enqueues a job for touching the taxons' do
- expect { subject }.to have_enqueued_job(Spree::Products::TouchTaxonsJob).with(
+ expect { subject }.to have_enqueued_job(Spree::Products::TouchCategoriesJob).with(
[taxonomy.root.id, taxon_1.id, taxon_2.id],
[taxonomy.id]
)
diff --git a/spree/core/spec/models/spree/promotion/rules/taxon_spec.rb b/spree/core/spec/models/spree/promotion/rules/taxon_spec.rb
index b50ba4c219..db016c6132 100644
--- a/spree/core/spec/models/spree/promotion/rules/taxon_spec.rb
+++ b/spree/core/spec/models/spree/promotion/rules/taxon_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Spree::Promotion::Rules::Taxon, type: :model do
+describe Spree::Promotion::Rules::Category, type: :model do
let(:store) { @default_store }
let(:promotion) { create(:promotion) }
let(:rule) { create(:promotion_rule_taxon, promotion: promotion) }
diff --git a/spree/core/spec/models/spree/promotion_spec.rb b/spree/core/spec/models/spree/promotion_spec.rb
index 70960bdb65..97b31aeedc 100644
--- a/spree/core/spec/models/spree/promotion_spec.rb
+++ b/spree/core/spec/models/spree/promotion_spec.rb
@@ -1015,7 +1015,7 @@ describe Spree::Promotion, type: :model do
promotion.reload
rule = promotion.rules.first
- expect(rule).to be_a(Spree::Promotion::Rules::Taxon)
+ expect(rule).to be_a(Spree::Promotion::Rules::Category)
expect(rule.taxons).to contain_exactly(taxon)
end
@@ -1029,7 +1029,7 @@ describe Spree::Promotion, type: :model do
fresh.save!
rule = fresh.reload.rules.first
- expect(rule).to be_a(Spree::Promotion::Rules::Taxon)
+ expect(rule).to be_a(Spree::Promotion::Rules::Category)
expect(rule.taxons).to contain_exactly(taxon)
end
diff --git a/spree/core/spec/models/spree/report_line_items/products_performance_spec.rb b/spree/core/spec/models/spree/report_line_items/products_performance_spec.rb
index 16add1ad44..6e7d652ebf 100644
--- a/spree/core/spec/models/spree/report_line_items/products_performance_spec.rb
+++ b/spree/core/spec/models/spree/report_line_items/products_performance_spec.rb
@@ -18,12 +18,6 @@ RSpec.describe Spree::ReportLineItems::ProductsPerformance do
end
end
- describe '#brand' do
- it 'returns brand name from record' do
- expect(subject.brand).to eq(variant.try(:brand_name))
- end
- end
-
describe '#category_levels' do
let(:taxonomy) { store.taxonomies.first || create(:taxonomy, name: 'Categories', store: store) }
let(:taxon) { create(:taxon, name: 'Shoes', taxonomy: taxonomy) }
diff --git a/spree/core/spec/models/spree/taxon_spec.rb b/spree/core/spec/models/spree/taxon_spec.rb
index 392be732a3..39aaac323d 100644
--- a/spree/core/spec/models/spree/taxon_spec.rb
+++ b/spree/core/spec/models/spree/taxon_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Spree::Taxon, type: :model do
+describe Spree::Category, type: :model do
let(:store) { @default_store }
let(:taxonomy) { store.taxonomies.first || create(:taxonomy, store: store) }
let(:taxon) { build(:taxon, name: 'Ruby on Rails', parent: nil) }
@@ -42,16 +42,15 @@ describe Spree::Taxon, type: :model do
context 'Store ownership' do
describe '#requires_taxonomy?' do
- it 'is true for a legacy taxon' do
- expect(described_class.new.requires_taxonomy?).to be(true)
+ it 'is false — a Category is owned via store_id, not a taxonomy' do
+ expect(described_class.new.requires_taxonomy?).to be(false)
end
end
describe 'taxonomy presence' do
- it 'requires a taxonomy' do
- legacy = described_class.new(name: 'Legacy')
- expect(legacy).not_to be_valid
- expect(legacy.errors[:taxonomy]).to be_present
+ it 'is valid without a taxonomy when store-owned' do
+ category = described_class.new(name: 'Standalone', store: store)
+ expect(category).to be_valid
end
end
@@ -680,135 +679,4 @@ describe Spree::Taxon, type: :model do
end
end
- describe '#products_matching_rules' do
- context 'when the taxon is manual' do
- let(:taxon) { create(:taxon) }
-
- it 'returns an empty taxon' do
- expect(taxon.reload.products_matching_rules).to be_empty
- end
- end
-
- context 'when the taxon is automatic' do
- let(:taxon) { create(:automatic_taxon) }
-
- context 'when the taxon has no rules' do
- it 'returns an empty taxon' do
- expect(taxon.reload.products_matching_rules).to be_empty
- end
- end
-
- context 'when the taxon has rules' do
- context 'when the rule is a tag rule' do
- let(:cruelty_free_tag) { ActsAsTaggableOn::Tag.create(name: 'cruelty-free') }
- let(:discounted_tag) { ActsAsTaggableOn::Tag.create(name: 'discounted') }
- let(:other_tag) { ActsAsTaggableOn::Tag.create(name: 'other') }
- let!(:cruelty_free_product) { create(:product, tags: [cruelty_free_tag]) }
- let!(:discounted_product) { create(:product, tags: [discounted_tag]) }
- let!(:both_tags_product) { create(:product, tags: [cruelty_free_tag, discounted_tag]) }
- let!(:other_product) { create(:product, tags: [other_tag]) }
-
- context 'when the match policy is is_equal_to' do
- it 'returns products that match cruelty-free tag' do
- create(:tag_taxon_rule, taxon: taxon, value: cruelty_free_tag.name)
-
- expect(taxon.reload.products_matching_rules).to contain_exactly(cruelty_free_product, both_tags_product)
- end
-
- it 'returns products that match discounted tag' do
- create(:tag_taxon_rule, taxon: taxon, value: discounted_tag.name)
-
- expect(taxon.reload.products_matching_rules).to contain_exactly(discounted_product, both_tags_product)
- end
-
- context 'with all rules match policy' do
- it 'returns products that match both tags' do
- create(:tag_taxon_rule, taxon: taxon, value: cruelty_free_tag.name)
- create(:tag_taxon_rule, taxon: taxon, value: discounted_tag.name)
-
- expect(taxon.reload.products_matching_rules).to contain_exactly(both_tags_product)
- end
- end
-
- context 'with any rules match policy' do
- let(:taxon) { create(:automatic_taxon, :any_match_policy) }
-
- it 'returns products that match any tag' do
- create(:tag_taxon_rule, taxon: taxon, value: cruelty_free_tag.name)
- create(:tag_taxon_rule, taxon: taxon, value: discounted_tag.name)
-
- expect(taxon.reload.products_matching_rules).to contain_exactly(cruelty_free_product, discounted_product, both_tags_product)
- end
- end
- end
-
- context 'when the match policy is is_not_equal_to' do
- it 'returns products that do not match cruelty-free tag' do
- create(:tag_taxon_rule, :is_not_equal_to, taxon: taxon, value: cruelty_free_tag.name)
-
- expect(taxon.reload.products_matching_rules).to contain_exactly(discounted_product, other_product)
- end
-
- it 'returns products that do not match discounted tag' do
- create(:tag_taxon_rule, :is_not_equal_to, taxon: taxon, value: discounted_tag.name)
-
- expect(taxon.reload.products_matching_rules).to contain_exactly(cruelty_free_product, other_product)
- end
-
- context 'with all rules match policy' do
- it 'returns products that do not match both tags' do
- create(:tag_taxon_rule, :is_not_equal_to, taxon: taxon, value: cruelty_free_tag.name)
- create(:tag_taxon_rule, :is_not_equal_to, taxon: taxon, value: discounted_tag.name)
-
- expect(taxon.reload.products_matching_rules).to contain_exactly(other_product)
- end
- end
-
- context 'with any rules match policy' do
- let(:taxon) { create(:automatic_taxon, :any_match_policy) }
-
- it 'returns products that do not match any tag' do
- create(:tag_taxon_rule, :is_not_equal_to, taxon: taxon, value: cruelty_free_tag.name)
- create(:tag_taxon_rule, :is_not_equal_to, taxon: taxon, value: discounted_tag.name)
-
- expect(taxon.reload.products_matching_rules).to contain_exactly(cruelty_free_product, discounted_product, other_product)
- end
- end
- end
- end
-
- context 'when the rule is a sale rule' do
- let!(:product_with_master_on_sale) { create(:product, price: 10, compare_at_price: 12) }
- let!(:product_with_one_variant_on_sale) do
- create(:product).tap do |p|
- create(:variant, product: p, price: 10, compare_at_price: 12)
- create(:variant, product: p, price: 10)
- end
- end
- let!(:product_on_sale_with_different_currency) do
- create(:product, price: 10).tap do |p|
- p.master.prices.create(amount: 10, compare_at_amount: 12, currency: 'PLN')
- end
- end
- let!(:product_not_on_sale) { create(:product, price: 10) }
-
- context 'when the match policy is is_equal_to' do
- it 'matches products that are on sale in store\'s currency' do
- create(:sale_taxon_rule, taxon: taxon)
-
- expect(taxon.reload.products_matching_rules).to contain_exactly(product_with_master_on_sale, product_with_one_variant_on_sale)
- end
- end
-
- context 'when the match policy is in_not_equal_to' do
- it 'matches products that aren\'t on sale and have price in store\'s currency' do
- create(:sale_taxon_rule, :is_not_equal_to, taxon: taxon)
-
- expect(taxon.reload.products_matching_rules).to contain_exactly(product_not_on_sale, product_on_sale_with_different_currency)
- end
- end
- end
- end
- end
- end
end
diff --git a/spree/core/spec/models/spree/taxonomy_spec.rb b/spree/core/spec/models/spree/taxonomy_spec.rb
index 4f90b5245a..024af159d7 100644
--- a/spree/core/spec/models/spree/taxonomy_spec.rb
+++ b/spree/core/spec/models/spree/taxonomy_spec.rb
@@ -50,8 +50,8 @@ describe Spree::Taxonomy, type: :model do
it 'destroys all associated taxons' do
@taxonomy.destroy
- expect { Spree::Taxon.find(@root_taxon.id) }.to raise_error(ActiveRecord::RecordNotFound)
- expect { Spree::Taxon.find(@child_taxon.id) }.to raise_error(ActiveRecord::RecordNotFound)
+ expect { Spree::Category.find(@root_taxon.id) }.to raise_error(ActiveRecord::RecordNotFound)
+ expect { Spree::Category.find(@child_taxon.id) }.to raise_error(ActiveRecord::RecordNotFound)
end
end
diff --git a/spree/core/spec/presenters/spree/csv/product_variant_presenter_spec.rb b/spree/core/spec/presenters/spree/csv/product_variant_presenter_spec.rb
index 32e6e6d1c9..aad30844b8 100644
--- a/spree/core/spec/presenters/spree/csv/product_variant_presenter_spec.rb
+++ b/spree/core/spec/presenters/spree/csv/product_variant_presenter_spec.rb
@@ -22,40 +22,39 @@ RSpec.describe Spree::CSV::ProductVariantPresenter do
expect(subject[3]).to eq product.slug
expect(subject[4]).to eq product.status
expect(subject[5]).to eq product.try(:vendor_name)
- expect(subject[6]).to eq product.brand_name
- expect(subject[7]).to eq product.description&.html_safe
- expect(subject[8]).to eq product.meta_title
- expect(subject[9]).to eq product.meta_description
- expect(subject[10]).to eq product.meta_keywords
- expect(subject[11]).to eq product.tag_list.to_s
- expect(subject[12]).to eq product.label_list.to_s
- expect(subject[13]).to eq variant.amount_in(store.default_currency).to_f
- expect(subject[14]).to eq variant.compare_at_amount_in(store.default_currency).to_f
- expect(subject[15]).to eq store.default_currency
- expect(subject[16]).to eq variant.width
- expect(subject[17]).to eq variant.height
- expect(subject[18]).to eq variant.depth
- expect(subject[19]).to eq 'in'
- expect(subject[20]).to eq variant.weight
- expect(subject[21]).to eq 'lb'
- expect(subject[22]).to eq default_publication.published_at&.strftime('%Y-%m-%d %H:%M:%S')
- expect(subject[23]).to eq(
+ expect(subject[6]).to eq product.description&.html_safe
+ expect(subject[7]).to eq product.meta_title
+ expect(subject[8]).to eq product.meta_description
+ expect(subject[9]).to eq product.meta_keywords
+ expect(subject[10]).to eq product.tag_list.to_s
+ expect(subject[11]).to eq product.label_list.to_s
+ expect(subject[12]).to eq variant.amount_in(store.default_currency).to_f
+ expect(subject[13]).to eq variant.compare_at_amount_in(store.default_currency).to_f
+ expect(subject[14]).to eq store.default_currency
+ expect(subject[15]).to eq variant.width
+ expect(subject[16]).to eq variant.height
+ expect(subject[17]).to eq variant.depth
+ expect(subject[18]).to eq 'in'
+ expect(subject[19]).to eq variant.weight
+ expect(subject[20]).to eq 'lb'
+ expect(subject[21]).to eq default_publication.published_at&.strftime('%Y-%m-%d %H:%M:%S')
+ expect(subject[22]).to eq(
(variant.discontinue_on || default_publication.unpublished_at)&.strftime('%Y-%m-%d %H:%M:%S')
)
- expect(subject[24]).to eq variant.track_inventory?
- expect(subject[25]).to eq(variant.total_on_hand == BigDecimal::INFINITY ? '∞' : variant.total_on_hand)
- expect(subject[26]).to eq variant.backorderable?
- expect(subject[27]).to eq variant.tax_category&.name
- expect(subject[28]).to eq product.shipping_category&.name
- expect(subject[29]).to end_with(variant.images[0].filename.to_s)
- expect(subject[30]).to end_with(variant.images[1].filename.to_s)
- expect(subject[31]).to end_with(variant.images[2].filename.to_s)
+ expect(subject[23]).to eq variant.track_inventory?
+ expect(subject[24]).to eq(variant.total_on_hand == BigDecimal::INFINITY ? '∞' : variant.total_on_hand)
+ expect(subject[25]).to eq variant.backorderable?
+ expect(subject[26]).to eq variant.tax_category&.name
+ expect(subject[27]).to eq product.shipping_category&.name
+ expect(subject[28]).to end_with(variant.images[0].filename.to_s)
+ expect(subject[29]).to end_with(variant.images[1].filename.to_s)
+ expect(subject[30]).to end_with(variant.images[2].filename.to_s)
+ expect(subject[31]).to eq nil
expect(subject[32]).to eq nil
expect(subject[33]).to eq nil
expect(subject[34]).to eq nil
expect(subject[35]).to eq nil
expect(subject[36]).to eq nil
- expect(subject[37]).to eq nil
end
context 'when index is not zero' do
@@ -77,14 +76,14 @@ RSpec.describe Spree::CSV::ProductVariantPresenter do
it 'returns variant specific fields' do
expect(subject[1]).to eq variant.sku
- expect(subject[13]).to eq variant.amount_in(store.default_currency).to_f
- expect(subject[24]).to eq false
- expect(subject[32]).to eq 'Color'
- expect(subject[33]).to eq 'Red'
- expect(subject[34]).to eq 'Size'
- expect(subject[35]).to eq 'Small'
+ expect(subject[12]).to eq variant.amount_in(store.default_currency).to_f
+ expect(subject[23]).to eq false
+ expect(subject[31]).to eq 'Color'
+ expect(subject[32]).to eq 'Red'
+ expect(subject[33]).to eq 'Size'
+ expect(subject[34]).to eq 'Small'
+ expect(subject[35]).to eq nil
expect(subject[36]).to eq nil
- expect(subject[37]).to eq nil
end
end
@@ -95,9 +94,9 @@ RSpec.describe Spree::CSV::ProductVariantPresenter do
end
it 'returns images with default host' do
+ expect(subject[28]).to start_with('http://test.host')
expect(subject[29]).to start_with('http://test.host')
expect(subject[30]).to start_with('http://test.host')
- expect(subject[31]).to start_with('http://test.host')
end
end
@@ -107,9 +106,9 @@ RSpec.describe Spree::CSV::ProductVariantPresenter do
end
it 'returns images with the store url' do
+ expect(subject[28]).to start_with("http://#{store.url}")
expect(subject[29]).to start_with("http://#{store.url}")
expect(subject[30]).to start_with("http://#{store.url}")
- expect(subject[31]).to start_with("http://#{store.url}")
end
end
@@ -213,7 +212,7 @@ RSpec.describe Spree::CSV::ProductVariantPresenter do
it 'exports shipping category name' do
result = presenter.call
- expect(result[28]).to eq 'Digital'
+ expect(result[27]).to eq 'Digital'
end
end
@@ -222,8 +221,8 @@ RSpec.describe Spree::CSV::ProductVariantPresenter do
it 'exports the assigned shipping category' do
result = presenter.call
- expect(result[28]).to be_present
- expect(result[28]).to eq product.shipping_category.name
+ expect(result[27]).to be_present
+ expect(result[27]).to eq product.shipping_category.name
end
end
end
diff --git a/spree/core/spec/services/spree/categories/add_products_spec.rb b/spree/core/spec/services/spree/categories/add_products_spec.rb
new file mode 100644
index 0000000000..5902b7af26
--- /dev/null
+++ b/spree/core/spec/services/spree/categories/add_products_spec.rb
@@ -0,0 +1,52 @@
+require 'spec_helper'
+
+module Spree
+ describe Categories::AddProducts do
+ let(:service) { described_class }
+ let(:categories) { create_list(:category, 2) }
+ let(:products) { create_list(:product, 3) }
+
+ describe '#call' do
+ subject { service.call(categories: categories, products: products) }
+
+ it 'creates product categories for each category-product pair' do
+ expect { subject }.to change { Spree::ProductCategory.count }.by(categories.size * products.size)
+ end
+
+ it 'sets the correct position for each product category' do
+ subject
+ categories.each do |category|
+ expect(category.product_categories.pluck(:position)).to eq((1..products.size).to_a)
+ end
+ end
+
+ it 'touches all products' do
+ expect { subject }.to change { Spree::Product.where(id: products.pluck(:id)).pluck(:updated_at) }
+ end
+
+ it "reindexes products" do
+ allow_any_instance_of(Spree::Product).to receive(:search_indexing_enabled?).and_return(true)
+ expect { subject }.to have_enqueued_job(Spree::SearchProvider::IndexJob).exactly(products.size).times
+ end
+
+ it 'touches all categories' do
+ expect { subject }.to change { Spree::Category.where(id: categories.pluck(:id)).pluck(:updated_at) }
+ end
+
+ it 'returns a successful result' do
+ expect(subject.success?).to be true
+ expect(subject.value).to eq true
+ end
+
+ it 'updates products_count on categories' do
+ expect { subject }.to change { categories.first.reload.products_count }.from(0).to(products.size)
+ .and change { categories.second.reload.products_count }.from(0).to(products.size)
+ end
+
+ it 'updates categories_count on products' do
+ expect { subject }.to change { products.first.reload.categories_count }.from(0).to(categories.size)
+ .and change { products.second.reload.categories_count }.from(0).to(categories.size)
+ end
+ end
+ end
+end
diff --git a/spree/core/spec/services/spree/categories/remove_products_spec.rb b/spree/core/spec/services/spree/categories/remove_products_spec.rb
new file mode 100644
index 0000000000..9bcb67e407
--- /dev/null
+++ b/spree/core/spec/services/spree/categories/remove_products_spec.rb
@@ -0,0 +1,60 @@
+require 'spec_helper'
+
+module Spree
+ describe Categories::RemoveProducts do
+ let(:service) { described_class }
+ let(:categories) { create_list(:category, 2) }
+ let(:products) { create_list(:product, 3) }
+
+ describe '#call' do
+ subject { service.call(categories: categories, products: products) }
+
+ before do
+ # Add products to categories initially
+ Spree::Categories::AddProducts.call(categories: categories, products: products)
+ end
+
+ it 'removes product categories for each category-product pair' do
+ expect { subject }.to change { Spree::ProductCategory.count }.by(-(categories.size * products.size))
+ end
+
+ it 'resets the position for remaining product categories' do
+ other_product = create(:product)
+ Spree::Categories::AddProducts.call(categories: categories, products: [other_product])
+
+ subject
+ categories.each do |category|
+ expect(category.product_categories.pluck(:position)).to eq([1])
+ end
+ end
+
+ it 'touches all products' do
+ expect { subject }.to change { Spree::Product.where(id: products.pluck(:id)).pluck(:updated_at) }
+ end
+
+ it 'touches all categories' do
+ expect { subject }.to change { Spree::Category.where(id: categories.pluck(:id)).pluck(:updated_at) }
+ end
+
+ it "reindexes products" do
+ allow_any_instance_of(Spree::Product).to receive(:search_indexing_enabled?).and_return(true)
+ expect { subject }.to have_enqueued_job(Spree::SearchProvider::IndexJob).exactly(products.size).times
+ end
+
+ it 'returns a successful result' do
+ expect(subject.success?).to be true
+ expect(subject.value).to eq true
+ end
+
+ it 'updates products_count on categories' do
+ expect { subject }.to change { categories.first.reload.products_count }.from(products.size).to(0)
+ .and change { categories.second.reload.products_count }.from(products.size).to(0)
+ end
+
+ it 'updates categories_count on products' do
+ expect { subject }.to change { products.first.reload.categories_count }.from(categories.size).to(0)
+ .and change { products.second.reload.categories_count }.from(categories.size).to(0)
+ end
+ end
+ end
+end
diff --git a/spree/core/spec/services/spree/taxons/add_products_spec.rb b/spree/core/spec/services/spree/taxons/add_products_spec.rb
deleted file mode 100644
index 0c883af258..0000000000
--- a/spree/core/spec/services/spree/taxons/add_products_spec.rb
+++ /dev/null
@@ -1,52 +0,0 @@
-require 'spec_helper'
-
-module Spree
- describe Taxons::AddProducts do
- let(:service) { described_class }
- let(:taxons) { create_list(:taxon, 2) }
- let(:products) { create_list(:product, 3) }
-
- describe '#call' do
- subject { service.call(taxons: taxons, products: products) }
-
- it 'creates classifications for each taxon-product pair' do
- expect { subject }.to change { Spree::Classification.count }.by(taxons.size * products.size)
- end
-
- it 'sets the correct position for each classification' do
- subject
- taxons.each do |taxon|
- expect(taxon.classifications.pluck(:position)).to eq((1..products.size).to_a)
- end
- end
-
- it 'touches all products' do
- expect { subject }.to change { Spree::Product.where(id: products.pluck(:id)).pluck(:updated_at) }
- end
-
- it "reindexes products" do
- allow_any_instance_of(Spree::Product).to receive(:search_indexing_enabled?).and_return(true)
- expect { subject }.to have_enqueued_job(Spree::SearchProvider::IndexJob).exactly(products.size).times
- end
-
- it 'touches all taxons' do
- expect { subject }.to change { Spree::Taxon.where(id: taxons.pluck(:id)).pluck(:updated_at) }
- end
-
- it 'returns a successful result' do
- expect(subject.success?).to be true
- expect(subject.value).to eq true
- end
-
- it 'updates products_count on taxons' do
- expect { subject }.to change { taxons.first.reload.products_count }.from(0).to(products.size)
- .and change { taxons.second.reload.products_count }.from(0).to(products.size)
- end
-
- it 'updates categories_count on products' do
- expect { subject }.to change { products.first.reload.categories_count }.from(0).to(taxons.size)
- .and change { products.second.reload.categories_count }.from(0).to(taxons.size)
- end
- end
- end
-end
diff --git a/spree/core/spec/services/spree/taxons/remove_products_spec.rb b/spree/core/spec/services/spree/taxons/remove_products_spec.rb
deleted file mode 100644
index fb1d3eb341..0000000000
--- a/spree/core/spec/services/spree/taxons/remove_products_spec.rb
+++ /dev/null
@@ -1,60 +0,0 @@
-require 'spec_helper'
-
-module Spree
- describe Taxons::RemoveProducts do
- let(:service) { described_class }
- let(:taxons) { create_list(:taxon, 2) }
- let(:products) { create_list(:product, 3) }
-
- describe '#call' do
- subject { service.call(taxons: taxons, products: products) }
-
- before do
- # Add products to taxons initially
- Spree::Taxons::AddProducts.call(taxons: taxons, products: products)
- end
-
- it 'removes classifications for each taxon-product pair' do
- expect { subject }.to change { Spree::Classification.count }.by(-(taxons.size * products.size))
- end
-
- it 'resets the position for remaining classifications' do
- other_product = create(:product)
- Spree::Taxons::AddProducts.call(taxons: taxons, products: [other_product])
-
- subject
- taxons.each do |taxon|
- expect(taxon.classifications.pluck(:position)).to eq([1])
- end
- end
-
- it 'touches all products' do
- expect { subject }.to change { Spree::Product.where(id: products.pluck(:id)).pluck(:updated_at) }
- end
-
- it 'touches all taxons' do
- expect { subject }.to change { Spree::Taxon.where(id: taxons.pluck(:id)).pluck(:updated_at) }
- end
-
- it "reindexes products" do
- allow_any_instance_of(Spree::Product).to receive(:search_indexing_enabled?).and_return(true)
- expect { subject }.to have_enqueued_job(Spree::SearchProvider::IndexJob).exactly(products.size).times
- end
-
- it 'returns a successful result' do
- expect(subject.success?).to be true
- expect(subject.value).to eq true
- end
-
- it 'updates products_count on taxons' do
- expect { subject }.to change { taxons.first.reload.products_count }.from(products.size).to(0)
- .and change { taxons.second.reload.products_count }.from(products.size).to(0)
- end
-
- it 'updates categories_count on products' do
- expect { subject }.to change { products.first.reload.categories_count }.from(taxons.size).to(0)
- .and change { products.second.reload.categories_count }.from(taxons.size).to(0)
- end
- end
- end
-end