Forum

Thread tagged as: Question, Shop

productopts within search results

I've added a perch_content_search() function to the page where all my Shop products are displayed. It returns the correct list of product and displays them using the same template as initially used for perch_shop_products(), except that I updated all perch:shop tags to perch:search.

This works fine except now I have added product options to my products. The options show for products returned by perch_shop_products() but not by perch_content_search()?

Hamish Irving

Hamish Irving 1 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

The options won't be available in the search result template, no.

Any way around this? Use perch_shop_products and filter on the query to mimic search?

Drew McLellan

Drew McLellan 2638 points
Perch Support

The central search functionality just doesn't have detailed information about a product in the Shop app available - they're two very different things.

If it were me, I think I'd do it with ajax. Have the SRP make a request to an endpoint that returns your extended HTML snippet for displaying.

I'm currently using ajax to do both the perch_shop_products() call and the perch_content_search() call. So perch_shop_products() is on its own page which is called in the ajax url and same with perch_content_search().

However I'm not sure what you mean by "request to an endpoint that returns your extended HTML snippet for displaying" ?

Drew McLellan

Drew McLellan 2638 points
Perch Support

perch_shop_products() is on its own page which is called in the ajax url

That's what I mean.

Ah cool, not sure how that helps me get around the productops issue though?

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can get the product options, just not in the search result. So get them on a different page (ajax endpoint) and request them from the search result.

Would that be using the perch_shop_product_variants() function? How should I identify the product? By slug?

So I could have a page set up for perch_shop_product_variants() function (lets say get-variants.php) and pass the product slug as a query on the url via ajax (i.e. /get-variants?slug123) then on get-variants.php, perch_get() the slug from the url and pass to perch_shop_product_variants() to filter for correct options?

Drew McLellan

Drew McLellan 2638 points
Perch Support

It depends if you're wanting to list the product options or the variants. I thought you were asking about product options originally.

Yes need to display options the same as can do for perch_shop_product(), I assumed variants were just a unique ID/SKU for a specific products options? I did't see a function to access product options in general?

Drew McLellan

Drew McLellan 2638 points
Perch Support

A variant is a combination of product options and option values. But yes, that would work fine.