Possible bug using the official WooCommerce Brands plugin https://woocommerce.com/products/brands/ which adds an additional taxonomy to filter products by brands.
I've uploaded the plugin here: https://github.com/trajche/woocommerce-brands
When filtering products by category, attributes etc. ElasticSearch works perfectly. However, when using the Brands taxonomy widget (Layered navigation from WooCommerce), it completely ignores the brand filter for the query.
Current WordPress version: Latest
Current ElasticPress version: Latest
Current Elasticsearch version: 2.3.1
Where do you host your Elasticsearch server: VPS
Other plugins installed:
WooCommerce
Steps to reproduce:
You can see the code for the widget from WooCommerce Brands here:
https://github.com/trajche/woocommerce-brands/blob/master/includes/widgets/class-wc-widget-brand-nav.php
Im wondering if it's related to the fact that the query they have written is an SQL query?
I have only looked at it with a quick glans, so my apologies if I'm completely off topic. @trajche can you try and add the product brand with the custom taxonomies filter and then reindex?
https://github.com/10up/ElasticPress/blob/develop/features/woocommerce/woocommerce.php#L254
The name of the taxonomy is found here: https://github.com/trajche/woocommerce-brands/blob/master/includes/class-wc-brands.php#L207
Thanks for the reply @kallehauge - I added the taxonomy in the filter and reindexed but that did not fix the filter issue. I went as far as adding it directly in the features/woocommerce/woocommerce.php file in the plugin but it is still not using the filters for that taxonomy.
Will have a look into the brands plugin again to see if it's adding anything extra to the woocommerce 'product' object...
Edit: One thing I noticed is that the Product Brands plugin, the GET parameters it uses in the URL are the actual ID's of the product_brand taxonomy terms, rather than the slugs as are used by the rest of the taxonomy terms... any chance this is causing the issue or is EP indexing the whole object?
Edit#2: When adding the product taxonomy in the filter, it allows for searching for the brands from the search bar -- so that does work properly, but it still does not allow filtering using the Layered Navigation widget from WooCommerce.
@trajche I might be wrong, but in your tax_query, isn't that supposed to be term_id?
https://github.com/trajche/woocommerce-brands/blob/master/includes/class-wc-brands.php#L101
since in our mapping we are using term_id
https://github.com/10up/ElasticPress/blob/develop/includes/mappings/5-2.php#L155
@ivankristianto - That fixed it! Thank you.
I will contact the WooCommerce Brands plugin developers (https://woocommerce.com/products/brands/) with this fix.
Hi there, I have also problem with this. Can you explain me what did you do to solve this problem? @trajche @ivankristianto
@kordicpetar This is apperantly fixed in the new version. But in case you are using the older version, then as @ivankristianto mentioned you need to change the following:
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_brand',
'terms' => $terms,
'field' => 'id'
)
)
to
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_brand',
'terms' => $terms,
'field' => 'term_id'
)
)
in woocommerce-brands/includes/class-wc-brands.php file.
@trajche Thanks for this, but it still does not show brand product. It listing all product when I click on brand in sidebar.
Here is my test site http://menda.rs.dedi36.your-server.de
I am having the same issue with the Woocomerce Brands Pro plug-in.
I have the same issue
woocommerce-brands | 1.6.9
elasticpress | 3.2
I had a (temp?) solution to fix the issue, on woocommerce-brands/includes/class-wc-brands.php
public function update_product_query_tax_query( array $tax_query, WC_Query $wc_query ) {
+ if ( is_tax( 'product_brand' ) ) {
+ $term = get_queried_object();
+ $tax_query[] = array(
+ 'taxonomy' => 'product_brand',
+ 'terms' => $term->term_id,
+ 'operator' => 'IN',
+ );
+ }
if ( isset( $_GET['filter_product_brand'] ) ) { // WPCS: input var ok, CSRF ok.
It works on my setup.