Skip to content

Commit

Permalink
Fix PLP searcher (spree-multi-domain)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomek Urban committed Aug 13, 2020
1 parent 71ca068 commit 218f3e1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions core/app/models/spree/taxonomy.rb
Expand Up @@ -6,11 +6,13 @@ class Taxonomy < Spree::Base

has_many :taxons, inverse_of: :taxonomy
has_one :root, -> { where parent_id: nil }, class_name: 'Spree::Taxon', dependent: :destroy
belongs_to :store, optional: true

after_create :set_root
after_save :set_root_taxon_name

default_scope { order("#{table_name}.position, #{table_name}.created_at") }
scope :by_store, ->(store_id) { where(store_id: store_id) }

private

Expand Down
@@ -0,0 +1,7 @@
class AddStoreToSpreeTaxonomies < ActiveRecord::Migration[6.0]
def change
unless column_exists?(:spree_store, :new_order_notifications_email)
add_reference :spree_taxonomies, :store, references: :spree_stores, index: true
end
end
end
4 changes: 3 additions & 1 deletion frontend/app/controllers/spree/products_controller.rb
Expand Up @@ -9,8 +9,10 @@ class ProductsController < Spree::StoreController
respond_to :html

def index
@searcher = build_searcher(params.merge(include_images: true))
@searcher = build_searcher(params.merge(include_images: true, current_store_id: current_store.id))
@products = @searcher.retrieve_products
@products = @products.includes(:possible_promotions) if @products.respond_to?(:includes)
@taxonomies = get_taxonomies

last_modified = @products.maximum(:updated_at)&.utc if @products.respond_to?(:maximum)

Expand Down
6 changes: 6 additions & 0 deletions frontend/app/helpers/spree/frontend_helper.rb
Expand Up @@ -288,6 +288,12 @@ def spree_social_link(service)
end
end

def get_taxonomies
@taxonomies ||= current_store.present? ? Spree::Taxonomy.by_store(current_store) : Spree::Taxonomy
@taxonomies = @taxonomies.includes(root: :children)
@taxonomies
end

private

def formatted_price(value)
Expand Down

0 comments on commit 218f3e1

Please sign in to comment.