Filter by category is not working in spree sunspot search - spree

I am facing problem in spree sunspot(solr) search.
Filter by price is working file but issue in filter by category.
I am using
rails- 4.1.6,
ruby 2.2.0,
spree_sunspot (1.3)
spree_sunspot.rb
string :category_names, :multiple => true do
category = Spree::Taxon.find_by_permalink('categories')
taxons.select{|t| t.ancestors.include?(category)}.collect{|t| t.self_and_ancestors.map(&:name)}.flatten - [category.name]
end
spree_sunspot_filters.rb
filters.add do |f|
f.display_name = 'Category'
f.search_condition = :any
f.search_param = 'category_name'
f.values { Spree::Taxon.find_by_permalink('categories').children.map(&:name) }
end

I have resolved the issue rebuild the index page and Its working fine.
rake sunspot:reindex

Related

Strong parameter does not work when i new model and controller in spree '3-0-stable' and rails 4.2

How to add new fields for spree::pre_order in Spree-3.0 + Rails4 ?
Like my old customization: ==========================
app/Controllers/spree/api/pre_order_controller
class PreOrderController < Spree::Api::BaseController
def create
#pre_order = PreOrder.new(pre_order_params)
if #pre_order.save
end
respond_with(#pre_order)
end
private
def pre_order_params
params.require(:pre_order).permit(:user_id,:is_order_created)
end
end
I Got following Error
{
"exception": "param is missing or the value is empty: pre_order"
}
Please let me know your comments.

Redirect user to modal popup after registration confirmation using Devise on Rails 4.x webapp

On a Rails 4.x app I'm using Devise to register users. What I want to do is redirect a user after confirmation to the usual user_path(resource) but having a modal appear to prompt for a few things. I don't know how to solve this without using cookies and javascript. Anyone solved this before or know to do it using the standard after_confirmation_path_for way in Devise? If not, what do you think is the best approach to solve it?
Many thanks in advance.
Ok, so if anyone else runs into this problem. I only found one way to solve it, this is it:
confirmations_controller.rb
class ConfirmationsController < Devise::ConfirmationsController
private
def after_confirmation_path_for(resource_name, resource)
sign_in(resource)
user_path(resource[:id], cp: true)
end
end
Then in the view which I want to popup the modal, I used this fairly popular javascript answer (How can I get query string values in JavaScript?) show.html.erb:
<%= javascript_tag do -%>
window.onload = function() {
var doCP = getParameterByName('cp');
if (doCP) {
$("#modal").html("<%= escape_javascript(render 'confirm_prompt_form') %>");
$("#modal").modal("show");
}
}
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

Does Rails 4.1 still have the asset_path helper?

In the upgrade guide it states
Rails 4.0 removed the ActionController::Base.asset_path option. Use the assets pipeline feature.
I am currently in the process of upgrading from Rails 3.2 to Rails 4.1. In my app I use the select2-rails gem and in my js I add an image for the select menu options:
//mycode.js.erb
function format(image) {
var image_path = "<%= asset_path('" + image.id.toLowerCase() +"') %>"
return "<img class='flag' src='" + image_path + "' />";
}
The above worked in my Rails 3.2 app but I seemed to have broken it with my upgrade to 4.1 and now receive the following error:
Sprockets::FileNotFound - couldn't find file '" + image.id.toLowerCase() +"'
Is the asset_path helper still available in Rails 4.1? If yes, any ideas on where I may have gone wrong?
Update
The code above is in my .js.erb file which allows me to have Ruby code within my js file. This currently works well in my Rails 3.2 project. I am doing this as select2 allows us to format the display of our select menu items as per the below example:
//sample.js
function format(state) {
if (!state.id) return state.text; // optgroup
return "<img class='flag' src='images/flags/" + state.id.toLowerCase() + ".png'/>" + state.text;
}
My understanding was that it is correct usage to use the asset pipeline paths rather than manually adding something like 'assets/images/icons/small'

Rails 4 - Circular dependency detected while autoloading constant Users::TodosController

besides using devise for authentification w standard Devise routes.. , I added the follwoing
namespace :users do
resources :todos
end
to magane todos for the current user.
the generated routes are fine ...
users_todos GET /users/todos(.:format) users/todos#index
POST /users/todos(.:format) users/todos#create
new_users_todo GET /users/todos/new(.:format) users/todos#new
edit_users_todo GET /users/todos/:id/edit(.:format) users/todos#edit
users_todo GET /users/todos/:id(.:format) users/todos#show
PATCH /users/todos/:id(.:format) users/todos#update
PUT /users/todos/:id(.:format) users/todos#update
DELETE /users/todos/:id(.:format) users/todos#destroy
once the user is logged in , he is redirected to his todos#index list .. (users_todos_url)
def after_sign_in_path_for(resource)
....
elsif resource.is_a?(User) && Settings.permit_user_login
stored_location_for(resource) || users_todos_url
....
but then , the error is raised .... and it's stated in the log :
Started GET "/users/todos" for 127.0.0.1 at 2014-07-22 14:29:15 +0200
LoadError - Unable to autoload constant Users::TodosController, expected /Users/yves/bitbucket/railsTests/todoapp/app/controllers/users/todos_controller.rb to define it:
I have a users/todo_controller.rb
class User::TodosController < ApplicationController
..
def index
sort_order = "updated_at DESC , title"
todos = Todo.where(:user_id => current_user[:id]).order(sort_order).page params[:page]
end
Log says todo s _controller.rb.
Controller names are plural form.

Getting current cart ID in prestashop

I am busy with a site built on Code Igniter that needs integration with Prestashop. In the site, when creating a user account, I save a "shop_id" to the database, which is then retrieved as a session variable when logging in.
I am using the Prestashop API to retrieve the customer successfully (using above "shop_id")
$xml = $this->PSWebService->get(
array('resource' => 'customers', 'id' => (int)$this->user['shop_id'])
);
This successfully returns the user in question, but there is no Cart IDs in this result.
Logging in to the back-end of my shop, I see that there are multiple carts associated with the logged in user.
My question is: How to I retrieve the LATEST cart ID using the API?
$userId = (int) $this->user['shop_id'];
$opt['resource'] = 'carts';
$xml = $this->PSWebService->get($opt);
$carts = $xml->carts->children();
foreach ($carts as $cart) {
$cartIds[] = $cart['id'];
}
for ($i = count($cartIds) - 1; $i > -1; $i--) {
$opt['id'] = $cartIds[$i];
$xml = $this->PSWebService->get($opt);
//since cart ids are descending the first found will be the latest
if ($xml->cart->id_customer == $userId) {
$latestCartId = $cartIds[$i];
break;
}
}
Kind of late, but I struggled a bit with this same problem and found a way to do it just from query, based on yenshirak's tip (since cart ids are descending the first found will be the latest).
I query the API directly using postman like this:
get all carts:
GET webserver/api/carts
get cart for customer:
GET webserver/api/carts?filter[id_customer]=1
get the most recent:
GET webserver/api/carts?filter[id_customer]=1&sort=[id_DESC]&limit=1
for a pretty print, you can also add params:
display=full&output_format=JSON
You can do this in php, I have not tested if the syntax is correct, but based on documentation it looks something like this:
$opt = array(
'resource' => 'carts',
'filter[id_customer]' => '[1]',
'sort' => '[id_DESC]',
'limit' => '1'
);
$xml = $webService->get($opt);