Skip to content

Commit

Permalink
use WC_Abstract_Order type instead of WC_Order
Browse files Browse the repository at this point in the history
  • Loading branch information
kilbot committed Jan 13, 2024
1 parent 346354f commit 2e50c26
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 50 deletions.
3 changes: 0 additions & 3 deletions includes/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ public function __construct() {
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(
Expand Down
32 changes: 17 additions & 15 deletions includes/API/Orders_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use Exception;
use WC_Email_Customer_Invoice;
use WC_Order;
use WC_Abstract_Order;
use WC_Order_Query;
use WC_REST_Orders_Controller;
use WCPOS\WooCommercePOS\Logger;
Expand Down Expand Up @@ -343,13 +343,13 @@ public function wcpos_send_email_permissions_check() {
}

/**
* @param string $recipient
* @param WC_Order $order
* @param WC_Email_Customer_Invoice $WC_Email_Customer_Invoice
* @param string $recipient.
* @param WC_Abstract_Order $order.
* @param WC_Email_Customer_Invoice $WC_Email_Customer_Invoice.
*
* @return string
*/
public function wcpos_recipient_email_address( string $recipient, WC_Order $order, WC_Email_Customer_Invoice $WC_Email_Customer_Invoice ) {
public function wcpos_recipient_email_address( string $recipient, WC_Abstract_Order $order, WC_Email_Customer_Invoice $WC_Email_Customer_Invoice ) {
return $this->wcpos_request['email'];
}

Expand Down Expand Up @@ -435,13 +435,13 @@ public function wcpos_register_wc_rest_api_hooks( WP_REST_Request $request ): vo
}

/**
* @param WP_REST_Response $response The response object.
* @param WC_Order $order Object data.
* @param WP_REST_Request $request Request object.
* @param WP_REST_Response $response The response object.
* @param WC_Abstract_Order $order Object data.
* @param WP_REST_Request $request Request object.
*
* @return WP_REST_Response
*/
public function wcpos_order_response( WP_REST_Response $response, WC_Order $order, WP_REST_Request $request ): WP_REST_Response {
public function wcpos_order_response( WP_REST_Response $response, WC_Abstract_Order $order, WP_REST_Request $request ): WP_REST_Response {
$data = $response->get_data();

// Add UUID to order
Expand Down Expand Up @@ -475,13 +475,15 @@ public function wcpos_order_response( WP_REST_Response $response, WC_Order $orde
/**
* Add UUID to order items.
*
* @param $items WC_Order_Item[]
* @param $order WC_Order
* @param $item_type string[] ['line_item' | 'fee' | 'shipping' | 'tax' | 'coupon']
* NOTE: OrderRefund can also be passed
*
* @param WC_Order_Item[] $items The order items.
* @param WC_Abstract_Order $order The order object.
* @param array $item_type string[] ['line_item' | 'fee' | 'shipping' | 'tax' | 'coupon'].
*
* @return WC_Order_Item[]
*/
public function wcpos_order_get_items( array $items, WC_Order $order, array $item_type ): array {
public function wcpos_order_get_items( array $items, WC_Abstract_Order $order, array $item_type ): array {
foreach ( $items as $item ) {
$this->maybe_add_order_item_uuid( $item );
}
Expand All @@ -493,11 +495,11 @@ public function wcpos_order_get_items( array $items, WC_Order $order, array $ite
* Add extra data for woocommerce pos orders.
* - Add custom 'created_via' prop for POS orders, used in WC Admin display.
*
* @param WC_Order $order The object being saved.
* @param WC_Abstract_Order $order The object being saved.
*
* @throws WC_Data_Exception
*/
public function wcpos_before_order_object_save( WC_Order $order ): void {
public function wcpos_before_order_object_save( WC_Abstract_Order $order ): void {
if ( $this->is_creating ) {
$order->set_created_via( PLUGIN_NAME );
}
Expand Down
4 changes: 2 additions & 2 deletions includes/API/Traits/Uuid_Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
namespace WCPOS\WooCommercePOS\API\Traits;

use Exception;
use function get_user_meta;
use Ramsey\Uuid\Uuid;
use function update_user_meta;
use WC_Data;
use WC_Meta_Data;
use WC_Order_Item;
use WCPOS\WooCommercePOS\Logger;
use WP_User;
use function get_user_meta;
use function update_user_meta;

trait Uuid_Handler {
/**
Expand Down
66 changes: 36 additions & 30 deletions includes/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public function __construct() {
$this->register_order_status();
add_filter( 'wc_order_statuses', array( $this, 'wc_order_statuses' ), 10, 1 );
add_filter( 'woocommerce_order_needs_payment', array( $this, 'order_needs_payment' ), 10, 3 );
add_filter( 'woocommerce_valid_order_statuses_for_payment', array($this,'valid_order_statuses_for_payment' ), 10, 2);
add_filter( 'woocommerce_valid_order_statuses_for_payment_complete', array( $this, 'valid_order_statuses_for_payment_complete' ), 10, 2);
add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'payment_complete_order_status' ), 10, 3);
add_filter( 'woocommerce_valid_order_statuses_for_payment', array( $this, 'valid_order_statuses_for_payment' ), 10, 2 );
add_filter( 'woocommerce_valid_order_statuses_for_payment_complete', array( $this, 'valid_order_statuses_for_payment_complete' ), 10, 2 );
add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'payment_complete_order_status' ), 10, 3 );

add_filter( 'woocommerce_hidden_order_itemmeta', array( $this, 'hidden_order_itemmeta' ) );

// order emails
Expand Down Expand Up @@ -151,33 +151,39 @@ public function manage_customer_emails( $enabled, $order, $email_class ) {

private function register_order_status(): void {
// Order status for open orders
register_post_status('wc-pos-open', array(
'label' => _x( 'POS - Open', 'Order status', 'woocommerce-pos' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
// translators: %s is the number of orders with POS - Open status
'label_count' => _n_noop(
'POS - Open <span class="count">(%s)</span>',
'POS - Open <span class="count">(%s)</span>',
'woocommerce-pos'
),
));
register_post_status(
'wc-pos-open',
array(
'label' => _x( 'POS - Open', 'Order status', 'woocommerce-pos' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
// translators: %s is the number of orders with POS - Open status
'label_count' => _n_noop(
'POS - Open <span class="count">(%s)</span>',
'POS - Open <span class="count">(%s)</span>',
'woocommerce-pos'
),
)
);

// Order status for partial payment orders
register_post_status('wc-pos-partial', array(
'label' => _x( 'POS - Partial Payment', 'Order status', 'woocommerce-pos' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
// translators: %s is the number of orders with POS - Partial Payment status
'label_count' => _n_noop(
'POS - Partial Payment <span class="count">(%s)</span>',
'POS - Partial Payment <span class="count">(%s)</span>',
'woocommerce-pos'
),
));
register_post_status(
'wc-pos-partial',
array(
'label' => _x( 'POS - Partial Payment', 'Order status', 'woocommerce-pos' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
// translators: %s is the number of orders with POS - Partial Payment status
'label_count' => _n_noop(
'POS - Partial Payment <span class="count">(%s)</span>',
'POS - Partial Payment <span class="count">(%s)</span>',
'woocommerce-pos'
),
)
);
}
}

0 comments on commit 2e50c26

Please sign in to comment.