Attached patch makes it possible to re-use the existing "add to cart button" views field with other views query engines, e.g. search api views. That works via the views_handler_field_entity which allows for rendering any entity fields via a loaded entity regardless of the back-end.

CommentFileSizeAuthor
d7_commerce_product_search_api_views.patch2.82 KBfago

Comments

giorgio79’s picture

Using Commerce Kickstart, applied patch, cleared cache, but when I go to Fields in Views admin for the Products search api view the Add to Cart form is not available

jwilson3’s picture

Status: Needs review » Reviewed & tested by the community

Patch in OP worked brilliantly for me. Thanks!

rszrama’s picture

I'm not sure I understand the move from the base entity tables to the views_entity_* tables for these two fields. Is that a requirement, or would using the handler be sufficient?

fago’s picture

The handler takes care of loading the entity via the used Views query class, while the changed base table makes sure the field is available for every Views base table that declares itself to list the given entity type.

Thus, it would work without moving the base table if you manually take care of registering the field. But that's hard to do generally, and Views has a built-in mechanism for that instead. So let's better use that - thanks to the "moved to" features it's totally BC.

giorgio79’s picture

PS : Nevermind, after adding the Product relationship, the Add to Cart form appeared.

@jwilson3 and @fago

Care to share the steps one should take to get this going? I applied the patch but even after clearing cache I am only seeing the regular Search API indexed product fields in the Views Field list like:

 Product: Product ID (indexed)
The internal numeric ID of the product.
 Product: SKU (indexed)
The human readable product SKU.
 Product: Title (indexed)
The title of the product.

No Shopping cart or Add to Cart...

rszrama’s picture

Category: task » feature
Status: Reviewed & tested by the community » Fixed

Ok, cool. This worked fine for me, and I love the Views "moved to" feature. Feel free to point out other areas you think we can use such an improvement.

jwilson3’s picture

Nice (crucial) improvement. Thanks Fago for the patch and Ryan for the commit!

Status: Fixed » Closed (fixed)

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