Forum
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()
?
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?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 theperch_content_search()
call. Soperch_shop_products()
is on its own page which is called in the ajax url and same withperch_content_search()
.However I'm not sure what you mean by "request to an endpoint that returns your extended HTML snippet for displaying" ?
That's what I mean.
Ah cool, not sure how that helps me get around the productops issue though?
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 sayget-variants.php
) and pass the product slug as a query on the url via ajax (i.e./get-variants?slug123
) then onget-variants.php
,perch_get()
the slug from the url and pass toperch_shop_product_variants()
to filter for correct options?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?A variant is a combination of product options and option values. But yes, that would work fine.