@@ 874-893 (lines=20) @@ | ||
871 | * @param string $action either 'create' or 'update' |
|
872 | * @throws WC_REST_Exception If item ID is not associated with order |
|
873 | */ |
|
874 | protected function set_item( $order, $item_type, $item, $action ) { |
|
875 | global $wpdb; |
|
876 | ||
877 | $set_method = 'set_' . $item_type; |
|
878 | ||
879 | // Verify provided line item ID is associated with order. |
|
880 | if ( 'update' === $action ) { |
|
881 | $result = $wpdb->get_row( |
|
882 | $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_id = %d AND order_id = %d", |
|
883 | absint( $item['id'] ), |
|
884 | absint( $order->id ) |
|
885 | ) ); |
|
886 | ||
887 | if ( is_null( $result ) ) { |
|
888 | throw new WC_REST_Exception( 'woocommerce_rest_invalid_item_id', __( 'Order item ID provided is not associated with order.', 'woocommerce' ), 400 ); |
|
889 | } |
|
890 | } |
|
891 | ||
892 | $this->$set_method( $order, $item, $action ); |
|
893 | } |
|
894 | ||
895 | /** |
|
896 | * Helper method to check if the resource ID associated with the provided item is null. |
@@ 877-896 (lines=20) @@ | ||
874 | * @param string $action either 'create' or 'update' |
|
875 | * @throws WC_CLI_Exception if item ID is not associated with order |
|
876 | */ |
|
877 | protected function set_item( $order, $item_type, $item, $action ) { |
|
878 | global $wpdb; |
|
879 | ||
880 | $set_method = "set_{$item_type}"; |
|
881 | ||
882 | // verify provided line item ID is associated with order |
|
883 | if ( 'update' === $action ) { |
|
884 | $result = $wpdb->get_row( |
|
885 | $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_id = %d AND order_id = %d", |
|
886 | absint( $item['id'] ), |
|
887 | absint( $order->id ) |
|
888 | ) ); |
|
889 | ||
890 | if ( is_null( $result ) ) { |
|
891 | throw new WC_CLI_Exception( 'woocommerce_invalid_item_id', __( 'Order item ID provided is not associated with order', 'woocommerce' ) ); |
|
892 | } |
|
893 | } |
|
894 | ||
895 | $this->$set_method( $order, $item, $action ); |
|
896 | } |
|
897 | ||
898 | /** |
|
899 | * Create or update a line item |