Git Product home page Git Product logo

Comments (4)

luxflux avatar luxflux commented on June 1, 2024 1

I'm not sure if this helps, but this code works for us:

# filter products by size option type
Spree::Product.add_search_scope :size_any do |*opts|
  conds = opts.map { |o| Spree::Core::ProductFilters.size_filter[:conds][o] }.reject(&:nil?)
  scope = conds.shift
  conds.each do |new_scope|
    scope = scope.or(new_scope)
  end
  Spree::Product.joins(variants: { option_values: :translations }).where(scope)
end

def self.size_filter
  size_type = Spree::OptionType.find_by(presentation: 'Size')
  size_options = size_type.option_values.with_translations
  option_value_translations_table = Arel::Table.new(:spree_option_value_translations, ActiveRecord::Base)

  conds = size_options.map { |o| [o.name, option_value_translations_table[:name].eq(o.name)] }
  {
    name:   'Sizes',
    scope:  :size_any,
    conds:  Hash[*conds.flatten],
    labels: conds.map { |k,v| [k, k] }
  }
end

I think the most important part is that you have to reference the table spree_option_value_translations (spree_product_property_translations in your case) instead of spree_option_values.

from solidus_globalize.

bricesanchez avatar bricesanchez commented on June 1, 2024

I've find a temp and bad workaround, it's slow and i think it works only for one product_property filter but... it works...

      Spree::Product.add_search_scope :age_category_any do |*opts|
        conds = opts
        spree_product_property_ids = []

        conds.each do |new_scope|
          spree_product_property_ids << Spree::ProductProperty::Translation.where(value: new_scope).map(&:spree_product_property_id)
        end

        Spree::Product.joins(:product_properties, :translations).where(spree_product_properties: { id: spree_product_property_ids} )
      end

      def ProductFilters.age_category_filter(taxon = nil)
        taxon ||= Spree::Taxonomy.first.root

        age_category_property = Spree::Property.with_translations(I18n.locale).find_by(name: 'age_category')
        # age_category_property.id = 144

        scope = Spree::ProductProperty.with_translations(I18n.locale).where(property_id: age_category_property.id).
          joins(product: :taxons).
          where("#{Spree::Taxon.table_name}.id" => [taxon] + taxon.descendants)

        age_categories = scope.map(&:value).uniq.map(&:to_s)
        pp = Spree::ProductProperty.arel_table
        conds = Hash[*age_categories.map { |b| [b, pp[:value].eq(b)] }.flatten]

        {
          name:   age_category_property.presentation,
          scope:  :age_category_any,
          conds:  conds,
          labels: (age_categories.sort).map { |k| [k, k] }
        }
      end

I think facets should be handle by a powerfull search engine like elasticsearch.

from solidus_globalize.

connecticus avatar connecticus commented on June 1, 2024

I have the same issue. And it seems, that hasn't fixed yet. More than that by creating a new product we've got a bunch of duplicated properties. Another words Solidus doesn't associate same properties in different products.

from solidus_globalize.

stale avatar stale commented on June 1, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from solidus_globalize.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.