Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit 40cf1f91bdf34ba8cb4ea50a720cf51803bf0c60 2 parents 7540d49 + 9675738
@sbounmy sbounmy authored
View
5 app/models/shipping_method_decorator.rb
@@ -0,0 +1,5 @@
+module Spree
+ ShippingMethod.class_eval do
+ translates :name
+ end
+end
View
5 app/models/tax_rate_decorator.rb
@@ -0,0 +1,5 @@
+module Spree
+ TaxRate.class_eval do
+ translates :name
+ end
+end
View
14 app/views/spree/order_mailer/cancel_email.fr.text.erb
@@ -1,17 +1,17 @@
Cher client,
-Votre commande est annulee.
-Merci de conserver cet email pour un eventuel usage ulterieur.
+Votre commande est annulée.
+Merci de conserver ce courriel pour un éventuel usage ultérieur.
============================================================
-Commande [ANNULEE]
+Commande [ANNULÉE]
============================================================
<% @order.line_items.each do |item| %>
-<%= item.variant.sku %> <%= item.variant.product.name %> <%= variant_options(item.variant) %> (<%= item.quantity %>) @ <%= number_to_currency item.price %> = <%= number_to_currency(item.price * item.quantity) %>
+ <%= item.variant.sku %> <%= raw(item.variant.product.name) %> <%= raw(item.variant.options_text) -%> (<%=item.quantity%>) @ <%= number_to_currency item.price %> = <%= number_to_currency(item.price * item.quantity) %>
<% end %>
============================================================
Sous-Total: <%= number_to_currency @order.item_total %>
-<% @order.adjustments.each do |adjustment| %>
-<%= "#{adjustment.label}: #{number_to_currency adjustment.amount}"%>
+<% @order.adjustments.eligible.each do |adjustment| %>
+ <%= raw(adjustment.label) %> <%= number_to_currency(adjustment.amount) %>
<% end %>
-Total TTC: <%= number_to_currency @order.total %>
+Total TTC: <%= number_to_currency(@order.total) %>
View
12 app/views/spree/order_mailer/confirm_email.fr.text.erb
@@ -1,20 +1,20 @@
Cher client,
-Votre commande est confirmee.
-Merci de conserver cet email pour un eventuel usage ulterieur.
+Votre commande est confirmée.
+Merci de conserver ce courriel pour un éventuel usage ultérieur.
============================================================
Commande
============================================================
<% @order.line_items.each do |item| %>
-<%=item.variant.sku %> <%=item.variant.product.name%> <%= item.variant.options_text -%> (<%=item.quantity%>) @ <%= number_to_currency item.price %> = <%= number_to_currency(item.price * item.quantity) %>
+ <%= item.variant.sku %> <%= raw(item.variant.product.name) %> <%= raw(item.variant.options_text) -%> (<%=item.quantity%>) @ <%= number_to_currency item.price %> = <%= number_to_currency(item.price * item.quantity) %>
<% end %>
============================================================
Sous-Total: <%= number_to_currency @order.item_total %>
-<% @order.adjustments.each do |adjustment| %>
-<%= "#{adjustment.label}: #{number_to_currency adjustment.amount}"%>
+<% @order.adjustments.eligible.each do |adjustment| %>
+ <%= raw(adjustment.label) %> <%= number_to_currency(adjustment.amount) %>
<% end %>
-Total TTC: <%= number_to_currency @order.total %>
+Total TTC: <%= number_to_currency(@order.total) %>
Merci pour votre achat.
View
10 db/migrate/20120620153608_add_translations_to_tax_rates.rb
@@ -0,0 +1,10 @@
+class AddTranslationsToTaxRates < ActiveRecord::Migration
+ def up
+ Spree::TaxRate.create_translation_table!({:name => :string},
+ {:migrate_data => true})
+ end
+
+ def down
+ Spree::TaxRate.drop_translation_table!(:migrate_date => true)
+ end
+end
View
9 db/migrate/20120628135204_add_translations_to_shipping_methods.rb
@@ -0,0 +1,9 @@
+class AddTranslationsToShippingMethods < ActiveRecord::Migration
+ def up
+ Spree::ShippingMethod.create_translation_table!(:name => :string)
+ end
+
+ def down
+ Spree::ShippingMethod.drop_translation_table!
+ end
+end
View
27 lib/spree/core/search/base_decorator.rb
@@ -0,0 +1,27 @@
+Spree::Core::Search::Base.class_eval do
+ def get_products_conditions_for(base_scope, query)
+ if query.blank?
+ base_scope
+ else
+ conditions = []
+ keywords = []
+ query.split.each do |keyword|
+ [:name, :description].map do |field|
+ conditions << "spree_product_translations.#{field} LIKE ?"
+ keywords << "%#{keyword}%"
+ end
+ end
+ base_scope.where(conditions.join(' OR '), *keywords)
+ end
+ end
+
+ protected
+
+ def get_base_scope_with_multi_lingual
+ base_scope = Spree::Product.active.joins(:translations).where("locale = ?", I18n.locale)
+ base_scope.merge(get_base_scope_without_multi_lingual)
+ end
+
+ alias_method_chain :get_base_scope, :multi_lingual
+
+end
View
2  lib/spree_multi_lingual/engine.rb
@@ -18,7 +18,7 @@ class Engine < Rails::Engine
end
def self.activate
- Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator*.rb")) do |c|
+ Dir.glob(File.join(File.dirname(__FILE__), "../../{app,lib}/**/*_decorator*.rb")) do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end
end
View
41 spec/lib/search/base_spec.rb
@@ -0,0 +1,41 @@
+require 'spec_helper'
+
+describe Spree::Core::Search::Base do
+
+ before do
+ include ::Spree::ProductFilters
+ @product1 = create(:product, :name => "RoR Shirt", :name_fr => "RoR Chemise", :name_es => "RoR Camisa", :price => 9.00, :on_hand => 1)
+ @product2 = create(:product, :name => "Trouser", :name_fr => "Pantalon", :name_es => "Pantalones", :price => 9.00, :on_hand => 1)
+ end
+
+ it "returns all products by default" do
+ params = { :per_page => "" }
+ searcher = Spree::Core::Search::Base.new(params)
+ searcher.retrieve_products.count.should == 2
+ end
+
+ it 'can return translated product name with correct i18n' do
+ params = { :per_page => "",
+ :keywords => 'Camisa' }
+ I18n.locale = :es
+ searcher = Spree::Core::Search::Base.new(params)
+ searcher.retrieve_products.should == [@product1]
+ end
+
+ it 'should not return with incorrect i18n' do
+ params = { :per_page => "",
+ :keywords => 'Camisa' }
+ I18n.locale = :fr
+ searcher = Spree::Core::Search::Base.new(params)
+ searcher.retrieve_products.should == []
+ end
+
+ it 'should not return product base attribute name' do
+ params = { :per_page => "",
+ :keywords => 'Shirt' }
+ I18n.locale = :fr
+ searcher = Spree::Core::Search::Base.new(params)
+ searcher.retrieve_products.should == []
+ end
+
+end
View
1  spec/spec_helper.rb
@@ -31,6 +31,7 @@
# instead of true.
config.use_transactional_fixtures = true
config.include Spree::UrlHelpers
+ config.include FactoryGirl::Syntax::Methods
config.include Capybara::DSL
config.after(:each) do
Please sign in to comment.
Something went wrong with that request. Please try again.