Changeset 2911370
- Timestamp:
- 05/11/2023 09:46:09 PM (3 years ago)
- Location:
- setary
- Files:
-
- 6 edited
- 1 copied
-
tags/1.6.0 (copied) (copied from setary/trunk)
-
tags/1.6.0/README.md (modified) (2 diffs)
-
tags/1.6.0/inc/class-products-with-variations.php (modified) (2 diffs)
-
tags/1.6.0/setary.php (modified) (2 diffs)
-
trunk/README.md (modified) (2 diffs)
-
trunk/inc/class-products-with-variations.php (modified) (2 diffs)
-
trunk/setary.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
setary/tags/1.6.0/README.md
r2903444 r2911370 5 5 Tested up to: 6.2 6 6 Requires PHP: 7.1 7 Stable tag: 1. 5.07 Stable tag: 1.6.0 8 8 License: MIT 9 9 License URI: https://opensource.org/licenses/MIT … … 77 77 == Changelog == 78 78 79 = v1.6.0 (2023-05-11) = 80 * [new] Enable sorting by ID, Name, or SKU 81 79 82 = v1.5.0 (2023-04-24) = 80 83 * [new] Batch updates endpoint - improves performance dramatically -
setary/tags/1.6.0/inc/class-products-with-variations.php
r2874509 r2911370 77 77 78 78 /** 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 /** 79 104 * Add special order query to order variations together with products. 80 105 * 81 * @param mixed $orderby_statement 106 * @param string $orderby_statement 107 * @param WP_Query $query 108 * 82 109 * @return string 83 110 */ 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 86 131 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; 87 176 } 88 177 … … 582 671 } 583 672 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 ); 585 675 586 676 $this->_fields = [ 'id' ]; -
setary/tags/1.6.0/setary.php
r2903444 r2911370 11 11 * Author URI: https://setary.com/ 12 12 * 13 * Version: 1. 5.013 * Version: 1.6.0 14 14 * WC requires at least: 6.0.0 15 * WC tested up to: 7. 6.015 * WC tested up to: 7.7.0 16 16 * 17 17 * @package Setary … … 23 23 define( 'SETARY_PATH', \plugin_dir_path( __FILE__ ) ); 24 24 define( 'SETARY_URL', \plugins_url( '/', __FILE__ ) ); 25 define( 'SETARY_VERSION', '1. 5.0' );25 define( 'SETARY_VERSION', '1.6.0' ); 26 26 define( 'SETARY_SITE_URL', 'https://setary.com/' ); 27 27 define( 'SETARY_APP_URL', 'https://setary.com/app/' ); -
setary/trunk/README.md
r2903444 r2911370 5 5 Tested up to: 6.2 6 6 Requires PHP: 7.1 7 Stable tag: 1. 5.07 Stable tag: 1.6.0 8 8 License: MIT 9 9 License URI: https://opensource.org/licenses/MIT … … 77 77 == Changelog == 78 78 79 = v1.6.0 (2023-05-11) = 80 * [new] Enable sorting by ID, Name, or SKU 81 79 82 = v1.5.0 (2023-04-24) = 80 83 * [new] Batch updates endpoint - improves performance dramatically -
setary/trunk/inc/class-products-with-variations.php
r2874509 r2911370 77 77 78 78 /** 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 /** 79 104 * Add special order query to order variations together with products. 80 105 * 81 * @param mixed $orderby_statement 106 * @param string $orderby_statement 107 * @param WP_Query $query 108 * 82 109 * @return string 83 110 */ 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 86 131 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; 87 176 } 88 177 … … 582 671 } 583 672 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 ); 585 675 586 676 $this->_fields = [ 'id' ]; -
setary/trunk/setary.php
r2903444 r2911370 11 11 * Author URI: https://setary.com/ 12 12 * 13 * Version: 1. 5.013 * Version: 1.6.0 14 14 * WC requires at least: 6.0.0 15 * WC tested up to: 7. 6.015 * WC tested up to: 7.7.0 16 16 * 17 17 * @package Setary … … 23 23 define( 'SETARY_PATH', \plugin_dir_path( __FILE__ ) ); 24 24 define( 'SETARY_URL', \plugins_url( '/', __FILE__ ) ); 25 define( 'SETARY_VERSION', '1. 5.0' );25 define( 'SETARY_VERSION', '1.6.0' ); 26 26 define( 'SETARY_SITE_URL', 'https://setary.com/' ); 27 27 define( 'SETARY_APP_URL', 'https://setary.com/app/' );
Note: See TracChangeset
for help on using the changeset viewer.