• Resolved madaolex

    (@madaolex)


    Hi!

    During the investigation of the site breakdowns, we found a bug (I suppose) in your plugin that causes the eternal loop.

    Steps:
    1. Add at least 2 filters on the page with different attributes (in our case it’s “topic” and “document-type”) but with same-named terms (in our case both “topic” and “document-type” have a term “specification”).
    2. On the page select at least one term in a filter (not the duplicate one).
    3. Now select the duplicate term in any of those filters.
    (for example, there are two filters: Document Type and Topic, I select the “Posters” term under the “Document Type” filter and then select the “Specification” at the same filter)
    4. Observe page is not loading and site breakdown.

    The reason is the part in the code nearby this https://plugins.trac.www.ads-software.com/browser/yith-woocommerce-ajax-navigation/tags/4.3.0/includes/widgets/class-yith-wcan-navigation-widget.php#L624 row (wp-content/plugins/yith-woocommerce-ajax-navigation/includes/widgets/class.yith-wcan-navigation-widget.php:624)

    // All current filters.
    			if ( $_chosen_attributes ) {
    				foreach ( $_chosen_attributes as $name => $data ) {
    					if ( $name !== $taxonomy ) {
    
    						// Exclude query arg for current term archive term.
    						while ( $in_array_function( $term->slug, $data['terms'] ) ) {
    							$key = array_search( $current_term, $data );
    							unset( $data['terms'][ $key ] );
    						}
    
    						// Remove pa_ and sanitize.
    						$filter_name = urldecode( sanitize_title( str_replace( 'pa_', '', $name ) ) );
    
    						if ( ! empty( $data['terms'] ) ) {
    							$link = add_query_arg( 'filter_' . $filter_name, implode( apply_filters( "yith_wcan_{$display_type}_filter_operator", ',', $display_type, $query_type ), $data['terms'] ), $link );
    						}
    
    						if ( 'or' === $data['query_type'] ) {
    							$link = add_query_arg( 'query_type_' . $filter_name, 'or', $link );
    						}
    					}
    				}
    			}

    At first, I can’t really understand, why you need to remove the term from the $_chosen attributes if this term with the same name but from the other taxonomy is already there, but this is not the cause of the bug, so it’s OK.

    The cause is in the “while” loop you check this:
    $in_array_function( $term->slug, $data['terms'] )
    but after that you get the $key with other attributes:
    $key = array_search( $current_term, $data );
    where you search in the “$data” array instead of “$data[‘terms’]
    and then you remove the item from “$data[‘terms’]” array by that key.

    $data = {array} [2]
     terms = {array} [2]
      0 = "posters"
      1 = "specification"
     query_type = "or"

    In our case $current_term = “”, so the array_search() function returns “false” that PHP transforms into 0 here
    unset( $data['terms'][ $key ] );

    The 0 element in the array in the example from the steps above will be “posters”, it will be removed, but “unset” doesn’t change keys of the remaining elements in the array, so the “specification” element will not be removed, and the while loop never ends.

    $data = {array} [2]
     terms = {array} [1]
      1 = "specification"
     query_type = "or"

    Please feel free to ask something, I hope the explanation above is clear.

    For now, we changed the duplicate term’s name for one of the attributes so it’s not entered the loop.

    • This topic was modified 3 years, 4 months ago by madaolex. Reason: Fix the name of the topic
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Iván Sosa

    (@ivansosa)

    Hi there,

    hope you are doing well! ??

    I can see that you are using the classic widget.
    I tell you that we’ll deprecate it in the future as we plan to remove this widget, so I kindly suggest you update the widgets and make them preset.

    So, it’s better to convert it right now, in order to have it all complete when we remove it and avoid unexpected problems in the future.

    In this link, we explain step by step how to update and adapt them on your site.

    If you have any questions, do not hesitate to contact us.

    Have a great day!

    Thread Starter madaolex

    (@madaolex)

    Thank you! I hope that will help.

    Plugin Support Iván Sosa

    (@ivansosa)

    Hi,

    great! glad to help! ??

    It seems you have no more doubts so we will proceed to close the topic.
    Anyway, if you have any issues don’t hesitate to contact us.

    Have a great day!

    Hello, we have http error and page not loading after installing yith filters, can this be the same cause? https://juwelendewaele.be/product-category/juwelen-18-kt/

    Plugin Support Alessio Torrisi

    (@alessio91)

    Hi @demeersman ,
    it seems you’re using premium version of our plugin.
    Unfortunately I can’t assist you on this platform, please contact us at https://yithemes.com

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Bug report | Cause of an eternal loop’ is closed to new replies.