| @@ 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 |
|
| @@ 854-873 (lines=20) @@ | ||
| 851 | * @param string $action either 'create' or 'update' |
|
| 852 | * @throws WC_REST_Exception If item ID is not associated with order |
|
| 853 | */ |
|
| 854 | protected function set_item( $order, $item_type, $item, $action ) { |
|
| 855 | global $wpdb; |
|
| 856 | ||
| 857 | $set_method = 'set_' . $item_type; |
|
| 858 | ||
| 859 | // Verify provided line item ID is associated with order. |
|
| 860 | if ( 'update' === $action ) { |
|
| 861 | $result = $wpdb->get_row( |
|
| 862 | $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_id = %d AND order_id = %d", |
|
| 863 | absint( $item['id'] ), |
|
| 864 | absint( $order->id ) |
|
| 865 | ) ); |
|
| 866 | ||
| 867 | if ( is_null( $result ) ) { |
|
| 868 | throw new WC_REST_Exception( 'woocommerce_rest_invalid_item_id', __( 'Order item ID provided is not associated with order.', 'woocommerce' ), 400 ); |
|
| 869 | } |
|
| 870 | } |
|
| 871 | ||
| 872 | $this->$set_method( $order, $item, $action ); |
|
| 873 | } |
|
| 874 | ||
| 875 | /** |
|
| 876 | * Helper method to check if the resource ID associated with the provided item is null. |
|
| @@ 827-847 (lines=21) @@ | ||
| 824 | * @param string $action either 'create' or 'update' |
|
| 825 | * @throws WC_API_Exception if item ID is not associated with order |
|
| 826 | */ |
|
| 827 | protected function set_item( $order, $item_type, $item, $action ) { |
|
| 828 | global $wpdb; |
|
| 829 | ||
| 830 | $set_method = "set_{$item_type}"; |
|
| 831 | ||
| 832 | // verify provided line item ID is associated with order |
|
| 833 | if ( 'update' === $action ) { |
|
| 834 | ||
| 835 | $result = $wpdb->get_row( |
|
| 836 | $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_id = %d AND order_id = %d", |
|
| 837 | absint( $item['id'] ), |
|
| 838 | absint( $order->id ) |
|
| 839 | ) ); |
|
| 840 | ||
| 841 | if ( is_null( $result ) ) { |
|
| 842 | throw new WC_API_Exception( 'woocommerce_invalid_item_id', __( 'Order item ID provided is not associated with order', 'woocommerce' ), 400 ); |
|
| 843 | } |
|
| 844 | } |
|
| 845 | ||
| 846 | $this->$set_method( $order, $item, $action ); |
|
| 847 | } |
|
| 848 | ||
| 849 | /** |
|
| 850 | * 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 |
|