Skip to content

Commit

Permalink
Merge pull request woocommerce#30179 from fitimvata/trunk
Browse files Browse the repository at this point in the history
[Rest] Refunds add api_restock param to restock items
  • Loading branch information
jonathansadowski authored Jul 1, 2021
2 parents 1de0734 + 482d019 commit 1c1f6fd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function prepare_object_for_database( $request, $creating = false ) {
'reason' => $request['reason'],
'line_items' => $request['line_items'],
'refund_payment' => $request['api_refund'],
'restock_items' => true,
'restock_items' => $request['api_restock'],
)
);

Expand Down Expand Up @@ -110,6 +110,13 @@ public function get_item_schema() {
'readonly' => true,
);

$schema['properties']['api_restock'] = array(
'description' => __( 'When true, refunded items are restocked.', 'woocommerce' ),
'type' => 'boolean',
'context' => array( 'edit' ),
'default' => true,
);

return $schema;
}
}
16 changes: 11 additions & 5 deletions src/Internal/RestApiUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class RestApiUtil {
* [
* "reason" => "",
* "api_refund" => "x",
* "api_restock" => "x",
* "line_items" => [
* "id" => "111",
* "quantity" => 222,
Expand All @@ -35,13 +36,14 @@ class RestApiUtil {
* ...to the internally used format:
*
* [
* "reason" => null, (if it's missing or any empty value, set as null)
* "api_refund" => true, (if it's missing or non-bool, set as "true")
* "line_items" => [ (convert sequential array to associative based on "id")
* "reason" => null, (if it's missing or any empty value, set as null)
* "api_refund" => true, (if it's missing or non-bool, set as "true")
* "api_restock" => true, (if it's missing or non-bool, set as "true")
* "line_items" => [ (convert sequential array to associative based on "id")
* "111" => [
* "qty" => 222, (rename "quantity" to "qty")
* "qty" => 222, (rename "quantity" to "qty")
* "refund_total" => 333,
* "refund_tax" => [ (convert sequential array to associative based on "id" and "refund_total)
* "refund_tax" => [ (convert sequential array to associative based on "id" and "refund_total)
* "444" => 555,...
* ],...
* ]
Expand All @@ -66,6 +68,10 @@ public static function adjust_create_refund_request_parameters( \WP_REST_Request
$request['api_refund'] = true;
}

if ( ! is_bool( $request['api_restock'] ) ) {
$request['api_restock'] = true;
}

if ( empty( $request['line_items'] ) ) {
$request['line_items'] = array();
} else {
Expand Down

0 comments on commit 1c1f6fd

Please sign in to comment.