Is there someone that use Search API (http://drupal.org/project/search_api) with Drupal Commerce? How it can be done?

I try to build a Search Index for Product Display but i can't use the defined product fields for it.
The only fields available are the ones from the product module like price, sku, created... etc
Also the Add to cart form it's not available if i want to duil a view for this Search index.

Is this a Commerce issue or a Search API one?

Comments

vasike’s picture

so nobody use Search API?!

I think a search it's very needed on a commerce site. I don't think that Views Exposed Filters it's enough for the search.
Any suggestions? directions?

sonar_un’s picture

I use Search API in my site and it works great. You have to create a search block in views and have it reference the product entity. Then all of the fields will be available for use.

I am sorry I didn't see this sooner, but the functionality is there in case anyone is interested.

vasike’s picture

what about add to cart in the search view?

sonar_un’s picture

Yep, including the add-to-cart view.

In Views, under Format, you can set the view from "fields" (which is usually default), to "entity". So when the search is placed through a context, it grabs the entire entity of the object that the search had indexed. From there, I changed the settings of the entity to a different view mode in order to display the entity in the way that I want. I used Display Suite in order create a new product display view and was able to format the view in the way that I wanted.

I used that to customize individual searches, creating a catalog using contexts for taxonomy terms. So the Search API isn't limited to just an advanced search replacement but an entire catalog, with faceted search. I use panels to set up the blocks for the facets to display them how I want.

This wasn't available until quite recently in Search API, they are still working on their Entity API stuff, but so far is has been working for me. As far as I know, I am the only person doing this kind of stuff. I haven't seen or heard of anyone else doing it. So I can help out a little I hope. It has been months of me scouring forms, posts, tutorials, etc just to get this far. It's very difficult to grasp, but you can get the hang of it.

-otto-’s picture

Hi sonar_un,

I'm have problems with this as well.
What I'm trying to do is create a faceted search for my products. I need three facets:
- product group (eg. t-shirts, sweaters, ...)
- product brand (eg. Diesel, Levi's, ...)
- and the tricky one size

I got the first two working, so that's nice, but I'm stuck on the size facet. The two other facets are taxonomy term references that I added to the node, so they're easy to add as fields in the search index. The size is a field of the commerce product and configured to be an attribute (so I have my color switcher).

To get my results, I created a search index on node, and added some fields to index. I tried adding the 'size' via the add related fields, but the size field doesn't show up in the list of fields, and that is where the problem is.

The rest is standard stuff: I added a search page via the search api to test. After that I added facets, created a view on my 'node index', set the view to show entities and selected my display suite view mode, and placed the facet blocks. All this works fine.

I took a look at you remark in #2, but have had no success adding the size field.
Any suggestions on this would be very welcome (I've been googling and trying settings for two days now).

Thx in advance,

eddib

sonar_un’s picture

Hi eddib,

I did a quick test of this on my own system using the SKU as a field. So it references the product entity from the store and not from the node. For me, the facet block showed up fine in my results and displayed all related SKU's.

So, knowing that the facet blocks do in fact work from the product entity, I think there might be an issue with your particular implementation. Here are some things you can try.

Check the fields for your search index and add the related fields for the product (I know you have done this already, but make sure that they are there).
Re-index all of your search terms. Whenever you add a new field into the search index, the system has to reindex everything to capture that field and put it into the Solr results.
Clear any caches

So if none of those ideas work, then what we might have is a problem with attributes. If I were you, I would try adding a search index field for SKU and one also for Size. If the SKU works, and the Size doesn't, then it must be an attribute problem. I haven't configured my store for attributes so I can't help too much further. I know that Search API is going to start using the Facet API for facets. We might have to wait until that integration comes together to find a solution to this particular problem.

I hope it goes well. Please let me know what you find. Also, if you find a way to make the sliders for price work, i'd really like to know as well. Thanks!

-otto-’s picture

Hi sonar_un,

Thanks for taking the trouble to do this test. Much appreciated.
I've taken a look at what you suggest and I can confirm that I can add the SKU to a node index by adding related fields for the product.

The problem for the size, however, remains. So it is my guess that there is something wrong to add product fields to the index that are configured with the field setting "Enable this field to function as an attribute field on Add to Cart forms."
My size comes from a vocabulary sizes.

If I make a search index on the product instead of the node however, I am able to index on the size field. But in this case I can't add the other fields which I added on the node and not on the commerce product.

So I think this is a bit of a dead end.
I'll now take a look at the Facet API, as I've heard good things about it (drunken_monkey from the search API is hoping for an integration with the search API on drupalCon London, let's hope he can pull it off).

Kind regards,

eddib

Damien Tournoud’s picture

@eddib: there is no reason for what you describe not to work.

Here is how you would do it:

* Add a taxonomy term reference field to the Product entity, linking to your size vocabulary
* Create a index for entities of type "Node"
* Add the fields you want, and add "Product" under "Add related fields"
* Add the "Product >> Size" field that now appears
* Enable faceting on that field in the facets table
* Reindex

Damien Tournoud’s picture

I just did that and it works beautifully. Make sure you have -dev versions of everything. The latest release for Search API is kidda old.

jakonore’s picture

Is it possible to index the field list items instead of a taxonomy term to provide a facet?

I tried but never been able to complete it. The use case is I have a product with lets say color and size variations enabled, each through a list field. I would like to add those variations to my index so I can have a 'filter by size' or 'filter by color block'. Is it possible?

I can always duplicate the information on the product element so when I select the red color I can add the color taxonomy and same for the size, but it seems to me that I shouldn't have to do it this way.

Any feedback is very welcome.

-otto-’s picture

Hi Damien,

Thank you for your reply.

The method described in #8 is exactly what I tried, but the 'Size' did not show up in the list of fields to add to the index...
I'll try again tomorrow and I'll also check if I have the latest versions of everything, I must have missed something somewhere...

Regards,

eddib

marcus_w’s picture

Hey eddib,

I couldn't get it to work properly as well. For me, upgrading to the dev version of Search API did the trick.

Good luck!

j0rd’s picture

sub. I'm currently using Search API with my Drupal Commerce site, but not for products.

The facets for Search API are currently lacking, which make the integration fairly useless at the moment. They're going through the process of integrating with FacetAPI which would make it wonderful. So please show your support for this on-going development over here: http://drupal.org/node/1182614#comment-4904994

-otto-’s picture

Hi all,

I just wanted to mention that I got the filtering on the size attribute working after upgrading to D7.8 and commerce1.0.
As posted in #8 I added product again and the size attribute now appears in the list. Great stuff

Thx for the help everybody.

j0rd’s picture

PS. FacetAPI & SearchAPI are now integrated and they're working great. This makes search api a wonderful catalog for Drupal Commerce. SearchAPI also added "OR" facets as well.

http://drupal.org/node/1182614#comment-4967040

rszrama’s picture

Ooooh, very nice. Thanks for the heads up!

Stompy’s picture

Version: 7.x-1.x-dev » 7.x-1.0

I'm having issues with this as well.

I have a few custom fields in my "Commerce Product" entity that I want to be able to search on, and have the price and add-to-cart form displayed in the search results view.

I've created a search index of entity type "Node". When I go to "Add related fields" and add "Products" I get some fields about the related products, such as Product ID, SKU, title, status etc., but none of my custom fields (such as "Size" and "Load/Speed") appear in the list. I've also tried adding a relationship afterwards on the view, but views tells me no relationships are available to add!

Am I doing something wrong? Or is there something in the module that isn't allowing Search API access to extra fields?

frixos12’s picture

subscribing

Stompy’s picture

bump

Stompy’s picture

Version: 7.x-1.0 » 7.x-1.x-dev
Category: support » feature

Sorry for another bump! This is the main feature blocking me from releasing the new version of my site. I'm willing to put a small amount of money towards getting it implemented if necessary!

rszrama’s picture

The problem is... what exactly do you need to go in? I've never used Search API and am not aware of anything you really should have to do for it to be able to consume our data, since it's just entity / field data.

gilgabar’s picture

@stompy, After adding products via 'add related fields' look at 'add related fields' again. It should show the fields that are related to products which you can then add. I had to do this to use the price as a filter, for example.

Stompy’s picture

@rszrama, basically I can't get an add-to-cart form to appear on my search results view. Since updating to the latest version of search API I now have all my custom fields available (as gilgabar mentioned), and can display the formatted price. However, for some reason the add-to-cart form isn't in the list. I'm not sure if this is a Commerce issue Search API?

I can give you access to my test site if you want to have a look for yourself :)

rszrama’s picture

Is it possibly because Search API can't index forms? A rendered form is session dependent, so perhaps it just automatically ignores it? Whatever it is, the Add to Cart form is a normal display formatter of the product reference field, so if your other fields are working (like prices), I don't know what else would be special about the Add to Cart form.

jakonore’s picture

How are you displaying your results in views? Are you using fields?
I am using search api on two websites and I am able to display the add to cart form. I selected "Content" instead of fields in my view and it works great.
Do you use latest dev of Search Api and related modules (facetapi & entity) ?

Stompy’s picture

I think the problem lies in that I'm search an index of products - not product displays. I want to do it this way because my product display nodes have multiple products on them, but a search (say for a particular size - I sell tyres) will only be relevant to particular products on each node.

@jakonore, I've tried it the way you say, and introduced a new view mode using display suite, but it just keeps throwing up all sorts of errors. I'm using the latest RC of search API (recently released) and latest stable of entity.

Stompy’s picture

Just thought I'd clarify why I need to use Search API in the first place, since I can get similar results using views exposed filters:

Tyre sizes are in the following form: 540/65R24
However, many users will input 540-65-24 or 540x65R24 etc, so I'm using the Search API tokeniser to treat any characters other than numbers as whitespace, and thus as word delimiters. If you know of a simpler way to do this that would be great! haha

rszrama’s picture

Oh, well the Add to Cart form is typically coming from a field display formatter attached to the product node. There is no Add to Cart form attached to a product itself, which would be why you can't find it. ; )

There is a Views field handler that creates a single product Add to Cart form, so is there any way to reuse that within Search API?

Stompy’s picture

If I create a normal view of Commerce Products, I have the field "Commerce Product: Add to Cart form" available to add to the view. In fact, this is the way I display products on my display nodes (as the standard option of a select list isn't good enough for what I need).

However, when I create a view of the search index of Commerce Products, all fields are available (including those that I didn't choose to index), but not the "Commerce Product: Add to Cart form". All I need is for it to appear there! Any ideas? Unfortunately I'm not too familiar with the inner workings of Search API and it's probably beyond me...

Stompy’s picture

I've now managed to achieve this a very hacky way. I created a view that takes a product id (could also be done with SKU) as an argument then returns an add to cart form and nothing else. I then installed the Views field view module and included this view inside my search results view, passing the product id to it as an argument.

I had a similar problem in that I wanted to link the product in the search results list to the relevant product display, but couldnt get this information through views either, so I created another view that takes the SKU as an argument, uses a relationship to find the relevant display node, and displays that. I link to this view from the search results.

It works for now, but I should imagine the overheads from doing it this way are pretty high!

If you want to see it in action, go to my test site (very incomplete!) and put in "65" in the search box.

mrfelton’s picture

Time for some cross posting...

Here are some related threads that may shed some light on some of the issues integrating commerce price fields with search_api and its facetapi implementation, particularly in relation with the search_api_ranges module wich provides a slider widget (and hopefully soon a text link based ranges widget - I'f I can get the damed thing working - hence my posting here!), as well as a possible problem with sorting based on price.

Firstly, If you are trying to use the slider widget on a facet for an indexed commerce price field via a relationship (for example, from an indexed product display node, through a product reference field, and onto a commerce price field) the issue at #1350528: Add support for Commerce module price fields is probably preventing the slider from showing up at all. I have a patch in that issue that makes the slider show up at least, although the values for the price ranges are shown 100 times larger than they should do (eg. $1.50 shows as $150). This is actually the main reason for my posting here.. In that thread there is a proposed solution in comment #11. For whatever reason, commerce is storing price values in 'minor units' (150 as opposed to 1.50), which simply doesn't play well with the current implementation of the slider widget. I'm hoping that someone with a bit more understanding about the commerce internals and the whole Entity arena can give some indication if the proposed solution outlined in comment #11 makes sense, or wether there might be a simpler solution.

Secondly, still with the slider widget - even if you were to apply the patch from the above issue to get the slider to show up (albeit with range values 100 times larger than they should be), the issue at #1344076: URL encoding issue in fields using relationships would probably also hit you - though thats a pretty trivial fix.

Lastly, If you are trying to do sorting using search_api_sorts on a commerce price field, #1310970: Add improved UI help for determining which fields are available for sorting points out that if the product reference field is multivalued (which it is in my case) that it wont be possible to sort on it - unless you create an aggregated field and then sort on that (I haven't tried this yet).

Other than all that, commerce seems to play pretty nicely with search_api!

bojanz’s picture

Category: feature » support
Status: Active » Fixed

Closing the issue. #31 is a good summary of remaining tasks.
Perhaps someone would like to write a tutorial for using Search API with Commerce.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

bojanz’s picture

Months later, all of the patches to all of the modules have been committed, price fields work across the board (indexing, sliders, etc).
We now also have: http://drupal.org/project/commerce_search_api for easier setup.

rszrama’s picture

w00t!

gibry21’s picture

Hi Guys...

I feel I am so close to sorting my issue which is very similar to the very first post here!!

I am using D7, and the Kickstart 2.0 distribution (which is awesome!!)

I have 3 vocabularies which are attached to the node...but also have one that is attached to the product (in the form of discounts).

I can get the search blocks for the 3 node based ones set up easily enough. When I try and copy the set up, by adding the 'Product Variations' additional field and then 'Product variations >> Discounts' then I set up the workflow, facets and sorts tabs in the same way as they others, then adding the block from the blocks admin....aaaaaaannnnnndddd....

NOTHING!

Thie first three work great but no discounts filter!! I know I must be so close and it is probably a simple configuration issue.

Commerceguys have recommended a turbo ticket costing me £65.00 to try and assist me....not great for my first attempt at promoting their OPENSOURCE' solution to my client! :(

Can anybody here help me out?

Thanks in advance guys.

p.s just to say that I would happily pay commerce guys in future and no doubt will have to with some of the larger sites I have in the pipeline, I really want to move our ecommerce solution of choice to Commerce instead of Magento moving forward...but need to have these small issues resolved.

..... I think a related issue may also be that the rendered taxonomy term 'Free this month' from the Discounts vocabulary on the node variation doesn't display an results on the taxonomy page view??? Strange...its does it the term is attached to the node??

rszrama’s picture

This is an old closed issue, and we don't really use the Commerce queue for general Search API support. Have you tried this video? http://www.drupalcommerce.org/blog/5374/ck-tip-2-organizing-your-store-u...