Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Handle search within translations fields #4

Closed
jipiboily opened this Issue · 5 comments

3 participants

@jipiboily
Owner

Currently, search is only searching in Spree::Product and not in the the Spree::Product::Translation (spree_product_translations). I did something in my project about that, but maybe something less custom could be done within this extension.

@sbounmy have you faced that problem too?

@sbounmy
Collaborator

@jipiboily honnestly, I haven't tried yet to use the search.
Would be great to support it, but seems like Spree 1.1.X is using ransack instead of solr

@olivierbuffon

@jipiboily Can you share what you've done to fix your search problem ? Even if it's sketchy...

@jipiboily
Owner

This is some dirty fix in a decorator, but this works for now (would need a better version):

Spree::Core::Search::Base.class_eval do
  def get_products_conditions_for(base_scope, query)
    # completely rewritten original method to make it work based on locale.
    sql = ""
    query.split.each_with_index do |keyword, i|
      sql += " OR " if i > 0
      sql += " spree_product_translations.name LIKE '%#{keyword}%' "
      sql += " OR spree_product_translations.description LIKE '%#{keyword}%' "
      sql += " OR spree_product_translations.caracteristiques LIKE '%#{keyword}%' "
      sql += " OR spree_products.south_shore_article_id LIKE '%#{keyword}%' "
    end
    base_scope.where(sql)
  end

  protected
    def get_base_scope
      base_scope = Spree::Product.active.joins(:translations).where("locale = ?", I18n.locale)
      # useless for us
      # base_scope = base_scope.in_taxon(taxon) unless taxon.blank?
      base_scope = get_products_conditions_for(base_scope, keywords) unless keywords.blank?
      # useless for us
      # base_scope = base_scope.on_hand unless Spree::Config[:show_zero_stock_products]
      base_scope = add_search_scopes(base_scope)
      base_scope
    end
end
@olivierbuffon

Oh thanks ! Exactly what I tried to do !

@jipiboily
Owner

My pleasure!

@j15e j15e referenced this issue from a commit in hooktstudios/spree_multi_lingual
@j15e j15e Multilingual search. Ref #4
- Based on @jipiboily solution, made it cleaner using chained method to avoid repeating spree core search logic & made cleaner SQL query building.
e8e33c9
@j15e j15e referenced this issue from a commit in hooktstudios/spree_multi_lingual
@j15e j15e Multilingual search. Ref #4
- Based on @jipiboily solution, made it cleaner using chained method to avoid repeating spree core search logic & made cleaner SQL query building.
7b3a8f6
@j15e j15e referenced this issue
Closed

Multilingual search #36

@sbounmy sbounmy referenced this issue from a commit
@sbounmy sbounmy Merge branch 'master' of https://github.com/hooktstudios/spree_multi_…
…lingual into 1-3-stable

* 'master' of https://github.com/hooktstudios/spree_multi_lingual:
  Fix for SQL injections, use ActiveRecord querying
  Search for Spree 1.2 updated logic
  Update spree version to 1.2.x
  Multilingual search. Ref #4
  Update email translations (add accents)
  Add translations for Spree::ShippingMethod (no UI controls yet)
  Add translations for Spree::TaxRate (no UI controls yet)

Conflicts:
	README.md
	spree_multi_lingual.gemspec
40cf1f9
@sbounmy sbounmy referenced this issue from a commit
@sbounmy sbounmy Merge branch '1-3-stable'
* 1-3-stable:
  using quoted translation table name from product model
  Fix for SQL injections, use ActiveRecord querying
  Search for Spree 1.2 updated logic
  Update spree version to 1.2.x
  Multilingual search. Ref #4
0290483
@sbounmy sbounmy closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.