Hello,

Is it possible to get results of Commerce products (https://drupal.org/project/commerce) with Views using "Autocompletion JSON" format? I try but the result is always empty. If I change display format to "Unformated list" it has results.

If it is possible I hope i could make the search autocompletion to search for Commerce products rather than product nodes.

Thank you.

Comments

tm01xx’s picture

Oh, i found that i have to check the title to be a link. If i let the title as plain text the result will be empty.

dom.’s picture

Hi !

I never used Drupal Commerce, so you will have to help me with this !
First of all, yes you can use Search Autocomplete to achieve what you need.

Here is what I have done :
- Install the latest Commerce
- Install Commerce Devel
- Using Devel Generate I have generated 50 products

Now build the view :
- Go to view and create a new one called "autocomplete-products"
- Use the Autocomplete JSON style on fields
- Remove all pagination settings
- Add the field "Product title" with option "linked to it's content"
- Add a filter on title with option "contains", expose it to users and call it's identifier "filter"

Check that you have some data at /autocomplete-products.

[
  {
    "link" : "http://sited7.axiomcafe.fr/admin/commerce/products/1",
    "label" : "Produit: Amet Pneum Qui",
    "value" : "Amet Pneum Qui"
  },
  {
    "link" : "http://sited7.axiomcafe.fr/admin/commerce/products/2",
    "label" : "Produit: Consequat Pneum Tation",
    "value" : "Consequat Pneum Tation"
  },
  {
    "link" : "http://sited7.axiomcafe.fr/admin/commerce/products/3",
    "label" : "Produit: Amet Humo Torqueo",
    "value" : "Amet Humo Torqueo"
  },
....

Now configure Search Autocomplete :
- Go to admin/config/search/search_autocomplete
- Change for instance the "Search Block" to use the callback "autocomplete-products?filter="

It should now work !

I don't understand the difference between Commerce Product and Product nodes. What I gave you will link you to the product page (the one where you can modify the product). I do suppose this is not what you need for your end-user. Have you created a "product" node type with some fields linked to a product or something that kind ?

Miro.

dom.’s picture

Yes indeed exactly you should have to link the title to it's content.
Please also note that I will soon release a 4.x branch where you will be able to add multiple fields in your completion. For instance a product image, the product name and it's price.

Miro.

tm01xx’s picture

Thanks Domi, yes it works perfectly when setting the title with link. Including image into the suggested result is a long waiting feature. Really expect that one release soon :-)

Best regards,

dom.’s picture

Hi !
You can already try it using the 7.x-4.0-alpha1. The more tester there will be, the sooner stable version will be released !

dom.’s picture

Status: Active » Closed (fixed)