Skip to content

Commit 0f97f40

Browse files
committed
fix POS Only bulk edit
1 parent 170a38e commit 0f97f40

17 files changed

+464
-414
lines changed

includes/AJAX.php

Lines changed: 61 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,63 +9,92 @@ class AJAX {
99
*
1010
* @var string[]
1111
*/
12-
private $product_actions = array(
13-
'load_variations',
14-
'save_variations',
12+
private $single_product_actions = array(
13+
'woocommerce_load_variations',
14+
'woocommerce_save_variations',
1515
);
1616

17+
/**
18+
* WooCommerce AJAX actions that we need to hook into on the Product admin pages.
19+
*
20+
* @var string[]
21+
*/
22+
private $list_products_actions = array(
23+
// 'inline-save', // this is a core WordPress action and it won't call our hook
24+
);
25+
1726
/**
1827
* WooCommerce AJAX actions that we need to hook into on the Order admin pages.
1928
*
2029
* @var string[]
2130
*/
2231
private $order_actions = array(
23-
'add_order_item',
24-
'add_order_fee',
25-
'add_order_shipping',
26-
'add_order_tax',
27-
'add_coupon_discount',
28-
'remove_order_coupon',
29-
'remove_order_item',
30-
'remove_order_tax',
31-
'calc_line_taxes',
32-
'save_order_items',
33-
'load_order_items',
34-
'get_order_details',
32+
'woocommerce_add_order_item',
33+
'woocommerce_add_order_fee',
34+
'woocommerce_add_order_shipping',
35+
'woocommerce_add_order_tax',
36+
'woocommerce_add_coupon_discount',
37+
'woocommerce_remove_order_coupon',
38+
'woocommerce_remove_order_item',
39+
'woocommerce_remove_order_tax',
40+
'woocommerce_calc_line_taxes',
41+
'woocommerce_save_order_items',
42+
'woocommerce_load_order_items',
43+
'woocommerce_get_order_details',
3544
);
3645

3746
/**
3847
*
3948
*/
4049
public function __construct() {
41-
$this->woocommerce_ajax_actions();
42-
}
50+
if ( ! isset( $_POST['action'] ) ) {
51+
return;
52+
}
4353

44-
/**
45-
*
46-
*/
47-
private function woocommerce_ajax_actions() {
48-
foreach ( $this->product_actions as $ajax_event ) {
49-
add_action( 'wp_ajax_woocommerce_' . $ajax_event, array( $this, 'woocommerce_product_ajax' ), 9, 0 );
50-
}
51-
foreach ( $this->order_actions as $ajax_event ) {
52-
add_action( 'wp_ajax_woocommerce_' . $ajax_event, array( $this, 'woocommerce_order_ajax' ), 9, 0 );
53-
}
54-
}
54+
if ( $_POST['action'] == 'heartbeat' ) {
55+
return;
56+
}
57+
58+
foreach ( $this->single_product_actions as $ajax_event ) {
59+
add_action( 'wp_ajax_' . $ajax_event, array( $this, 'load_single_product_class' ), 9 );
60+
}
61+
foreach ( $this->list_products_actions as $ajax_event ) {
62+
add_action( 'wp_ajax_' . $ajax_event, array( $this, 'load_list_products_class' ), 9 );
63+
}
64+
foreach ( $this->order_actions as $ajax_event ) {
65+
add_action( 'wp_ajax_' . $ajax_event, array( $this, 'load_orders_class' ), 9 );
66+
}
67+
68+
// we need to hook into these actions to save our custom fields via AJAX
69+
add_action( 'woocommerce_product_quick_edit_save',
70+
array(
71+
'\WCPOS\WooCommercePOS\Admin\Products\List_Products',
72+
'quick_edit_save',
73+
)
74+
);
75+
}
5576

5677
/**
57-
* The Admin\Products class is not loaded for AJAX requests.
78+
* The Admin\Products\Single_Product class is not loaded for AJAX requests.
5879
* We need to load it manually here.
5980
*/
60-
public function woocommerce_product_ajax() {
61-
new Admin\Products();
81+
public function load_single_product_class() {
82+
new Admin\Products\Single_Product();
6283
}
6384

85+
/**
86+
* The Admin\Products\List_Products class is not loaded for AJAX requests.
87+
* We need to load it manually here.
88+
*/
89+
public function load_list_products_class() {
90+
//
91+
}
92+
6493
/**
6594
* The Admin\Orders class is not loaded for AJAX requests.
6695
* We need to load it manually here.
6796
*/
68-
public function woocommerce_order_ajax() {
97+
public function load_orders_class() {
6998
new Admin\Orders();
7099
}
71100

includes/Admin.php

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,29 @@ public function admin_menu( $context ): void {
5555
* @param $current_screen
5656
*/
5757
public function current_screen( $current_screen ): void {
58-
// Add setting to permalink page
59-
if ( 'options-permalink' == $current_screen->id ) {
60-
new Admin\Permalink();
61-
}
6258

63-
// Edit products page
64-
if ( 'product' == $current_screen->id ) {
65-
new Admin\Products();
66-
}
59+
switch ( $current_screen->id ) {
60+
case 'options-permalink': // Add setting to permalink page
61+
new Admin\Permalink();
62+
break;
6763

68-
// Add POS settings to orders pages
69-
if ( $current_screen->id == 'shop_order' || $current_screen->id == 'edit-shop_order' ) {
70-
new Admin\Orders();
71-
}
64+
case 'product': // Single product page
65+
new Admin\Products\Single_Product();
66+
break;
67+
68+
case 'edit-product': // List products page
69+
new Admin\Products\List_Products();
70+
break;
71+
72+
case 'shop_order': // Add POS settings to orders pages
73+
case 'edit-shop_order': // Add POS settings to orders pages
74+
new Admin\Orders();
75+
break;
76+
77+
case 'plugins': // Customise plugins page
78+
new Admin\Plugins();
79+
break;
7280

73-
// Customise plugins page
74-
if ( 'plugins' == $current_screen->id ) {
75-
new Admin\Plugins();
7681
}
7782

7883
// Load the Settings class

includes/Admin/Orders.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public function wc_order_is_editable( bool $is_editable, WC_Order $order ): bool
4646
return $is_editable;
4747
}
4848

49+
/**
50+
*
51+
*/
4952
public function order_filter_dropdown() {
5053
$selected = isset( $_GET['pos_order'] ) ? $_GET['pos_order'] : '';
5154

@@ -64,6 +67,10 @@ public function order_filter_dropdown() {
6467
echo '</select>';
6568
}
6669

70+
/**
71+
* @param WP_Query $query
72+
* @return void
73+
*/
6774
public function parse_query( WP_Query $query ) {
6875
if ( isset( $_GET['pos_order'] ) && $_GET['pos_order'] != '' ) {
6976
$meta_query = array( 'relation' => 'AND' );

0 commit comments

Comments
 (0)