Comments (4)
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.
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.
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.
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)
- Dependabot can't resolve your Ruby dependency files
- Dependabot can't resolve your Ruby dependency files
- Soft-delete ShippingMethod translations HOT 16
- Dependabot couldn't find a Gemfile-local for this project HOT 1
- Dependabot couldn't find a Gemfile-local for this project HOT 1
- No text input for languages HOT 1
- Dependabot couldn't find a Gemfile-local for this project HOT 1
- DEPRECATION WARNING: SolidusSupport::EngineExtensions::Decorators is deprecated! Use SolidusSupport::EngineExtensions instead. HOT 1
- Dependabot couldn't find a Gemfile-local for this project HOT 1
- Dependabot couldn't find a Gemfile-local for this project HOT 1
- Dependabot couldn't find a Gemfile-local for this project HOT 1
- Prepare Solidus Globalize for Solidus 3.0 HOT 1
- Dependabot couldn't find a Gemfile-local for this project HOT 1
- Dependabot couldn't find a Gemfile-local for this project
- Solidus 3.0 compatibility HOT 8
- Admin Product Search Form Doesn't Persist Name HOT 1
- Variant Autocomplete Breaks HOT 1
- Install fail HOT 1
- Bump Ruby Support HOT 2
- I have a issue when integrate the this gem. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from solidus_globalize.