Changeset 2906136
- Timestamp:
- 04/29/2023 04:48:47 PM (3 years ago)
- Location:
- sf-autosuggest-product-search
- Files:
-
- 31 added
- 5 edited
-
tags/1.2 (added)
-
tags/1.2/README.txt (added)
-
tags/1.2/assets (added)
-
tags/1.2/assets/css (added)
-
tags/1.2/assets/css/sf_pa.css (added)
-
tags/1.2/assets/css/sf_pa_admin.css (added)
-
tags/1.2/assets/fonts (added)
-
tags/1.2/assets/fonts/Roboto (added)
-
tags/1.2/assets/fonts/Roboto/LICENSE.txt (added)
-
tags/1.2/assets/fonts/Roboto/Roboto-Black.ttf (added)
-
tags/1.2/assets/fonts/Roboto/Roboto-BlackItalic.ttf (added)
-
tags/1.2/assets/fonts/Roboto/Roboto-Bold.ttf (added)
-
tags/1.2/assets/fonts/Roboto/Roboto-BoldItalic.ttf (added)
-
tags/1.2/assets/fonts/Roboto/Roboto-Italic.ttf (added)
-
tags/1.2/assets/fonts/Roboto/Roboto-Light.ttf (added)
-
tags/1.2/assets/fonts/Roboto/Roboto-LightItalic.ttf (added)
-
tags/1.2/assets/fonts/Roboto/Roboto-Medium.ttf (added)
-
tags/1.2/assets/fonts/Roboto/Roboto-MediumItalic.ttf (added)
-
tags/1.2/assets/fonts/Roboto/Roboto-Regular.ttf (added)
-
tags/1.2/assets/fonts/Roboto/Roboto-Thin.ttf (added)
-
tags/1.2/assets/fonts/Roboto/Roboto-ThinItalic.ttf (added)
-
tags/1.2/assets/img (added)
-
tags/1.2/assets/img/search-example.png (added)
-
tags/1.2/assets/js (added)
-
tags/1.2/assets/js/sf_pa.js (added)
-
tags/1.2/assets/js/sf_pa_admin.js (added)
-
tags/1.2/classes (added)
-
tags/1.2/classes/AdminClass.php (added)
-
tags/1.2/classes/SearchClass.php (added)
-
tags/1.2/classes/ValidatorClass.php (added)
-
tags/1.2/sf_products_autosuggest.php (added)
-
trunk/README.txt (modified) (3 diffs)
-
trunk/assets/js/sf_pa.js (modified) (1 diff)
-
trunk/classes/AdminClass.php (modified) (8 diffs)
-
trunk/classes/SearchClass.php (modified) (4 diffs)
-
trunk/sf_products_autosuggest.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sf-autosuggest-product-search/trunk/README.txt
r2898515 r2906136 5 5 Requires PHP: 7.0 6 6 Tested up to: 6.2 7 Stable tag:1. 17 Stable tag:1.2 8 8 License: GPLv3 9 9 License URI: http://www.gnu.org/licenses/gpl-3.0.txt … … 43 43 44 44 =Can I exclude some categories from search suggests?= 45 Yes, you can exlude categoies by ID in settings page. 45 Yes, you can exlude categories by ID in settings page. 46 47 =Can I search for product taxonomies like "Product categories" or "Tags"?= 48 Yes, you can search for product taxonomies. 46 49 47 50 == Screenshots == … … 56 59 * Added ability to customize "Show all results" text 57 60 61 = 1.2 = 62 * Added search for taxonomies option. 63 * Added ability to customize placeholder input 64 * Fix bug incorrect permalink 65 58 66 == Upgrade Notice == -
sf-autosuggest-product-search/trunk/assets/js/sf_pa.js
r2870187 r2906136 19 19 for (var i = 0; i < response.length; ++i) { 20 20 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'){ 22 24 to_append += '<div><img style="width:50px; height: auto;" src="'+response[i].img_url+'"></div>'; 23 25 } 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'){ 26 30 to_append += '<p>'+response[i].cat_title+'</p>'; 27 31 } -
sf-autosuggest-product-search/trunk/classes/AdminClass.php
r2887056 r2906136 50 50 ), 51 51 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( 52 59 'title' => __('Text "Show all results"', 'sf_products_autosuggest'), 53 60 'section' => 'sf_pa_apparance', … … 98 105 'instruction' => __('Exclude products from search. Insert comma separated id of products. For example "12,20"', 'sf_products_autosuggest') 99 106 ), 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 ) 100 114 ); 101 115 … … 114 128 if (isset($options[$params['key']])) 115 129 $value = esc_attr( $options[$params['key']]); 130 116 131 echo "<input id='".$params['section']."_".$params['key']."' name='sf_pa_autosuggest_plugin_options[".$params['key']."]' type='text' value='" .$value. "' />"; 132 117 133 if(isset($params['instruction']) && !empty($params['instruction'])){ 118 134 echo '<p class="sf_pa-instruction">'.$params['instruction'].'</p>'; … … 125 141 if (isset($options[$params['key']])) 126 142 $value = esc_attr( $options[$params['key']]); 143 127 144 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 128 146 if(isset($params['instruction']) && !empty($params['instruction'])){ 129 147 echo '<p class="sf_pa-instruction">'.$params['instruction'].'</p>'; … … 136 154 if (isset($options[$params['key']]) && $options[$params['key']] =='on') 137 155 $value = 'checked'; 156 138 157 echo "<input id='".$params['section']."_".$params['key']."' name='sf_pa_autosuggest_plugin_options[".$params['key']."]' type='checkbox' $value />"; 139 158 … … 142 161 } 143 162 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; 144 186 } 145 187 … … 147 189 $validator = new SfWAValidator; 148 190 $newinput['results_count'] = $validator->int($input['results_count'], 6); 191 $newinput['input_placeholder'] = $validator->plaintext($input['input_placeholder']); 149 192 $newinput['all_text'] = $validator->plaintext($input['all_text']); 150 193 $newinput['all_bg'] = $validator->hexadecimal($input['all_bg'], '#000'); … … 154 197 $newinput['exclude_cat'] = $validator->ids($input['exclude_cat']); 155 198 $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 156 205 157 206 return $newinput; -
sf-autosuggest-product-search/trunk/classes/SearchClass.php
r2887056 r2906136 8 8 $this->count = 6; 9 9 $this->content_url = $content_url['baseurl']; 10 $this-> products = array();10 $this->results = array(); 11 11 } 12 12 … … 26 26 } 27 27 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 29 30 LEFT JOIN ".$wpdb->prefix."postmeta ON ".$wpdb->prefix."postmeta.post_id = ".$wpdb->prefix."posts.ID AND ".$wpdb->prefix."postmeta.meta_key = '_thumbnail_id' 30 31 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' … … 49 50 50 51 $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 51 59 foreach($results_prod as $single_prod){ 52 60 $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); 54 62 $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; 57 65 } 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; 60 77 } 61 78 … … 76 93 return ''; 77 94 } 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 } 78 115 } -
sf-autosuggest-product-search/trunk/sf_products_autosuggest.php
r2898515 r2906136 4 4 * Plugin URI: https://www.your-site.com/ 5 5 * Description: Autosuggest Product Search for Woocommerce 6 * Version: 1. 16 * Version: 1.2 7 7 * Author: Simone Fontana 8 8 * Author URI: https://www.simonefontana.net/ … … 44 44 $all_bg = '#000'; 45 45 $all_color = '#fff'; 46 $placeholder = 'Search products..'; 46 47 if(isset($options['all_bg']) && !empty($options['all_bg'])){ 47 48 $all_bg = $options['all_bg']; … … 50 51 $all_color = $options['all_color']; 51 52 } 53 if(isset($options['input_placeholder']) && !empty($options['input_placeholder'])){ 54 $placeholder = $options['input_placeholder']; 55 } 52 56 53 57 $html = '<div class="sf_pa_search_input_container"> 54 58 <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"> 56 60 <input type="submit"> 57 61 </form>
Note: See TracChangeset
for help on using the changeset viewer.