Plugin Directory

Changeset 2864952


Ignore:
Timestamp:
02/14/2023 09:05:28 AM (3 years ago)
Author:
setaryapp
Message:

Update to version 1.2.0 from GitHub

Location:
setary
Files:
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • setary/tags/1.2.0/README.md

    r2860720 r2864952  
    44Requires at least: 5.7
    55Tested up to: 6.1.1
    6 Requires PHP: 5.6
    7 Stable tag: 1.1.0
     6Requires PHP: 7.1
     7Stable tag: 1.2.0
    88License: MIT
    99License URI: https://opensource.org/licenses/MIT
     
    1818Connect your WooCommerce store to Setary with this helper plugin and start bulk editing your WooCommerce products in a spreadsheet environment.
    1919
    20 = Effortless Bulk Editing =
    21 Edit multiple product fields with ease using Setary, the ultimate solution for WooCommerce product management. Effortlessly update fields such as stock, prices, titles, descriptions, and custom fields in a matter of clicks.
     20= Effortlessly Bulk Edit WooCommerce Products =
     21Edit multiple product fields with ease using Setary, the ultimate bulk product editor for WooCommerce. Effortlessly update fields such as stock, prices, titles, descriptions, and custom fields in a matter of clicks.
    2222
    2323= Lightning-Fast =
    24 Setary is super quick! Its API-driven bulk editing for WooCommerce means we remove all the strain off your server and deliver an unrivalled experience.
     24Setary is super quick! Our WooCommerce bulk editor extends the WooCommerce API to alleviate server strain and deliver an unparalleled experience.
    2525
    2626= Manage Multiple Stores =
     
    2828
    2929= Push to Multiple Stores at Once =
    30 If you have the same products in multiple WooCommerce stores, Setary makes it possible to update them all at the same time. Make your changes in our bulk spreadsheet editor on one store, then push those changes to multiple stores by matching products based on their Name, SKU, Slug, or ID.
     30If you have the same products in multiple WooCommerce stores, Setary's bulk product editor makes it possible to update them all at the same time. Make your changes in our bulk product editor on one store, then push those changes to multiple stores by matching products based on their Name, SKU, Slug, or ID.
    3131
    3232= Low-Cost Bulk Editing for WooCommerce =
     
    6161
    6262== Changelog ==
     63
     64= v1.2.0 (2023-02-14) =
     65* [new] Enabled the "menu_order" field
     66* [new] Enabled the "width" field
     67* [new] Enabled the "height" field
     68* [new] Enabled the "length" field
     69* [new] Enabled the "shipping_class" field
     70* [new] Enabled the "weight" field
     71* [new] Enabled the "tax_class" field
     72* [new] Enabled the "tax_status" field
    6373
    6474= v1.1.0 (2023-02-06) =
  • setary/tags/1.2.0/inc/class-product-controller.php

    r2860687 r2864952  
    4141        }
    4242
     43        if ( isset( $request['tax_class'] ) && 'standard' === $request['tex_class'] ) {
     44            $product->set_tax_class( '' );
     45        }
     46
    4347        if ( isset( $request['formatted_categories'] ) ) {
    4448            $category_ids = $this->get_term_ids( $request['formatted_categories'], 'product_cat' );
     
    6064                $gallery_image_ids = wp_list_pluck( $images, 'id' );
    6165                $product->set_gallery_image_ids( $gallery_image_ids );
     66            }
     67        }
     68
     69        // These keys are not saved by default, so let's process them here.
     70
     71        $keys = [
     72            'width',
     73            'height',
     74            'length',
     75        ];
     76
     77        foreach( $keys as $key ) {
     78            if( isset( $request[ $key ] ) ) {
     79                $method_name = sprintf( 'set_%s', $key );
     80
     81                if ( ! method_exists( $product, $method_name ) ) {
     82                    continue;
     83                }
     84
     85                call_user_func( array( $product, $method_name ), $request[ $key ] );
    6286            }
    6387        }
  • setary/tags/1.2.0/inc/class-products-with-variations.php

    r2860687 r2864952  
    132132            // 31 => 'external_url',
    133133            // 32 => 'button_text',
    134             // 33 => 'tax_status',
    135             // 34 => 'tax_class',
     134            33 => 'tax_status',
     135            34 => 'tax_class',
    136136            35 => 'manage_stock',
    137137            36 => 'stock_quantity',
     
    143143            42 => 'sold_individually',
    144144            43 => 'weight',
    145             // 44 => 'dimensions',
     145            44 => 'dimensions',
    146146            // 45 => 'shipping_required',
    147147            // 46 => 'shipping_taxable',
    148             // 47 => 'shipping_class',
     148            47 => 'shipping_class',
    149149            // 48 => 'shipping_class_id',
    150150            // 49 => 'reviews_allowed',
     
    163163            // 62 => 'variations',
    164164            // 63 => 'grouped_products',
    165             // 64 => 'menu_order',
     165            64 => 'menu_order',
    166166            65 => 'meta_data',
    167167        ];
     
    169169        $request->set_param( '_fields', $params );
    170170
    171         /**
    172          * Ensure we get the variation image ID, and not the parent product image ID.
    173          *
    174          * @see WC_Product_Variation::get_image_id()
    175          */
    176         add_filter( 'woocommerce_product_variation_get_image_id', function( $image_id, $product ) {
    177             return $product->get_image_id( 'edit' );
    178         }, 10, 2 );
     171        $this->filter_variation_data();
    179172
    180173        /**
     
    184177
    185178        return parent::get_product_data( $product, $context, $request );
     179    }
     180
     181    /**
     182     * Filter variation data to ensure we're not
     183     * getting data belonging to the parent product.
     184     */
     185    public function filter_variation_data() {
     186        $variation_data_keys = array(
     187            'image_id',
     188            'width',
     189            'height',
     190            'length',
     191            'weight',
     192            'shipping_class_id',
     193        );
     194
     195        foreach ( $variation_data_keys as $key ) {
     196            add_filter( 'woocommerce_product_variation_get_' . $key, function( $value, $product ) use ( $key ) {
     197                $method_name = 'get_' . $key;
     198
     199                if ( ! method_exists( $product, $method_name ) ) {
     200                    return $value;
     201                }
     202
     203                return call_user_func( array( $product, $method_name ), 'edit' );
     204            }, 10, 2 );
     205        }
    186206    }
    187207
     
    206226        $item['formatted_upsell_ids']     = $this->format_ids( $item['upsell_ids'] );
    207227        $item['formatted_cross_sell_ids'] = $this->format_ids( $item['cross_sell_ids'] );
     228        $item['width']                    = $this->get_dimension( $item, 'width');
     229        $item['height']                   = $this->get_dimension( $item, 'height');
     230        $item['length']                   = $this->get_dimension( $item, 'length');
     231        $item['tax_class']                = empty( $item['tax_class'] ) ? 'standard' : $item['tax_class'];
    208232
    209233        // If manage stock is "parent", then really it means "No".
     
    247271                $filter['from'] = 0;
    248272            }
    249             if( empty( $filter['to'] ) ) {
    250                 $filter['to'] = PHP_INT_MAX;
     273
     274            if( empty( $filter['to'] ) && ( isset( $filter['to'] ) && '0' !== $filter['to'] ) ) {
     275                $filter['to'] = $filter['from'];
    251276            }
    252277
     
    268293            }
    269294
     295            $numeric_post_fields = [
     296                'id' => 'ID',
     297                'parent_id' => 'post_parent',
     298                'menu_order' => 'menu_order',
     299            ];
     300
     301            // When searching by empty value, we need to use different query.
     302            // Continue after adding filter.
    270303            if ( ! empty( $filter['mode'] ) && 'empty' === $filter['mode'] ) {
    271304                if( 'name' === $key ) {
    272305                    add_filter( 'posts_where', [ new FilterByBetween(" AND ({$wpdb->prefix}posts.post_title IS NULL OR {$wpdb->prefix}posts.post_title = '')", array()), 'filter' ]);
     306                } else if ( array_key_exists( $key, $numeric_post_fields ) ) {
     307                    $field = $numeric_post_fields[ $key ];
     308                    add_filter( 'posts_where', [ new FilterByBetween(" AND (({$wpdb->prefix}posts.{$field} IS NULL OR {$wpdb->prefix}posts.{$field} = '') AND {$wpdb->prefix}posts.{$field} != 0)", array()), 'filter' ]);
    273309                } else if( 'slug' === $key ) {
    274310                    add_filter( 'posts_where', [ new FilterByBetween(" AND ({$wpdb->prefix}posts.post_name IS NULL OR {$wpdb->prefix}posts.post_name = '')", array()), 'filter' ]);
     
    290326                        ]
    291327                    );
    292                 } else if( in_array( $key, [ '_sku', '_regular_price', '_sale_price', '_stock' ], true) ) {
    293                     $query_args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok.
    294                         $query_args,
    295                         [
    296                             'relation' => 'OR',
    297                             [
    298                                'key' => $key,
    299                                'value' => '',
    300                                'compare' => '=',
    301                             ],
    302                             [
    303                                 'key' => $key,
    304                                 'value' => '0',
    305                                 'compare' => '=',
    306                              ],
    307                             [
    308                                 'key' => $key,
    309                                 'compare' => 'NOT EXISTS',
    310                                 'value' => 'null',
    311                             ]
    312                         ]
    313                     );
    314328                } else {
    315329                    $query_args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok.
    316330                        $query_args,
    317                         [
    318                             'relation' => 'OR',
    319                             [
    320                                'key' => $key,
    321                                'value' => '',
    322                                'compare' => '=',
    323                             ],
    324                             [
    325                                 'key' => $key,
    326                                 'value' => '0',
    327                                 'compare' => '=',
    328                              ],
    329                             [
    330                                 'key' => $key,
    331                                 'compare' => 'NOT EXISTS',
    332                                 'value' => 'null',
    333                             ]
    334                         ]
     331                        $this->get_empty_meta_query( $key )
    335332                    );
    336333                }
     
    338335            }
    339336
    340             if( 'id' === $key ) {
    341                 add_filter( 'posts_where', [ new FilterByBetween(" AND {$wpdb->prefix}posts.ID BETWEEN %d AND %d", array( floatval($filter['from']), floatval($filter['to']) )), 'filter' ]);
     337            // Otherwise, we can use standard query.
     338            if ( array_key_exists( $key, $numeric_post_fields ) ) {
     339                $field = $numeric_post_fields[ $key ];
     340                add_filter( 'posts_where', [ new FilterByBetween(" AND {$wpdb->prefix}posts.{$field} BETWEEN %d AND %d", array( floatval($filter['from']), floatval($filter['to']) )), 'filter' ]);
    342341            } else if( 'type' === $key ) {
    343342                if( in_array( 'variation', $filter['query'], true ) ) {
     
    353352                    );
    354353                }
    355             } else if( 'parent_id' === $key ) {
    356                 add_filter( 'posts_where', [ new FilterByBetween(" AND {$wpdb->prefix}posts.post_parent BETWEEN %d AND %d", array( floatval($filter['from']), floatval($filter['to']) )), 'filter' ]);
    357354            } else if( 'name' === $key ) {
    358355                add_filter( 'posts_where', [ new FilterByBetween(" AND {$wpdb->prefix}posts.post_title LIKE %s", array( '%' . $filter['query'] . '%' )), 'filter' ]);
     
    463460                    )
    464461                );
    465             } else if( $filter['type'] === 'numeric' ) {
     462            } else if ( $filter['type'] === 'numeric' ) {
    466463                $query_args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok.
    467464                    $query_args,
    468465                    array(
    469466                        'key'     => $key,
    470                         'value'   => array( floatval($filter['from']), floatval($filter['to']) ),
    471                         'compare' => 'BETWEEN',
     467                        'value'   => array( floatval( $filter['from'] ), floatval( $filter['to'] ) ),
     468                        'compare' => 'BETWEEN',
    472469                    )
     470                );
     471            }
     472
     473            // Special case for tax_class. `'standard` is actually an empty string or not set.
     474            if ( '_tax_class' === $key && in_array( 'standard', $filter['query'] ) ) {
     475                $query_args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok.
     476                    $query_args,
     477                    $this->get_empty_meta_query( $key ),
     478                    'OR'
    473479                );
    474480            }
     
    535541        return $response;
    536542    }
     543
     544    /**
     545     * Get an empty meta query.
     546     *
     547     * @return array
     548     */
     549    protected function get_empty_meta_query( $key ) {
     550        return [
     551            'relation' => 'OR',
     552            [
     553                'key'     => $key,
     554                'value'   => '',
     555                'compare' => '=',
     556            ],
     557            [
     558                'key'     => $key,
     559                'value'   => '0',
     560                'compare' => '=',
     561            ],
     562            [
     563                'key'     => $key,
     564                'compare' => 'NOT EXISTS',
     565                'value'   => 'null',
     566            ],
     567        ];
     568}
    537569
    538570    /**
     
    690722        return implode( ', ', $ids );
    691723    }
     724
     725    /**
     726     * Get a specific product dimension.
     727     *
     728     * @param array  $item Item array.
     729     * @param string $key  Key.
     730     *
     731     * @return string|float
     732     */
     733    public function get_dimension( $item, $key ) {
     734        if ( empty( $item['dimensions'] ) || empty( $item['dimensions'][ $key ] ) ) {
     735            return '';
     736        }
     737
     738        return floatval( $item['dimensions'][ $key ] );
     739    }
     740
     741    /**
     742     * Add meta query.
     743     *
     744     * @param array  $args       Query args.
     745     * @param array  $meta_query Meta query.
     746     * @param string $relation
     747     *
     748     * @return array
     749     */
     750    protected function add_meta_query( $args, $meta_query, $relation = 'AND' ) {
     751        if ( empty( $args['meta_query'] ) ) {
     752            $args['meta_query'] = array();
     753        }
     754
     755        $args['meta_query']['relation'] = $relation;
     756        $args['meta_query'][]           = $meta_query;
     757
     758        return $args['meta_query'];
     759    }
    692760}
  • setary/tags/1.2.0/setary.php

    r2860687 r2864952  
    1111 * Author URI:           https://setary.com/
    1212 *
    13  * Version:              1.1.0
     13 * Version:              1.2.0
    1414 * WC requires at least: 6.0.0
    1515 * WC tested up to:      7.3.0
     
    2323define( 'SETARY_PATH', \plugin_dir_path( __FILE__ ) );
    2424define( 'SETARY_URL', \plugins_url( '/', __FILE__ ) );
    25 define( 'SETARY_VERSION', '1.1.0' );
     25define( 'SETARY_VERSION', '1.2.0' );
    2626define( 'SETARY_SITE_URL', 'https://setary.com/' );
    2727define( 'SETARY_APP_URL', 'https://setary.com/app/' );
  • setary/trunk/README.md

    r2860720 r2864952  
    44Requires at least: 5.7
    55Tested up to: 6.1.1
    6 Requires PHP: 5.6
    7 Stable tag: 1.1.0
     6Requires PHP: 7.1
     7Stable tag: 1.2.0
    88License: MIT
    99License URI: https://opensource.org/licenses/MIT
     
    1818Connect your WooCommerce store to Setary with this helper plugin and start bulk editing your WooCommerce products in a spreadsheet environment.
    1919
    20 = Effortless Bulk Editing =
    21 Edit multiple product fields with ease using Setary, the ultimate solution for WooCommerce product management. Effortlessly update fields such as stock, prices, titles, descriptions, and custom fields in a matter of clicks.
     20= Effortlessly Bulk Edit WooCommerce Products =
     21Edit multiple product fields with ease using Setary, the ultimate bulk product editor for WooCommerce. Effortlessly update fields such as stock, prices, titles, descriptions, and custom fields in a matter of clicks.
    2222
    2323= Lightning-Fast =
    24 Setary is super quick! Its API-driven bulk editing for WooCommerce means we remove all the strain off your server and deliver an unrivalled experience.
     24Setary is super quick! Our WooCommerce bulk editor extends the WooCommerce API to alleviate server strain and deliver an unparalleled experience.
    2525
    2626= Manage Multiple Stores =
     
    2828
    2929= Push to Multiple Stores at Once =
    30 If you have the same products in multiple WooCommerce stores, Setary makes it possible to update them all at the same time. Make your changes in our bulk spreadsheet editor on one store, then push those changes to multiple stores by matching products based on their Name, SKU, Slug, or ID.
     30If you have the same products in multiple WooCommerce stores, Setary's bulk product editor makes it possible to update them all at the same time. Make your changes in our bulk product editor on one store, then push those changes to multiple stores by matching products based on their Name, SKU, Slug, or ID.
    3131
    3232= Low-Cost Bulk Editing for WooCommerce =
     
    6161
    6262== Changelog ==
     63
     64= v1.2.0 (2023-02-14) =
     65* [new] Enabled the "menu_order" field
     66* [new] Enabled the "width" field
     67* [new] Enabled the "height" field
     68* [new] Enabled the "length" field
     69* [new] Enabled the "shipping_class" field
     70* [new] Enabled the "weight" field
     71* [new] Enabled the "tax_class" field
     72* [new] Enabled the "tax_status" field
    6373
    6474= v1.1.0 (2023-02-06) =
  • setary/trunk/inc/class-product-controller.php

    r2860687 r2864952  
    4141        }
    4242
     43        if ( isset( $request['tax_class'] ) && 'standard' === $request['tex_class'] ) {
     44            $product->set_tax_class( '' );
     45        }
     46
    4347        if ( isset( $request['formatted_categories'] ) ) {
    4448            $category_ids = $this->get_term_ids( $request['formatted_categories'], 'product_cat' );
     
    6064                $gallery_image_ids = wp_list_pluck( $images, 'id' );
    6165                $product->set_gallery_image_ids( $gallery_image_ids );
     66            }
     67        }
     68
     69        // These keys are not saved by default, so let's process them here.
     70
     71        $keys = [
     72            'width',
     73            'height',
     74            'length',
     75        ];
     76
     77        foreach( $keys as $key ) {
     78            if( isset( $request[ $key ] ) ) {
     79                $method_name = sprintf( 'set_%s', $key );
     80
     81                if ( ! method_exists( $product, $method_name ) ) {
     82                    continue;
     83                }
     84
     85                call_user_func( array( $product, $method_name ), $request[ $key ] );
    6286            }
    6387        }
  • setary/trunk/inc/class-products-with-variations.php

    r2860687 r2864952  
    132132            // 31 => 'external_url',
    133133            // 32 => 'button_text',
    134             // 33 => 'tax_status',
    135             // 34 => 'tax_class',
     134            33 => 'tax_status',
     135            34 => 'tax_class',
    136136            35 => 'manage_stock',
    137137            36 => 'stock_quantity',
     
    143143            42 => 'sold_individually',
    144144            43 => 'weight',
    145             // 44 => 'dimensions',
     145            44 => 'dimensions',
    146146            // 45 => 'shipping_required',
    147147            // 46 => 'shipping_taxable',
    148             // 47 => 'shipping_class',
     148            47 => 'shipping_class',
    149149            // 48 => 'shipping_class_id',
    150150            // 49 => 'reviews_allowed',
     
    163163            // 62 => 'variations',
    164164            // 63 => 'grouped_products',
    165             // 64 => 'menu_order',
     165            64 => 'menu_order',
    166166            65 => 'meta_data',
    167167        ];
     
    169169        $request->set_param( '_fields', $params );
    170170
    171         /**
    172          * Ensure we get the variation image ID, and not the parent product image ID.
    173          *
    174          * @see WC_Product_Variation::get_image_id()
    175          */
    176         add_filter( 'woocommerce_product_variation_get_image_id', function( $image_id, $product ) {
    177             return $product->get_image_id( 'edit' );
    178         }, 10, 2 );
     171        $this->filter_variation_data();
    179172
    180173        /**
     
    184177
    185178        return parent::get_product_data( $product, $context, $request );
     179    }
     180
     181    /**
     182     * Filter variation data to ensure we're not
     183     * getting data belonging to the parent product.
     184     */
     185    public function filter_variation_data() {
     186        $variation_data_keys = array(
     187            'image_id',
     188            'width',
     189            'height',
     190            'length',
     191            'weight',
     192            'shipping_class_id',
     193        );
     194
     195        foreach ( $variation_data_keys as $key ) {
     196            add_filter( 'woocommerce_product_variation_get_' . $key, function( $value, $product ) use ( $key ) {
     197                $method_name = 'get_' . $key;
     198
     199                if ( ! method_exists( $product, $method_name ) ) {
     200                    return $value;
     201                }
     202
     203                return call_user_func( array( $product, $method_name ), 'edit' );
     204            }, 10, 2 );
     205        }
    186206    }
    187207
     
    206226        $item['formatted_upsell_ids']     = $this->format_ids( $item['upsell_ids'] );
    207227        $item['formatted_cross_sell_ids'] = $this->format_ids( $item['cross_sell_ids'] );
     228        $item['width']                    = $this->get_dimension( $item, 'width');
     229        $item['height']                   = $this->get_dimension( $item, 'height');
     230        $item['length']                   = $this->get_dimension( $item, 'length');
     231        $item['tax_class']                = empty( $item['tax_class'] ) ? 'standard' : $item['tax_class'];
    208232
    209233        // If manage stock is "parent", then really it means "No".
     
    247271                $filter['from'] = 0;
    248272            }
    249             if( empty( $filter['to'] ) ) {
    250                 $filter['to'] = PHP_INT_MAX;
     273
     274            if( empty( $filter['to'] ) && ( isset( $filter['to'] ) && '0' !== $filter['to'] ) ) {
     275                $filter['to'] = $filter['from'];
    251276            }
    252277
     
    268293            }
    269294
     295            $numeric_post_fields = [
     296                'id' => 'ID',
     297                'parent_id' => 'post_parent',
     298                'menu_order' => 'menu_order',
     299            ];
     300
     301            // When searching by empty value, we need to use different query.
     302            // Continue after adding filter.
    270303            if ( ! empty( $filter['mode'] ) && 'empty' === $filter['mode'] ) {
    271304                if( 'name' === $key ) {
    272305                    add_filter( 'posts_where', [ new FilterByBetween(" AND ({$wpdb->prefix}posts.post_title IS NULL OR {$wpdb->prefix}posts.post_title = '')", array()), 'filter' ]);
     306                } else if ( array_key_exists( $key, $numeric_post_fields ) ) {
     307                    $field = $numeric_post_fields[ $key ];
     308                    add_filter( 'posts_where', [ new FilterByBetween(" AND (({$wpdb->prefix}posts.{$field} IS NULL OR {$wpdb->prefix}posts.{$field} = '') AND {$wpdb->prefix}posts.{$field} != 0)", array()), 'filter' ]);
    273309                } else if( 'slug' === $key ) {
    274310                    add_filter( 'posts_where', [ new FilterByBetween(" AND ({$wpdb->prefix}posts.post_name IS NULL OR {$wpdb->prefix}posts.post_name = '')", array()), 'filter' ]);
     
    290326                        ]
    291327                    );
    292                 } else if( in_array( $key, [ '_sku', '_regular_price', '_sale_price', '_stock' ], true) ) {
    293                     $query_args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok.
    294                         $query_args,
    295                         [
    296                             'relation' => 'OR',
    297                             [
    298                                'key' => $key,
    299                                'value' => '',
    300                                'compare' => '=',
    301                             ],
    302                             [
    303                                 'key' => $key,
    304                                 'value' => '0',
    305                                 'compare' => '=',
    306                              ],
    307                             [
    308                                 'key' => $key,
    309                                 'compare' => 'NOT EXISTS',
    310                                 'value' => 'null',
    311                             ]
    312                         ]
    313                     );
    314328                } else {
    315329                    $query_args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok.
    316330                        $query_args,
    317                         [
    318                             'relation' => 'OR',
    319                             [
    320                                'key' => $key,
    321                                'value' => '',
    322                                'compare' => '=',
    323                             ],
    324                             [
    325                                 'key' => $key,
    326                                 'value' => '0',
    327                                 'compare' => '=',
    328                              ],
    329                             [
    330                                 'key' => $key,
    331                                 'compare' => 'NOT EXISTS',
    332                                 'value' => 'null',
    333                             ]
    334                         ]
     331                        $this->get_empty_meta_query( $key )
    335332                    );
    336333                }
     
    338335            }
    339336
    340             if( 'id' === $key ) {
    341                 add_filter( 'posts_where', [ new FilterByBetween(" AND {$wpdb->prefix}posts.ID BETWEEN %d AND %d", array( floatval($filter['from']), floatval($filter['to']) )), 'filter' ]);
     337            // Otherwise, we can use standard query.
     338            if ( array_key_exists( $key, $numeric_post_fields ) ) {
     339                $field = $numeric_post_fields[ $key ];
     340                add_filter( 'posts_where', [ new FilterByBetween(" AND {$wpdb->prefix}posts.{$field} BETWEEN %d AND %d", array( floatval($filter['from']), floatval($filter['to']) )), 'filter' ]);
    342341            } else if( 'type' === $key ) {
    343342                if( in_array( 'variation', $filter['query'], true ) ) {
     
    353352                    );
    354353                }
    355             } else if( 'parent_id' === $key ) {
    356                 add_filter( 'posts_where', [ new FilterByBetween(" AND {$wpdb->prefix}posts.post_parent BETWEEN %d AND %d", array( floatval($filter['from']), floatval($filter['to']) )), 'filter' ]);
    357354            } else if( 'name' === $key ) {
    358355                add_filter( 'posts_where', [ new FilterByBetween(" AND {$wpdb->prefix}posts.post_title LIKE %s", array( '%' . $filter['query'] . '%' )), 'filter' ]);
     
    463460                    )
    464461                );
    465             } else if( $filter['type'] === 'numeric' ) {
     462            } else if ( $filter['type'] === 'numeric' ) {
    466463                $query_args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok.
    467464                    $query_args,
    468465                    array(
    469466                        'key'     => $key,
    470                         'value'   => array( floatval($filter['from']), floatval($filter['to']) ),
    471                         'compare' => 'BETWEEN',
     467                        'value'   => array( floatval( $filter['from'] ), floatval( $filter['to'] ) ),
     468                        'compare' => 'BETWEEN',
    472469                    )
     470                );
     471            }
     472
     473            // Special case for tax_class. `'standard` is actually an empty string or not set.
     474            if ( '_tax_class' === $key && in_array( 'standard', $filter['query'] ) ) {
     475                $query_args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok.
     476                    $query_args,
     477                    $this->get_empty_meta_query( $key ),
     478                    'OR'
    473479                );
    474480            }
     
    535541        return $response;
    536542    }
     543
     544    /**
     545     * Get an empty meta query.
     546     *
     547     * @return array
     548     */
     549    protected function get_empty_meta_query( $key ) {
     550        return [
     551            'relation' => 'OR',
     552            [
     553                'key'     => $key,
     554                'value'   => '',
     555                'compare' => '=',
     556            ],
     557            [
     558                'key'     => $key,
     559                'value'   => '0',
     560                'compare' => '=',
     561            ],
     562            [
     563                'key'     => $key,
     564                'compare' => 'NOT EXISTS',
     565                'value'   => 'null',
     566            ],
     567        ];
     568}
    537569
    538570    /**
     
    690722        return implode( ', ', $ids );
    691723    }
     724
     725    /**
     726     * Get a specific product dimension.
     727     *
     728     * @param array  $item Item array.
     729     * @param string $key  Key.
     730     *
     731     * @return string|float
     732     */
     733    public function get_dimension( $item, $key ) {
     734        if ( empty( $item['dimensions'] ) || empty( $item['dimensions'][ $key ] ) ) {
     735            return '';
     736        }
     737
     738        return floatval( $item['dimensions'][ $key ] );
     739    }
     740
     741    /**
     742     * Add meta query.
     743     *
     744     * @param array  $args       Query args.
     745     * @param array  $meta_query Meta query.
     746     * @param string $relation
     747     *
     748     * @return array
     749     */
     750    protected function add_meta_query( $args, $meta_query, $relation = 'AND' ) {
     751        if ( empty( $args['meta_query'] ) ) {
     752            $args['meta_query'] = array();
     753        }
     754
     755        $args['meta_query']['relation'] = $relation;
     756        $args['meta_query'][]           = $meta_query;
     757
     758        return $args['meta_query'];
     759    }
    692760}
  • setary/trunk/setary.php

    r2860687 r2864952  
    1111 * Author URI:           https://setary.com/
    1212 *
    13  * Version:              1.1.0
     13 * Version:              1.2.0
    1414 * WC requires at least: 6.0.0
    1515 * WC tested up to:      7.3.0
     
    2323define( 'SETARY_PATH', \plugin_dir_path( __FILE__ ) );
    2424define( 'SETARY_URL', \plugins_url( '/', __FILE__ ) );
    25 define( 'SETARY_VERSION', '1.1.0' );
     25define( 'SETARY_VERSION', '1.2.0' );
    2626define( 'SETARY_SITE_URL', 'https://setary.com/' );
    2727define( 'SETARY_APP_URL', 'https://setary.com/app/' );
Note: See TracChangeset for help on using the changeset viewer.