Display prices of a particular variation in filter
- prakashreddy.imduriParticipant2 years, 6 months ago #30706
Hi,
How can I limit the price filter to index of prices related to a certain variation? Currently its indexing all the prices of the product variations, but on filtering the data with price filter, the data is mismatched as in search result , we are showing the price of the a certain variation type along with title of the product.wpsolrKeymaster2 years, 6 months ago #30707Themes only display products in search results, not product variations.
WPSOLR is indexing products with all their variations prices, which enables filtering products (not product variations) on all variation prices.
After getting the results from WPSOLR, the themes display the product with its price.- This reply was modified 2 years, 6 months ago by wpsolr.
prakashreddy.imduriParticipant2 years, 6 months ago #30711I have a product which has variations in the range of 2000$ – 4000$, I am displaying the minimum variant price in search result, but as it falls into this range, if I select 2000-4000$ range, the item is showing up but the price of lowest variation is $2000.
wpsolrKeymaster2 years, 6 months ago #30712Indeed, WPSOLR found that Product1 has at least one variation with a price in the filter range 4000-5000.
But your theme is showing Product1 with a default price (lower variation price perhaps) not in the filter range.Some themes can show the price range of variations on products results, $2,000-$4,000 for your example.
You could also customize your search results price to show the intersection of filter range and price range (in the url as parameters), $4,000 in your example (intersection of 2000-4000 and 4000-5000)
prakashreddy.imduriParticipant2 years, 6 months ago #30713Your solution is okay, but our requirement is a bit different. We are limited to show only the lowest variation and also the price filter, should work on the basis of that lowest variation (we have a variation name for this, which is same across all the product). Any fix for this ? Can we restrict the price filter not to index the prices outside of this variation ?
prakashreddy.imduriParticipant2 years, 6 months ago #30715yes, we have a variation called single, we want to index that only.
wpsolrKeymaster2 years, 6 months ago #30716Here is the idea: replacing the product _price just before sending the product to the index.
<?php use wpsolr\core\classes\WPSOLR_Events; add_filter( WPSOLR_Events::WPSOLR_FILTER_SOLARIUM_DOCUMENT_BEFORE_UPDATE, 'update_price_with_lowest_variation_price', 99, 5 ); function update_price_with_lowest_variation_price( array $document_for_update, $solr_indexing_options, $post, $attachment_body, $search_engine_client ) { switch ( $post->post_type ) { case 'product': $document_for_update['_price_f'] = /* calculate new price here from wc_get_product( $post->ID ) and its variations */; break; } return $document_for_update; }
prakashreddy.imduriParticipant2 years, 6 months ago #30717As this code is fetching lowest price, Can we set it to get the price from a specific variation every time, instead of calculating lowest price?
prakashreddy.imduriParticipant2 years, 6 months ago #30719Okay, thanks..
prakashreddy.imduriParticipant2 years, 6 months ago #30722Can we use this code in functions.php or any specific file ?
prakashreddy.imduriParticipant2 years, 6 months ago #30724I added this code. For testing , I added a static value as 2000, when I print the array to see if the code is working, I can see the _price_str as 2000, but the facet filter still showing all price range, I am using integer type, to get checkbox with ranges option, I tried :
$document_for_update[‘_price_str’] = 2000, I also checked with [‘_price_i’] and [‘_price_s’], still the filters arent changing.
Also, checked with checkbox layout, prices arent reflecting.
Any settings, I missed out in data tab, for this to work ?
Can you pls advise.
You must be logged in to reply to this topic.