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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Merge branch '6-0-dev' into feature/v-3470
Łukasz Adamczyke1c70fe74267
diff --cc spree/admin/spec/controllers/spree/admin/classifications_controller_spec.rbindex 8811db93d7,96d59b6fbe..e1ff896b50--- a/spree/admin/spec/controllers/spree/admin/classifications_controller_spec.rb+++ b/spree/admin/spec/controllers/spree/admin/classifications_controller_spec.rb@@@ -50,7 -53,8 +53,8 @@@ RSpec.describe Spree::Admin::Classificasubject { post :create, params: { taxon_id: taxon.to_param, ids: [product1.id, product2.id], format: :turbo_stream } }it 'creates classifications' do+ pending('spree/admin not migrated off the master variant - retired in 6.0 for the admin SPA (V-3471)')- expect { subject }.to change(Spree::Classification, :count).by(2)+ expect { subject }.to change(Spree::ProductCategory, :count).by(2)endit 'returns a successful response' dodiff --cc spree/core/app/models/spree/product.rbindex 45860a66f4,e9f7f3ad21..4196cd0b95--- a/spree/core/app/models/spree/product.rb+++ b/spree/core/app/models/spree/product.rb@@@ -158,17 -115,16 +142,16 @@@ module Sprebefore_validation :ensure_default_shipping_categoryafter_create :add_associations_from_prototype- after_create :build_variants_from_option_values_hash, if: :option_values_hashafter_create :apply_pending_variants, if: :pending_variants?+ after_create :ensure_default_variant+ after_create :set_default_variantafter_save :apply_pending_media, if: :pending_media?- after_save :save_master- after_save :run_touch_callbacks, if: :anything_changed?- after_save :reset_nested_changes+ after_save :auto_promote_default_variant+ after_save :run_touch_callbacks, if: :saved_changes?- after_touch :touch_taxons+ after_touch :touch_categories- after_commit :auto_match_taxons, if: :eligible_for_taxon_matching?+ after_commit :auto_match_collections, if: :eligible_for_collection_matching?with_options length: { maximum: 255 }, allow_blank: true dovalidates :meta_keywords@@@ -232,31 -189,21 +216,31 @@@self.tag_list = tagsend- # Sets prices on the master variant.+ # Sets prices on the default variant.# Accepts array of { currency:, amount:, compare_at_amount: } hashes.def prices=(prices_params)- find_or_build_master.prices = prices_params+ find_or_build_default_variant.prices = prices_paramsend- # 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+ 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; 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) : idend- self.taxon_ids = Spree::Taxon.for_store(assignable_store).where(id: decoded_ids).ids+ super(Spree::Collection.for_store(assignable_store).where(id: decoded_ids).ids)end# Sync media inline. Entries with `id` patch the existing asset@@@ -303,9 -250,9 +287,9 @@@endself.whitelisted_ransackable_attributes = %w[description name slug discontinue_on status available_on created_at updated_at]- self.whitelisted_ransackable_associations = %w[categories collections store channels variants_including_master master variants tags labels- self.whitelisted_ransackable_associations = %w[taxons categories store channels variants default_variant tags labels- shipping_category classifications option_types]- self.whitelisted_ransackable_scopes = %w[not_discontinued search_by_name in_taxon in_category in_categories price_between++ self.whitelisted_ransackable_associations = %w[categories collections store channels variants default_variant 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_betweenprice_lte price_gtesearch multi_search in_stock out_of_stock with_option_value_ids@@@ -628,24 -541,55 +578,34 @@@endend- # Master variant may be deleted (i.e. when the product is deleted)- # which would make AR's default finder return nil.- # This is a stopgap for that little problem.+ # @deprecated Use #default_variant — the master variant is being removed in Spree 6.1.def master- super || variants_including_master.with_deleted.find_by(is_master: true)+ Spree::Deprecation.warn('Spree::Product#master is deprecated and will be removed in Spree 6.1. Use #default_variant instead.')+ default_variant+ end++ # @deprecated Use #variants — will be removed in Spree 6.1.+ def variants_including_master+ Spree::Deprecation.warn('Spree::Product#variants_including_master is deprecated and will be removed in Spree 6.1. Use #variants instead.')+ variants+ end++ # @deprecated Use #default_variant_id — will be removed in Spree 6.1.+ def master_id+ default_variant_idend- # Returns the brand taxon for the product- # @return [Spree::Taxon]- def brand_taxon- @brand_taxon ||= if classification_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+ # 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?- # Returns the brand name for the product- # @return [String]- def brand_name- brand_taxon&.name+ @primary_category ||= categories.firstend+ # @deprecated Use {#primary_category}.def main_taxon- return if classification_count.zero?-- @main_taxon ||= taxons.first- end-- def taxons_for_store(store)- return if classification_count.zero?-- taxons.loaded? ? taxons.find_all { |taxon| taxon.taxonomy.store_id == store.id } : taxons.for_store(store)+ primary_categoryenddef any_variant_in_stock_or_backorderable?@@@ -688,11 -632,11 +648,11 @@@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_valueend- 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]+ all_variants = variants.to_adefault_currency = store.default_currencyadditional_currencies = store.supported_currencies_list.map(&:iso_code) - [default_currency]diff --cc spree/core/app/models/spree/reports/products_performance.rbindex 7a854d1aa0,7f175197ca..8c8d0e1f0e--- a/spree/core/app/models/spree/reports/products_performance.rb+++ b/spree/core/app/models/spree/reports/products_performance.rb@@@ -28,7 -28,7 +28,7 @@@ module Spreproduct_scope = store.productsproduct_scope = product_scope.where(vendor_id: vendor.id) if defined?(vendor) && vendor.present?- product_scope.includes(:categories, :tax_category, variants: :prices, master: :prices).- product_scope.includes(:taxons, :tax_category, variants: :prices).++ product_scope.includes(:categories, :tax_category, variants: :prices).joins("LEFT JOIN (#{line_items_sql}) AS line_items ON #{Spree::Product.table_name}.id = line_items.product_id").select("spree_products.*,diff --cc spree/core/app/sorters/spree/classifications/sort.rbindex fba1092d38,c768ac76ce..b4149e9254--- a/spree/core/app/sorters/spree/classifications/sort.rb+++ b/spree/core/app/sorters/spree/classifications/sort.rb@@@ -52,8 -52,8 +52,8 @@@ module Spredef by_price(scope)return scope unless (value = sort_by?('price'))- scope.joins(product: { variants_including_master: :prices }).+ scope.joins(product: { variants: :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]}").