From c19c6883d93aa70483a7319bb6d20dd99990eedc Mon Sep 17 00:00:00 2001 From: Saiful Islam Date: Thu, 8 Sep 2022 12:53:07 +0600 Subject: [PATCH 1/2] Pagination issue has been solved --- assets/js/wpt-control.js | 9 ++++++--- inc/handle/pagination.php | 6 +++--- inc/shortcode-ajax.php | 13 +++++++++++++ inc/shortcode-base.php | 10 +++++++++- inc/shortcode.php | 7 +++---- 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/assets/js/wpt-control.js b/assets/js/wpt-control.js index 5e40a0a8..13325ed5 100644 --- a/assets/js/wpt-control.js +++ b/assets/js/wpt-control.js @@ -31,7 +31,7 @@ jQuery(function($) { url: ajax_url, data: data, success:function(result){ - // $('.wpt_edit_table').html(result); + $('.wpt_edit_table').html(result); if ( result ) { $.each( result, function( key, value ) { if('string' === typeof key){ @@ -64,7 +64,6 @@ jQuery(function($) { var table_id = thisPagination.data('table_id'); var args = getSearchQueriedArgs( table_id ); - console.log(args); ajaxTableLoad(table_id, args, page_number ); @@ -82,7 +81,10 @@ jQuery(function($) { }); function getSearchQueriedArgs( table_id ){ - let value,key; + let value,key,base_link; + + //On ajax search, Page link shown with ajax link, we will send this base link, so that always can get smart link + base_link = $('.wpt-my-pagination-' + table_id ).data('base_link'); var texonomies = {}; value = false; $('#search_box_' + table_id + ' .search_select.query').each(function(){ @@ -146,6 +148,7 @@ jQuery(function($) { s: s, tax_query: tax_query, meta_query: meta_query, + base_link:base_link, }; return args; } diff --git a/inc/handle/pagination.php b/inc/handle/pagination.php index 1f95ceb9..fce8dcda 100644 --- a/inc/handle/pagination.php +++ b/inc/handle/pagination.php @@ -5,8 +5,9 @@ class Pagination{ public static function render( Shortcode $shortcode ){ + ?> -
+
@@ -18,13 +19,12 @@ public static function render( Shortcode $shortcode ){ public static function get_paginate_links( Shortcode $shortcode ){ $args = $shortcode->args; $product_loop = new \WP_Query($args); - $big = 99999999; /** * @Hook Filter for pagination */ $paginate_args = apply_filters('wpt_paginate_args', array( - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), + 'base' => $shortcode->pagination_base_url, 'format' => apply_filters( 'wpto_pagination_format', '?paged=%#%', $args ), 'mid_size' => 3, 'prev_next' => false, diff --git a/inc/shortcode-ajax.php b/inc/shortcode-ajax.php index 0a980ea8..33499e40 100644 --- a/inc/shortcode-ajax.php +++ b/inc/shortcode-ajax.php @@ -43,6 +43,19 @@ public function wpt_load_both(){ $page_number = $_POST['page_number'] ?? $this->page_number; + + /** + * Actually base link is not part of Args. but we take it + * using args when call ajax + * to set right link + * on pagination. otherwise, it was shown link + * like: example.com/wp-admin/wp-ajax.php?page=2 + * + * but now it wll show page linke: example.com/page/2 + * @since 3.2.5.2 + */ + $this->pagination_base_url = $_POST['args']['base_link'] ?? null; + $this->args['paged'] = $this->page_number = $page_number; /** diff --git a/inc/shortcode-base.php b/inc/shortcode-base.php index 211b34cd..cc33fe46 100644 --- a/inc/shortcode-base.php +++ b/inc/shortcode-base.php @@ -9,6 +9,8 @@ class Shortcode_Base extends Base{ public $items_directory; public $items_permanent_dir; + public $data; + protected function unsetArrayItem( Array $arr, $unset_item ){ if( ! isset( $arr[$unset_item] ) ) return $arr; @@ -40,5 +42,11 @@ public function get_meta( string $meta_key ){ return is_array( $data ) ? $data : []; } - + public function __get( $name ){ + return $this->data[$name] ?? null; + } + + public function __set($name, $value){ + $this->data[$name] = $value; + } } \ No newline at end of file diff --git a/inc/shortcode.php b/inc/shortcode.php index feccb31f..d0af7bfc 100644 --- a/inc/shortcode.php +++ b/inc/shortcode.php @@ -199,6 +199,9 @@ class=""> pagination ){ + $big = 99999999; + $this->pagination_base_url = str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ); + Pagination::render( $this ); } @@ -486,10 +489,6 @@ protected function table_head(){ args , $this->table_id, ['args' => $this->args]); - } /** * Basically for main search box and Meta field wise search box. From 9e40c160b21e5cb2facb9f1f95c8659352216778 Mon Sep 17 00:00:00 2001 From: Saiful Islam Date: Thu, 8 Sep 2022 14:35:57 +0600 Subject: [PATCH 2/2] $(document).on('keyup','.wpt_row input.input-text.qty.text', oneSecondDelay(inputBoxChangeHandle,1500)); --- assets/js/custom.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/assets/js/custom.js b/assets/js/custom.js index 333a7655..9cacc883 100644 --- a/assets/js/custom.js +++ b/assets/js/custom.js @@ -1804,8 +1804,12 @@ jQuery(function($) { /** * keyup is actually for total price live changing * When someone type quantity then total price will change live + * if($('#table_id_' + table_id + ' .wpt_total').length > 0){ + inputBoxChangeHandle(); + } */ - $(document).on('keyup','.wpt_row input.input-text.qty.text', inputBoxChangeHandle); + // $(document).on('keyup','.wpt_row input.input-text.qty.text', inputBoxChangeHandle); + $(document).on('keyup','.wpt_row input.input-text.qty.text', oneSecondDelay(inputBoxChangeHandle,1500)); $('body').on('change', '.wpt_row input.input-text.qty.text', inputBoxChangeHandle); function inputBoxChangeHandle() { @@ -1815,12 +1819,12 @@ jQuery(function($) { var thisRow = '#table_id_' + temp_number + ' tr.product_id_' + product_id; - $( thisRow + 'input.input-text.qty.text').val(Qty_Val); // input.input-text.qty.text + $( thisRow + ' input.input-text.qty.text').val(Qty_Val); // input.input-text.qty.text $( thisRow ).attr('data-quantity', Qty_Val); - $( thisRow + 'a.wpt_woo_add_cart_button').attr('data-quantity', Qty_Val); - $( thisRow + 'a.add_to_cart_button').attr('data-quantity', Qty_Val); + $( thisRow + ' a.wpt_woo_add_cart_button').attr('data-quantity', Qty_Val); + $( thisRow + ' a.add_to_cart_button').attr('data-quantity', Qty_Val); var Item_URL = '?add-to-cart=' + product_id + '&quantity=' + Qty_Val; - $( thisRow + 'a.add_to_cart_button').attr('href', Item_URL); + $( thisRow + ' a.add_to_cart_button').attr('href', Item_URL); var targetTotalSelector = $('#table_id_' + temp_number + ' .product_id_' + product_id + ' .wpt_total_item.total_general');