Changeset 2421992
- Timestamp:
- 11/20/2020 02:34:07 AM (5 years ago)
- Location:
- mobile-builder/trunk
- Files:
-
- 5 edited
-
README.txt (modified) (1 diff)
-
api/class-mobile-builder-products.php (modified) (4 diffs)
-
includes/class-mobile-builder.php (modified) (3 diffs)
-
mobile-builder.php (modified) (1 diff)
-
product/class-mobile-builder-product.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
mobile-builder/trunk/README.txt
r2404324 r2421992 42 42 43 43 == Changelog == 44 = 1.3.1 = 45 46 * Add: Config query product by radius 47 44 48 = 1.3.0 = 45 49 -
mobile-builder/trunk/api/class-mobile-builder-products.php
r2404325 r2421992 70 70 'permission_callback' => array( $product, 'get_items_permissions_check' ), 71 71 ) ); 72 73 register_rest_route( 'wc/v3', 'term-product-counts', array(74 'methods' => WP_REST_Server::READABLE,75 'callback' => array( $this, 'get_filtered_term_product_counts' ),76 'permission_callback' => array( $product, 'get_items_permissions_check' ),77 ) );78 72 } 79 73 … … 118 112 } 119 113 120 public function get_filtered_term_product_counts( $request ) { 121 global $wpdb; 122 123 $term_ids = wp_list_pluck( get_terms( $request['taxonomy'], array( 'hide_empty' => '1' ) ), 'term_id' ); 124 125 $tax_query = array(); 126 $meta_query = array(); 114 public function woocommerce_rest_product_object_query( $args, $request ) { 115 $tax_query = array(); 127 116 128 117 if ( isset( $request['attrs'] ) && $request['attrs'] ) { … … 135 124 ); 136 125 } 137 } 138 139 if ( isset( $request['category'] ) && $request['category'] ) { 140 $tax_query[] = array( 141 'taxonomy' => 'product_cat', 142 'field' => 'cat_id', 143 'terms' => array( $request['category'] ), 144 ); 126 $args['tax_query'] = $tax_query; 127 } 128 129 return $args; 130 } 131 132 /** 133 * Pre product attribute 134 * 135 * @param $response 136 * @param $item 137 * @param $request 138 * 139 * @return mixed 140 * @since 1.0.0 141 */ 142 public function custom_woocommerce_rest_prepare_product_attribute( $response, $item, $request ) { 143 144 $taxonomy = wc_attribute_taxonomy_name( $item->attribute_name ); 145 146 $options = get_terms( array( 147 'taxonomy' => $taxonomy, 148 'hide_empty' => false, 149 ) ); 150 151 $terms = $this->term_counts( $request, $taxonomy ); 152 153 foreach ( $options as $key => $term ) { 154 if ( $item->attribute_type == 'color' ) { 155 $term->value = sanitize_hex_color( get_term_meta( $term->term_id, 'product_attribute_color', 156 true ) ); 157 } 158 159 if ( $item->attribute_type == 'image' ) { 160 $attachment_id = absint( get_term_meta( $term->term_id, 'product_attribute_image', true ) ); 161 $image_size = function_exists( 'woo_variation_swatches' ) ? woo_variation_swatches()->get_option( 'attribute_image_size' ) : 'thumbnail'; 162 163 $term->value = wp_get_attachment_image_url( $attachment_id, 164 apply_filters( 'wvs_product_attribute_image_size', $image_size ) ); 165 } 166 167 $options[ $key ] = $term; 168 } 169 170 $_terms = array(); 171 foreach ( $terms as $key => $term ) { 172 $i = array_search( $term['term_count_id'], array_column( $options, 'term_id' ) ); 173 if ( $i >= 0 ) { 174 $option = $options[ $i ]; 175 $option->count = intval( $term['term_count'] ); 176 $_terms[] = $option; 177 } 178 } 179 $response->data['options'] = $options; 180 $response->data['terms'] = $_terms; 181 182 return $response; 183 } 184 185 public function term_counts( $request, $taxonomy ) { 186 global $wpdb; 187 188 $term_ids = wp_list_pluck( get_terms( array( 189 'taxonomy' => $taxonomy, 190 'hide_empty' => true, 191 ) ), 'term_id' ); 192 193 $tax_query = array(); 194 $meta_query = array(); 195 196 if ( isset( $request['attrs'] ) && $request['attrs'] ) { 197 $attrs = $request['attrs']; 198 foreach ( $attrs as $attr ) { 199 // foreach ( $attr['terms'] as $term ) { 200 // $tax_query[] = array( 201 // 'taxonomy' => $attr['taxonomy'], 202 // 'field' => $attr['field'], 203 // 'terms' => $term, 204 // ); 205 // } 206 $tax_query[] = array( 207 'taxonomy' => $attr['taxonomy'], 208 'field' => $attr['field'], 209 'terms' => $attr['terms'], 210 ); 211 } 145 212 } 146 213 … … 170 237 $query = implode( ' ', $query ); 171 238 239 172 240 return $wpdb->get_results( $query, ARRAY_A ); 173 241 } 174 242 175 public function woocommerce_rest_product_object_query( $args, $request ) { 176 $tax_query = array(); 177 178 if ( isset( $request['attrs'] ) && $request['attrs'] ) { 179 $attrs = $request['attrs']; 180 foreach ( $attrs as $attr ) { 181 $tax_query[] = array( 182 'taxonomy' => $attr['taxonomy'], 183 'field' => $attr['field'], 184 'terms' => $attr['terms'], 185 ); 186 } 187 $args['tax_query'] = $tax_query; 188 } 189 190 return $args; 243 /** 244 * @param $response 245 * @param $post 246 * @param $request 247 * 248 * @return mixed 249 * @since 1.0.0 250 */ 251 public function prepare_product_images( $response, $post, $request ) { 252 global $_wp_additional_image_sizes; 253 254 if ( empty( $response->data ) ) { 255 return $response; 256 } 257 258 foreach ( $response->data['images'] as $key => $image ) { 259 $image_urls = []; 260 foreach ( $_wp_additional_image_sizes as $size => $value ) { 261 $image_info = wp_get_attachment_image_src( $image['id'], $size ); 262 $response->data['images'][ $key ][ $size ] = $image_info[0]; 263 } 264 } 265 266 return $response; 267 268 } 269 270 /** 271 * @param $response 272 * @param $post 273 * @param $request 274 * 275 * @return mixed 276 * @since 1.0.0 277 */ 278 public function prepare_product_variation_images( $response, $post, $request ) { 279 global $_wp_additional_image_sizes; 280 281 if ( empty( $response->data ) || empty( $response->data['image'] ) ) { 282 return $response; 283 } 284 285 foreach ( $_wp_additional_image_sizes as $size => $value ) { 286 $image_info = wp_get_attachment_image_src( $response->data['image']['id'], $size ); 287 $response->data['image'][ $size ] = $image_info[0]; 288 } 289 290 return $response; 291 292 } 293 294 public function add_value_pa_color( $response ) { 295 296 $term_id = $response->data['id']; 297 $response->data['value'] = sanitize_hex_color( get_term_meta( $term_id, 'product_attribute_color', true ) ); 298 299 return $response; 300 } 301 302 public function add_value_pa_image( $response ) { 303 304 $term_id = $response->data['id']; 305 $attachment_id = absint( get_term_meta( $term_id, 'product_attribute_image', true ) ); 306 $image_size = woo_variation_swatches()->get_option( 'attribute_image_size' ); 307 308 $response->data['value'] = wp_get_attachment_image_url( $attachment_id, 309 apply_filters( 'wvs_product_attribute_image_size', $image_size ) ); 310 311 return $response; 191 312 } 192 313 } -
mobile-builder/trunk/includes/class-mobile-builder.php
r2404324 r2421992 223 223 $plugin_api = new Mobile_Builder_Vendor( $this->get_plugin_name(), $this->get_version() ); 224 224 $this->loader->add_action( 'rest_api_init', $plugin_api, 'add_api_routes', 10 ); 225 // $this->loader->add_filter( 'posts_clauses', $plugin_api, 'mbd_product_list_geo_location_filter_post_clauses', 500, 2 ); 225 if ( defined( 'MOBILE_BUILDER_QUERY_PRODUCT_RADIUS' ) && MOBILE_BUILDER_QUERY_PRODUCT_RADIUS ) { 226 $this->loader->add_filter( 'posts_clauses', $plugin_api, 'mbd_product_list_geo_location_filter_post_clauses', 500, 2 ); 227 } 226 228 $this->loader->add_filter( 'posts_clauses', $plugin_api, 'mbd_product_list_by_vendor', 501, 2 ); 227 229 $this->loader->add_filter( 'posts_clauses', $plugin_api, 'mbd_product_distance', 501, 2 ); … … 238 240 $this->loader->add_filter( 'woocommerce_rest_product_object_query', $products_api, 'woocommerce_rest_product_object_query', 10, 2 ); 239 241 242 $this->loader->add_filter( 'woocommerce_rest_prepare_product_object', $products_api, 243 'prepare_product_images', 30, 3 ); 244 $this->loader->add_filter( 'woocommerce_rest_prepare_product_attribute', $products_api, 245 'custom_woocommerce_rest_prepare_product_attribute', 10, 3 ); 246 $this->loader->add_filter( 'woocommerce_rest_prepare_pa_color', $products_api, 'add_value_pa_color' ); 247 $this->loader->add_filter( 'woocommerce_rest_prepare_pa_image', $products_api, 'add_value_pa_image' ); 248 240 249 } 241 250 … … 321 330 'custom_the_title', 20, 3 ); 322 331 323 $this->loader->add_filter( 'woocommerce_rest_prepare_product_object', $plugin_product,324 'prepare_product_images', 30, 3 );325 326 // Product Attribute327 $this->loader->add_filter( 'woocommerce_rest_prepare_product_attribute', $plugin_product,328 'custom_woocommerce_rest_prepare_product_attribute', 10, 3 );329 330 $this->loader->add_filter( 'woocommerce_rest_prepare_pa_color', $plugin_product, 'add_value_pa_color' );331 $this->loader->add_filter( 'woocommerce_rest_prepare_pa_image', $plugin_product, 'add_value_pa_image' );332 333 332 $this->loader->add_filter( 'wcml_client_currency', $plugin_product, 'mbd_wcml_client_currency' ); 334 333 -
mobile-builder/trunk/mobile-builder.php
r2404324 r2421992 11 11 * Plugin URI: https://doc-oreo.rnlab.io 12 12 * Description: The most advanced drag & drop app builder. Create multi templates and app controls. 13 * Version: 1.3. 013 * Version: 1.3.1 14 14 * Author: Rnlab.io 15 15 * Author URI: https://rnlab.io -
mobile-builder/trunk/product/class-mobile-builder-product.php
r2364781 r2421992 123 123 global $wpdb; 124 124 125 125 126 $lat = $request->get_param( 'lat' ); 126 127 $lng = $request->get_param( 'lng' ); … … 161 162 } 162 163 163 // $data[] = array(164 // 'origin_string' => $origin_string,165 // 'destinations_string' => $destinations_string,166 // 'ids' => $ids,167 // 'gmw_locations' => $gmw_locations168 // );169 170 164 $response->data = $data; 171 165 } … … 185 179 186 180 return $client_currency; 187 }188 189 public function add_value_pa_color( $response ) {190 191 $term_id = $response->data['id'];192 $response->data['value'] = sanitize_hex_color( get_term_meta( $term_id, 'product_attribute_color', true ) );193 194 return $response;195 }196 197 public function add_value_pa_image( $response ) {198 199 $term_id = $response->data['id'];200 $attachment_id = absint( get_term_meta( $term_id, 'product_attribute_image', true ) );201 $image_size = woo_variation_swatches()->get_option( 'attribute_image_size' );202 203 $response->data['value'] = wp_get_attachment_image_url( $attachment_id,204 apply_filters( 'wvs_product_attribute_image_size', $image_size ) );205 206 return $response;207 181 } 208 182 … … 358 332 return $product_data; 359 333 } 360 361 /**362 * Pre product attribute363 *364 * @param $response365 * @param $item366 * @param $request367 *368 * @return mixed369 * @since 1.0.0370 */371 public function custom_woocommerce_rest_prepare_product_attribute( $response, $item, $request ) {372 373 $options = get_terms( array(374 'taxonomy' => wc_attribute_taxonomy_name( $item->attribute_name ),375 'hide_empty' => false,376 ) );377 378 foreach ( $options as $key => $term ) {379 if ( $item->attribute_type == 'color' ) {380 $term->value = sanitize_hex_color( get_term_meta( $term->term_id, 'product_attribute_color',381 true ) );382 }383 384 if ( $item->attribute_type == 'image' ) {385 $attachment_id = absint( get_term_meta( $term->term_id, 'product_attribute_image', true ) );386 $image_size = function_exists( 'woo_variation_swatches' ) ? woo_variation_swatches()->get_option( 'attribute_image_size' ) : 'thumbnail';387 388 $term->value = wp_get_attachment_image_url( $attachment_id,389 apply_filters( 'wvs_product_attribute_image_size', $image_size ) );390 }391 392 $options[ $key ] = $term;393 394 }395 396 $response->data['options'] = $options;397 398 return $response;399 }400 401 /**402 * @param $response403 * @param $post404 * @param $request405 *406 * @return mixed407 * @since 1.0.0408 */409 public function prepare_product_images( $response, $post, $request ) {410 global $_wp_additional_image_sizes;411 412 if ( empty( $response->data ) ) {413 return $response;414 }415 416 foreach ( $response->data['images'] as $key => $image ) {417 $image_urls = [];418 foreach ( $_wp_additional_image_sizes as $size => $value ) {419 $image_info = wp_get_attachment_image_src( $image['id'], $size );420 $response->data['images'][ $key ][ $size ] = $image_info[0];421 }422 }423 424 return $response;425 426 }427 428 /**429 * @param $response430 * @param $post431 * @param $request432 *433 * @return mixed434 * @since 1.0.0435 */436 public function prepare_product_variation_images( $response, $post, $request ) {437 global $_wp_additional_image_sizes;438 439 if ( empty( $response->data ) || empty( $response->data['image'] ) ) {440 return $response;441 }442 443 foreach ( $_wp_additional_image_sizes as $size => $value ) {444 $image_info = wp_get_attachment_image_src( $response->data['image']['id'], $size );445 $response->data['image'][ $size ] = $image_info[0];446 }447 448 return $response;449 450 }451 452 334 }
Note: See TracChangeset
for help on using the changeset viewer.