Plugin Directory

Changeset 2906136


Ignore:
Timestamp:
04/29/2023 04:48:47 PM (3 years ago)
Author:
simonefontana
Message:

Update plugin version 1.2.

Location:
sf-autosuggest-product-search
Files:
31 added
5 edited

Legend:

Unmodified
Added
Removed
  • sf-autosuggest-product-search/trunk/README.txt

    r2898515 r2906136  
    55Requires PHP: 7.0
    66Tested up to: 6.2
    7 Stable tag:1.1
     7Stable tag:1.2
    88License: GPLv3
    99License URI: http://www.gnu.org/licenses/gpl-3.0.txt
     
    4343
    4444=Can I exclude some categories from search suggests?=
    45 Yes, you can exlude categoies by ID in settings page.
     45Yes, you can exlude categories by ID in settings page.
     46
     47=Can I search for product taxonomies like "Product categories" or "Tags"?=
     48Yes, you can search for product taxonomies.
    4649
    4750== Screenshots ==
     
    5659* Added ability to customize "Show all results" text
    5760
     61= 1.2 =
     62* Added search for taxonomies option.
     63* Added ability to customize placeholder input
     64* Fix bug incorrect permalink
     65
    5866== Upgrade Notice ==
  • sf-autosuggest-product-search/trunk/assets/js/sf_pa.js

    r2870187 r2906136  
    1919                    for (var i = 0; i < response.length; ++i) {
    2020                        var to_append = '<div class="sf_pa_autosuggest_response"><div>';
    21                         if(response[i].show_thumbnail == 'on'){
     21                       
     22                        //Product Image
     23                        if(response[i].show_thumbnail == 'on' && response[i].type == 'product'){
    2224                            to_append += '<div><img style="width:50px; height: auto;" src="'+response[i].img_url+'"></div>';
    2325                        }
    24                         to_append += '<div><div class="sf_pa_autosuggest_title"><a href="'+response[i].link+'">'+response[i].post_title+'</a>';
    25                         if(response[i].show_cat == 'on'){
     26                        //Title and Link
     27                        to_append += '<div><div class="sf_pa_autosuggest_title"><a href="'+response[i].link+'">'+response[i].title+'</a>';
     28                        //Category title
     29                        if(response[i].show_cat == 'on' && response[i].type == 'product'){
    2630                            to_append += '<p>'+response[i].cat_title+'</p>';
    2731                        }
  • sf-autosuggest-product-search/trunk/classes/AdminClass.php

    r2887056 r2906136  
    5050                            ),
    5151                            array(
     52                                'title' => __('Search placeholder', 'sf_products_autosuggest'),
     53                                'section' => 'sf_pa_apparance',
     54                                'key' => 'input_placeholder',
     55                                'input' => 'text_input',
     56                                'instruction' => __('Text of input placeholder', 'sf_products_autosuggest')
     57                            ),
     58                            array(
    5259                                'title' => __('Text "Show all results"', 'sf_products_autosuggest'),
    5360                                'section' => 'sf_pa_apparance',
     
    98105                                'instruction' => __('Exclude products from search. Insert comma separated id of products. For example "12,20"', 'sf_products_autosuggest')
    99106                            ),
     107                            array(
     108                                'title' => __('Search for taxonomies', 'sf_products_autosuggest'),
     109                                'section' => 'sf_pa_apparance',
     110                                'key' => 'taxonomies_search',
     111                                'input' => 'taxonomies',
     112                                'instruction' => __('Select wich taxonomy want search.', 'sf_products_autosuggest')
     113                            )
    100114                        );
    101115   
     
    114128        if (isset($options[$params['key']]))
    115129            $value = esc_attr( $options[$params['key']]);
     130       
    116131        echo "<input id='".$params['section']."_".$params['key']."' name='sf_pa_autosuggest_plugin_options[".$params['key']."]' type='text' value='" .$value. "' />";
     132       
    117133        if(isset($params['instruction']) && !empty($params['instruction'])){
    118134            echo '<p class="sf_pa-instruction">'.$params['instruction'].'</p>';
     
    125141        if (isset($options[$params['key']]))
    126142            $value = esc_attr( $options[$params['key']]);
     143       
    127144        echo "<input id='".$params['section']."_".$params['key']."' class='sf_pa_color_picker' name='sf_pa_autosuggest_plugin_options[".$params['key']."]' type='text' value='" .$value. "' />";
     145       
    128146        if(isset($params['instruction']) && !empty($params['instruction'])){
    129147            echo '<p class="sf_pa-instruction">'.$params['instruction'].'</p>';
     
    136154        if (isset($options[$params['key']]) && $options[$params['key']] =='on')
    137155            $value = 'checked';
     156       
    138157        echo "<input id='".$params['section']."_".$params['key']."' name='sf_pa_autosuggest_plugin_options[".$params['key']."]' type='checkbox' $value />";
    139158       
     
    142161        }
    143162   
     163    }
     164
     165    public function taxonomies($params){
     166        /*TODO: multple choice*/
     167        $options = get_option( 'sf_pa_autosuggest_plugin_options' );
     168        $value = '';
     169        $tax_to_not_use = array('product_type', 'product_visibility', 'product_shipping_class');
     170
     171        $taxonomies = get_object_taxonomies('product','objects');
     172        $html = '<select name="sf_pa_autosuggest_plugin_options['.$params["key"].'][]" multiple="multiple">
     173                    <option value="">-- None --</option>';
     174        foreach($taxonomies as $taxonomy){
     175            if(!in_array($taxonomy->name, $tax_to_not_use)){
     176                $selected = '';
     177                if(isset($options[$params['key']]) && in_array($taxonomy->name, $options[$params['key']])){
     178                    $selected = 'selected';
     179                }
     180                $html .= '<option value="'.$taxonomy->name.'" '.$selected.'>'.$taxonomy->label.'</option>';
     181            }
     182        }
     183
     184        $html .= '</select>';
     185        echo $html;
    144186    }
    145187   
     
    147189        $validator = new SfWAValidator;
    148190        $newinput['results_count'] = $validator->int($input['results_count'], 6);
     191        $newinput['input_placeholder'] = $validator->plaintext($input['input_placeholder']);
    149192        $newinput['all_text'] =  $validator->plaintext($input['all_text']);
    150193        $newinput['all_bg'] =  $validator->hexadecimal($input['all_bg'], '#000');
     
    154197        $newinput['exclude_cat'] = $validator->ids($input['exclude_cat']);
    155198        $newinput['exclude_ids'] =  $validator->ids($input['exclude_ids']);
     199        $newinput['taxonomies_search'] = array();
     200        foreach($input['taxonomies_search'] as $single_tax){
     201            if( $single_tax != '')
     202                $newinput['taxonomies_search'][] =  $validator->plaintext($single_tax);
     203        }
     204       
    156205   
    157206        return $newinput;
  • sf-autosuggest-product-search/trunk/classes/SearchClass.php

    r2887056 r2906136  
    88        $this->count = 6;
    99        $this->content_url = $content_url['baseurl'];
    10         $this->products = array();
     10        $this->results = array();
    1111    }
    1212
     
    2626        }
    2727
    28         $sql = "SELECT ".$wpdb->prefix."posts.post_title, ".$wpdb->prefix."posts.guid as link, img_postmeta.meta_value as img_url,  ".$wpdb->prefix."terms.name as cat_title, %s as show_cat, %s as show_thumbnail  FROM ".$wpdb->prefix."posts
     28        $sql = "SELECT ".$wpdb->prefix."posts.ID, ".$wpdb->prefix."posts.post_title as title, img_postmeta.meta_value as img_url,  ".$wpdb->prefix."terms.name as cat_title, %s as show_cat, %s as show_thumbnail, 'product' AS type
     29                FROM ".$wpdb->prefix."posts
    2930                LEFT JOIN ".$wpdb->prefix."postmeta ON ".$wpdb->prefix."postmeta.post_id =  ".$wpdb->prefix."posts.ID AND ".$wpdb->prefix."postmeta.meta_key = '_thumbnail_id'
    3031                LEFT JOIN ".$wpdb->prefix."postmeta as img_postmeta ON img_postmeta.post_id =  ".$wpdb->prefix."postmeta.meta_value AND img_postmeta.meta_key = '_wp_attachment_metadata'
     
    4950       
    5051        $results_prod = $wpdb->get_results($wpdb->prepare($sql, $prepare));
     52
     53        $results_cat = array();
     54        if(isset($this->options['taxonomies_search']) && !empty($this->options['taxonomies_search']) && is_array($this->options['taxonomies_search'])){
     55            $results_cat = $this->get_taxonomies_search($sf_pa_search);
     56        }
     57       
     58
    5159        foreach($results_prod as $single_prod){
    5260            $single_prod->img_url = $this->get_thumb_from_serialize($single_prod->img_url);
    53             $single_prod->post_title =  esc_html($single_prod->post_title);
     61            $single_prod->title = esc_html($single_prod->title);
    5462            $single_prod->cat_title = esc_html($single_prod->cat_title);
    55             $single_prod->link = esc_url($single_prod->link);
    56             $this->products[] = $single_prod;
     63            $single_prod->link = esc_url($this->build_link($single_prod->type, $single_prod->ID));
     64            $this->results[] = $single_prod;
    5765        }
    58         $this->products = apply_filters('sf_pa_autosuggest_results', $this->products);
    59         return $this->products;
     66
     67        foreach($results_cat as $single_cat){
     68            $single_cat->name = esc_html($single_cat->name);
     69            $single_cat->link = esc_url($this->build_link($single_cat->type, false, $single_cat->taxonomy,$single_cat->slug ));
     70            $this->results[] = $single_cat;
     71        }
     72
     73        $this->results = apply_filters('sf_pa_autosuggest_results', $this->results);
     74
     75       
     76        return $this->results;
    6077    }
    6178
     
    7693        return '';
    7794    }
     95
     96    private function get_taxonomies_search($sf_pa_search){
     97        global $wpdb;
     98        $prepare = $this->options['taxonomies_search'];
     99        $prepare[] = '%' . $wpdb->esc_like($sf_pa_search) .'%';
     100        $sql = "SELECT ".$wpdb->prefix."terms.name as title, ".$wpdb->prefix."terms.slug, ".$wpdb->prefix."term_taxonomy.taxonomy, 'taxonomy' AS type FROM ".$wpdb->prefix."terms
     101                INNER JOIN ".$wpdb->prefix."term_taxonomy ON ".$wpdb->prefix."terms.term_id =  ".$wpdb->prefix."term_taxonomy.term_id
     102                WHERE ".$wpdb->prefix."term_taxonomy.taxonomy IN (".implode(', ', array_fill(0, count($this->options['taxonomies_search']), '%s')).") AND ".$wpdb->prefix."terms.name LIKE %s AND ".$wpdb->prefix."term_taxonomy.count > 0";
     103        $results_cat = $wpdb->get_results($wpdb->prepare($sql, $prepare));
     104        return $results_cat;
     105    }
     106
     107    private function build_link($type, $id, $taxonomy = false, $slug = false){
     108        if($type == 'product'){
     109            return get_site_url().'?p='.$id;
     110        }
     111        elseif('taxonomy'){
     112            return get_site_url().'?taxonomy='.$taxonomy.'&term='.$slug;
     113        }
     114    }
    78115}
  • sf-autosuggest-product-search/trunk/sf_products_autosuggest.php

    r2898515 r2906136  
    44* Plugin URI: https://www.your-site.com/
    55* Description: Autosuggest Product Search for Woocommerce
    6 * Version: 1.1
     6* Version: 1.2
    77* Author: Simone Fontana
    88* Author URI: https://www.simonefontana.net/
     
    4444    $all_bg = '#000';
    4545    $all_color = '#fff';
     46    $placeholder = 'Search products..';
    4647    if(isset($options['all_bg']) && !empty($options['all_bg'])){
    4748        $all_bg = $options['all_bg'];
     
    5051        $all_color = $options['all_color'];
    5152    }
     53    if(isset($options['input_placeholder']) && !empty($options['input_placeholder'])){
     54        $placeholder = $options['input_placeholder'];
     55    }
    5256   
    5357    $html = '<div class="sf_pa_search_input_container">
    5458                <form method="get" role="search" action="'.get_site_url().'">
    55                     <input type="search" id="sf_pa_search_input" class="search-field" placeholder="Search products.." value="" name="s">
     59                    <input type="search" id="sf_pa_search_input" class="search-field" placeholder="'.esc_attr($placeholder).'" value="" name="s">
    5660                    <input type="submit">
    5761                </form>
Note: See TracChangeset for help on using the changeset viewer.