@@ 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 |
@@ 870-890 (lines=21) @@ | ||
867 | * @param string $action either 'create' or 'update' |
|
868 | * @throws WC_API_Exception if item ID is not associated with order |
|
869 | */ |
|
870 | protected function set_item( $order, $item_type, $item, $action ) { |
|
871 | global $wpdb; |
|
872 | ||
873 | $set_method = "set_{$item_type}"; |
|
874 | ||
875 | // verify provided line item ID is associated with order |
|
876 | if ( 'update' === $action ) { |
|
877 | ||
878 | $result = $wpdb->get_row( |
|
879 | $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_id = %d AND order_id = %d", |
|
880 | absint( $item['id'] ), |
|
881 | absint( $order->id ) |
|
882 | ) ); |
|
883 | ||
884 | if ( is_null( $result ) ) { |
|
885 | throw new WC_API_Exception( 'woocommerce_invalid_item_id', __( 'Order item ID provided is not associated with order', 'woocommerce' ), 400 ); |
|
886 | } |
|
887 | } |
|
888 | ||
889 | $this->$set_method( $order, $item, $action ); |
|
890 | } |
|
891 | ||
892 | /** |
|
893 | * Create or update a line item |