Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter eugenesomething

    (@eugenesomething)

    Hello!

    I’m sorry for not marking this issue as solved.

    Finally, the solution was in configuring Advanced Quantities for Woo Commerce Plugin properly for different products. For some, I had to use “min_qty” 0.1 and “step_qty” as 0.1, and for some as 1.

    Thank you for your assistance!

    Thread Starter eugenesomething

    (@eugenesomething)

    Hi!

    I will try to modify the theme in order to display the total amount of items found.

    I’m still having issues with displaying the total amount of items found in the AJAX list. I have modified plugins JS section responsible for displaying products (I have adjusted php-end-point to transfer total amount of matching records via “count” variable in response):

    var productsNum = response.products.length;
    var productsTotal = response.count;
    	if (productsNum <10) {
    		html+= '<li style="padding: 10px 8px; font-weight: 600; "class="aws_result_item"> displayed '+productsNum+' items of '+productsTotal+'</li>';
    		} else {
    		html+= '<li style="padding: 10px 8px; font-weight: 600; "class="aws_result_item"> displayed 10 items of '+productsTotal+'</li>';
    		};

    Also, I have modified PHP end-point for AJAX query (aws search file):

    on search section

                if ( ! empty( $this->data['search_terms'] ) ) {
    			// total QTYs section
                    	$posts_ids = $this->query_index_table();
    			$products_count = $posts_ids['posts_count'];
    			$posts_ids = $posts_ids['posts_ids'];
    			// total QTYs section

    query index table section

    
                $sql = "SELECT
                        {$query['select']},
                        {$query['relevance']} as relevance
                    FROM
                        {$table_name}
                    WHERE
                        1=1
                    {$query['search']}
                    {$query['stock']}
                    {$query['visibility']}
                    {$query['exclude_products']}
                    {$query['lang']}
                    GROUP BY ID
                        having relevance > 0
                    ORDER BY
                        relevance DESC, id DESC
    				LIMIT 0, {$results_num}
    		    ";
    			
    			// total QTYs section
    			$sql_count = "SELECT
                        {$query['select']},
                        {$query['relevance']} as relevance
                    FROM
                        {$table_name}
                    WHERE
                        1=1
                    {$query['search']}
                    {$query['stock']}
                    {$query['visibility']}
                    {$query['exclude_products']}
                    {$query['lang']}
                    GROUP BY ID
                        having relevance > 0
                    ORDER BY
                        relevance DESC, id DESC
    		    ";
    
            $this->data['sql'] = $sql;
    			
    	$this->data['sql_count'] = $sql_count;
    
            $posts_ids = $this->get_posts_ids( $sql, $sql_count );
    
            return $posts_ids;

    get_posts_ids section

            private function get_posts_ids( $sql, $sql_count ) {
    
                global $wpdb;
    
                $posts_ids = array();
    
                $search_results = $wpdb->get_results( $sql );
    			
    			// total QTYs section
    			$search_results_count = $wpdb->get_results( $sql_count );
    			
    			$search_results_count = count($search_results_count);
    			// total QTYs section
    			
                if ( !empty( $search_results ) && !is_wp_error( $search_results ) && is_array( $search_results ) ) {
                    foreach ( $search_results as $search_result ) {
                        $post_id = intval( $search_result->ID );
                        if ( ! in_array( $post_id, $posts_ids ) ) {
                            $posts_ids[] = $post_id;
                        }
                    }
                }
    
                unset( $search_results );
    
    			// total QTYs section
    			$result = [
    				'posts_ids' => $posts_ids,
    				'posts_count' => $search_results_count
    			];
    			
    			unset($search_results_count);
    			// total QTYs section
    			
                return $result;
    
            }

    I had certain issues with displaying recurring searches for certain items (got undefined) but I think the unset of $search_results_count has solved the issue.

    I know this solution is terrible from the productivity point of view. Can you advise where to look for in case I simply want to know the total amount of items found? I’m sure using “count” in query would be much smarter than getting full array and then counting it.

    Thread Starter eugenesomething

    (@eugenesomething)

    Hello!

    Unfortunately, event ‘window.addEventListener(‘load’, function() {‘ never fires in my actual project. I have tried both snippets and functions.php connection options. The only way to make this work was by adding this code into the body of the plugin itself (JS part):
    if ( ( typeof response.products !== ‘undefined’ ) && response.products.length > 0 ) {
    //code added begins
    var productsNum = response.products.length;
    html+= ‘<li style=”padding: 10px 8px;”class=”aws_result_item”>’+productsNum+’ items found‘;
    //code added ends
    $.each(response.products, function (i, result) {

    Can you advise why this event as suggested in the initial response never fires?

    Also, I would like to know, if there is a way to add the total amount of products found to the search result page in PHP/HTML, not only to the AJAX dropdown list.

    Thread Starter eugenesomething

    (@eugenesomething)

    Thanks!

    Are you planning to add such functionality to the standard version?

    Thread Starter eugenesomething

    (@eugenesomething)

    Hi!

    I don’t think the project I’m dealing with uses such plugins. I see WooCommerce Advanced Quantity and Quantity Field on Shop Page for WooCommerce plugins. Does any of them support separate pricing per SKU?

Viewing 5 replies - 1 through 5 (of 5 total)