Plugin Directory

Changeset 2911370


Ignore:
Timestamp:
05/11/2023 09:46:09 PM (3 years ago)
Author:
setaryapp
Message:

Update to version 1.6.0 from GitHub

Location:
setary
Files:
6 edited
1 copied

Legend:

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

    r2903444 r2911370  
    55Tested up to: 6.2
    66Requires PHP: 7.1
    7 Stable tag: 1.5.0
     7Stable tag: 1.6.0
    88License: MIT
    99License URI: https://opensource.org/licenses/MIT
     
    7777== Changelog ==
    7878
     79= v1.6.0 (2023-05-11) =
     80* [new] Enable sorting by ID, Name, or SKU
     81
    7982= v1.5.0 (2023-04-24) =
    8083* [new] Batch updates endpoint - improves performance dramatically
  • setary/tags/1.6.0/inc/class-products-with-variations.php

    r2874509 r2911370  
    7777
    7878    /**
     79     * Add post_meta table to query if we're sorting by meta.
     80     *
     81     * @param string   $join
     82     * @param WP_Query $query
     83     *
     84     * @return string
     85     */
     86    public function edit_posts_join( $join, $query ) {
     87        $sort_option = $this->get_sort_option();
     88
     89        // No need to add post_meta if the sort is a post table method.
     90        if ( ! $sort_option || $sort_option['post_table_orderby'] ) {
     91            return $join;
     92        }
     93
     94        // Check if this is the query you want to modify
     95        global $wpdb;
     96
     97        // Join the postmeta table with the main query
     98        $join .= " LEFT JOIN {$wpdb->postmeta} ON {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_sku'";
     99
     100        return $join;
     101    }
     102
     103    /**
    79104     * Add special order query to order variations together with products.
    80105     *
    81      * @param mixed $orderby_statement
     106     * @param string   $orderby_statement
     107     * @param WP_Query $query
     108     *
    82109     * @return string
    83110     */
    84     public function edit_posts_orderby( $orderby_statement ) {
    85         $orderby_statement = 'IF(post_parent > 0, post_parent, id), id ASC';
     111    public function edit_posts_orderby( $orderby_statement, $query ) {
     112        // Default order by, post ID and then variations.
     113        $orderby_statement = 'IF(post_parent > 0, post_parent, id) ASC';
     114        $sort_option       = $this->get_sort_option();
     115
     116        if ( ! $sort_option ) {
     117            return $orderby_statement;
     118        }
     119
     120        global $wpdb;
     121
     122        if ( $sort_option['post_table_orderby'] ) {
     123            $orderby_statement = "{$sort_option['post_table_orderby']} {$sort_option['order']}";
     124        } else {
     125            $orderby_statement = $wpdb->prepare(
     126                "CASE WHEN {$wpdb->postmeta}.meta_key = %s THEN {$wpdb->postmeta}.meta_value ELSE {$wpdb->posts}.ID END {$sort_option['order']}",
     127                $sort_option['orderby']
     128            );
     129        }
     130
    86131        return $orderby_statement;
     132    }
     133
     134    /**
     135     * Get sort option from filters.
     136     *
     137     * @return array|false
     138     */
     139    public function get_sort_option() {
     140        static $sort_option = null;
     141
     142        if ( ! is_null( $sort_option ) ) {
     143            return $sort_option;
     144        }
     145
     146        $sort_option = false;
     147
     148        if ( empty( $this->filters ) ) {
     149            return $sort_option;
     150        }
     151
     152        $post_table_orderby_map = array(
     153            'id'        => 'id',
     154            'parent_id' => 'post_parent',
     155            'name'      => 'post_title',
     156        );
     157
     158        foreach ( $this->filters as $filter ) {
     159            if ( empty( $filter['sortOption'] ) ) {
     160                continue;
     161            }
     162
     163            $orderby            = isset( $filter['filterData'] ) ? $filter['filterData'] : $filter['data'];
     164            $post_table_orderby = isset( $post_table_orderby_map[ $orderby ] ) ? $post_table_orderby_map[ $orderby ] : false;
     165
     166            $sort_option = array(
     167                'order'              => $filter['sortOption'],
     168                'orderby'            => $orderby,
     169                'post_table_orderby' => $post_table_orderby,
     170            );
     171
     172            break;
     173        }
     174
     175        return $sort_option;
    87176    }
    88177
     
    582671        }
    583672
    584         add_filter( 'posts_orderby', [ $this, 'edit_posts_orderby' ] );
     673        add_filter('posts_join', [ $this, 'edit_posts_join' ], 10, 2);
     674        add_filter( 'posts_orderby', [ $this, 'edit_posts_orderby' ], 10, 2 );
    585675
    586676        $this->_fields = [ 'id' ];
  • setary/tags/1.6.0/setary.php

    r2903444 r2911370  
    1111 * Author URI:           https://setary.com/
    1212 *
    13  * Version:              1.5.0
     13 * Version:              1.6.0
    1414 * WC requires at least: 6.0.0
    15  * WC tested up to:      7.6.0
     15 * WC tested up to:      7.7.0
    1616 *
    1717 * @package              Setary
     
    2323define( 'SETARY_PATH', \plugin_dir_path( __FILE__ ) );
    2424define( 'SETARY_URL', \plugins_url( '/', __FILE__ ) );
    25 define( 'SETARY_VERSION', '1.5.0' );
     25define( 'SETARY_VERSION', '1.6.0' );
    2626define( 'SETARY_SITE_URL', 'https://setary.com/' );
    2727define( 'SETARY_APP_URL', 'https://setary.com/app/' );
  • setary/trunk/README.md

    r2903444 r2911370  
    55Tested up to: 6.2
    66Requires PHP: 7.1
    7 Stable tag: 1.5.0
     7Stable tag: 1.6.0
    88License: MIT
    99License URI: https://opensource.org/licenses/MIT
     
    7777== Changelog ==
    7878
     79= v1.6.0 (2023-05-11) =
     80* [new] Enable sorting by ID, Name, or SKU
     81
    7982= v1.5.0 (2023-04-24) =
    8083* [new] Batch updates endpoint - improves performance dramatically
  • setary/trunk/inc/class-products-with-variations.php

    r2874509 r2911370  
    7777
    7878    /**
     79     * Add post_meta table to query if we're sorting by meta.
     80     *
     81     * @param string   $join
     82     * @param WP_Query $query
     83     *
     84     * @return string
     85     */
     86    public function edit_posts_join( $join, $query ) {
     87        $sort_option = $this->get_sort_option();
     88
     89        // No need to add post_meta if the sort is a post table method.
     90        if ( ! $sort_option || $sort_option['post_table_orderby'] ) {
     91            return $join;
     92        }
     93
     94        // Check if this is the query you want to modify
     95        global $wpdb;
     96
     97        // Join the postmeta table with the main query
     98        $join .= " LEFT JOIN {$wpdb->postmeta} ON {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_sku'";
     99
     100        return $join;
     101    }
     102
     103    /**
    79104     * Add special order query to order variations together with products.
    80105     *
    81      * @param mixed $orderby_statement
     106     * @param string   $orderby_statement
     107     * @param WP_Query $query
     108     *
    82109     * @return string
    83110     */
    84     public function edit_posts_orderby( $orderby_statement ) {
    85         $orderby_statement = 'IF(post_parent > 0, post_parent, id), id ASC';
     111    public function edit_posts_orderby( $orderby_statement, $query ) {
     112        // Default order by, post ID and then variations.
     113        $orderby_statement = 'IF(post_parent > 0, post_parent, id) ASC';
     114        $sort_option       = $this->get_sort_option();
     115
     116        if ( ! $sort_option ) {
     117            return $orderby_statement;
     118        }
     119
     120        global $wpdb;
     121
     122        if ( $sort_option['post_table_orderby'] ) {
     123            $orderby_statement = "{$sort_option['post_table_orderby']} {$sort_option['order']}";
     124        } else {
     125            $orderby_statement = $wpdb->prepare(
     126                "CASE WHEN {$wpdb->postmeta}.meta_key = %s THEN {$wpdb->postmeta}.meta_value ELSE {$wpdb->posts}.ID END {$sort_option['order']}",
     127                $sort_option['orderby']
     128            );
     129        }
     130
    86131        return $orderby_statement;
     132    }
     133
     134    /**
     135     * Get sort option from filters.
     136     *
     137     * @return array|false
     138     */
     139    public function get_sort_option() {
     140        static $sort_option = null;
     141
     142        if ( ! is_null( $sort_option ) ) {
     143            return $sort_option;
     144        }
     145
     146        $sort_option = false;
     147
     148        if ( empty( $this->filters ) ) {
     149            return $sort_option;
     150        }
     151
     152        $post_table_orderby_map = array(
     153            'id'        => 'id',
     154            'parent_id' => 'post_parent',
     155            'name'      => 'post_title',
     156        );
     157
     158        foreach ( $this->filters as $filter ) {
     159            if ( empty( $filter['sortOption'] ) ) {
     160                continue;
     161            }
     162
     163            $orderby            = isset( $filter['filterData'] ) ? $filter['filterData'] : $filter['data'];
     164            $post_table_orderby = isset( $post_table_orderby_map[ $orderby ] ) ? $post_table_orderby_map[ $orderby ] : false;
     165
     166            $sort_option = array(
     167                'order'              => $filter['sortOption'],
     168                'orderby'            => $orderby,
     169                'post_table_orderby' => $post_table_orderby,
     170            );
     171
     172            break;
     173        }
     174
     175        return $sort_option;
    87176    }
    88177
     
    582671        }
    583672
    584         add_filter( 'posts_orderby', [ $this, 'edit_posts_orderby' ] );
     673        add_filter('posts_join', [ $this, 'edit_posts_join' ], 10, 2);
     674        add_filter( 'posts_orderby', [ $this, 'edit_posts_orderby' ], 10, 2 );
    585675
    586676        $this->_fields = [ 'id' ];
  • setary/trunk/setary.php

    r2903444 r2911370  
    1111 * Author URI:           https://setary.com/
    1212 *
    13  * Version:              1.5.0
     13 * Version:              1.6.0
    1414 * WC requires at least: 6.0.0
    15  * WC tested up to:      7.6.0
     15 * WC tested up to:      7.7.0
    1616 *
    1717 * @package              Setary
     
    2323define( 'SETARY_PATH', \plugin_dir_path( __FILE__ ) );
    2424define( 'SETARY_URL', \plugins_url( '/', __FILE__ ) );
    25 define( 'SETARY_VERSION', '1.5.0' );
     25define( 'SETARY_VERSION', '1.6.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.