Skip to content

Commit

Permalink
fix POS Only bulk edit
Browse files Browse the repository at this point in the history
  • Loading branch information
kilbot committed Jul 7, 2023
1 parent 170a38e commit 0f97f40
Show file tree
Hide file tree
Showing 17 changed files with 464 additions and 414 deletions.
93 changes: 61 additions & 32 deletions includes/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,63 +9,92 @@ class AJAX {
*
* @var string[]
*/
private $product_actions = array(
'load_variations',
'save_variations',
private $single_product_actions = array(
'woocommerce_load_variations',
'woocommerce_save_variations',
);

/**
* WooCommerce AJAX actions that we need to hook into on the Product admin pages.
*
* @var string[]
*/
private $list_products_actions = array(
// 'inline-save', // this is a core WordPress action and it won't call our hook
);

/**
* WooCommerce AJAX actions that we need to hook into on the Order admin pages.
*
* @var string[]
*/
private $order_actions = array(
'add_order_item',
'add_order_fee',
'add_order_shipping',
'add_order_tax',
'add_coupon_discount',
'remove_order_coupon',
'remove_order_item',
'remove_order_tax',
'calc_line_taxes',
'save_order_items',
'load_order_items',
'get_order_details',
'woocommerce_add_order_item',
'woocommerce_add_order_fee',
'woocommerce_add_order_shipping',
'woocommerce_add_order_tax',
'woocommerce_add_coupon_discount',
'woocommerce_remove_order_coupon',
'woocommerce_remove_order_item',
'woocommerce_remove_order_tax',
'woocommerce_calc_line_taxes',
'woocommerce_save_order_items',
'woocommerce_load_order_items',
'woocommerce_get_order_details',
);

/**
*
*/
public function __construct() {
$this->woocommerce_ajax_actions();
}
if ( ! isset( $_POST['action'] ) ) {
return;
}

/**
*
*/
private function woocommerce_ajax_actions() {
foreach ( $this->product_actions as $ajax_event ) {
add_action( 'wp_ajax_woocommerce_' . $ajax_event, array( $this, 'woocommerce_product_ajax' ), 9, 0 );
}
foreach ( $this->order_actions as $ajax_event ) {
add_action( 'wp_ajax_woocommerce_' . $ajax_event, array( $this, 'woocommerce_order_ajax' ), 9, 0 );
}
}
if ( $_POST['action'] == 'heartbeat' ) {
return;
}

foreach ( $this->single_product_actions as $ajax_event ) {
add_action( 'wp_ajax_' . $ajax_event, array( $this, 'load_single_product_class' ), 9 );
}
foreach ( $this->list_products_actions as $ajax_event ) {
add_action( 'wp_ajax_' . $ajax_event, array( $this, 'load_list_products_class' ), 9 );
}
foreach ( $this->order_actions as $ajax_event ) {
add_action( 'wp_ajax_' . $ajax_event, array( $this, 'load_orders_class' ), 9 );
}

// we need to hook into these actions to save our custom fields via AJAX
add_action( 'woocommerce_product_quick_edit_save',
array(
'\WCPOS\WooCommercePOS\Admin\Products\List_Products',
'quick_edit_save',
)
);
}

/**
* The Admin\Products class is not loaded for AJAX requests.
* The Admin\Products\Single_Product class is not loaded for AJAX requests.
* We need to load it manually here.
*/
public function woocommerce_product_ajax() {
new Admin\Products();
public function load_single_product_class() {
new Admin\Products\Single_Product();
}

/**
* The Admin\Products\List_Products class is not loaded for AJAX requests.
* We need to load it manually here.
*/
public function load_list_products_class() {
//
}

/**
* The Admin\Orders class is not loaded for AJAX requests.
* We need to load it manually here.
*/
public function woocommerce_order_ajax() {
public function load_orders_class() {
new Admin\Orders();
}

Expand Down
35 changes: 20 additions & 15 deletions includes/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,29 @@ public function admin_menu( $context ): void {
* @param $current_screen
*/
public function current_screen( $current_screen ): void {
// Add setting to permalink page
if ( 'options-permalink' == $current_screen->id ) {
new Admin\Permalink();
}

// Edit products page
if ( 'product' == $current_screen->id ) {
new Admin\Products();
}
switch ( $current_screen->id ) {
case 'options-permalink': // Add setting to permalink page
new Admin\Permalink();
break;

// Add POS settings to orders pages
if ( $current_screen->id == 'shop_order' || $current_screen->id == 'edit-shop_order' ) {
new Admin\Orders();
}
case 'product': // Single product page
new Admin\Products\Single_Product();
break;

case 'edit-product': // List products page
new Admin\Products\List_Products();
break;

case 'shop_order': // Add POS settings to orders pages
case 'edit-shop_order': // Add POS settings to orders pages
new Admin\Orders();
break;

case 'plugins': // Customise plugins page
new Admin\Plugins();
break;

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

// Load the Settings class
Expand Down
7 changes: 7 additions & 0 deletions includes/Admin/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public function wc_order_is_editable( bool $is_editable, WC_Order $order ): bool
return $is_editable;
}

/**
*
*/
public function order_filter_dropdown() {
$selected = isset( $_GET['pos_order'] ) ? $_GET['pos_order'] : '';

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

/**
* @param WP_Query $query
* @return void
*/
public function parse_query( WP_Query $query ) {
if ( isset( $_GET['pos_order'] ) && $_GET['pos_order'] != '' ) {
$meta_query = array( 'relation' => 'AND' );
Expand Down
Loading

0 comments on commit 0f97f40

Please sign in to comment.