diff --git a/includes/mutation/class-order-create.php b/includes/mutation/class-order-create.php index 6ca4f8e51..8e23ee1c8 100644 --- a/includes/mutation/class-order-create.php +++ b/includes/mutation/class-order-create.php @@ -108,8 +108,11 @@ public static function get_input_fields() { 'type' => 'Boolean', 'description' => __( 'Define if the order is paid. It will set the status to processing and reduce stock items.', 'wp-graphql-woocommerce' ), ], + 'createdVia' => array( + 'type' => 'String', + 'description' => __( 'Order created via', 'wp-graphql-woocommerce' ), + ) ]; - return $input_fields; } @@ -169,7 +172,7 @@ public static function mutate_and_get_payload() { throw new UserError( __( 'Customer ID is invalid.', 'wp-graphql-woocommerce' ) ); } - $order->set_created_via( 'graphql-api' ); + $order->set_created_via( ! empty( $input['createdVia'] ) ? $input['createdVia'] : 'graphql-api' ); $order->set_prices_include_tax( 'yes' === get_option( 'woocommerce_prices_include_tax' ) ); $order->calculate_totals( true ); diff --git a/tests/wpunit/CheckoutMutationTest.php b/tests/wpunit/CheckoutMutationTest.php index 732a65567..258ba73d3 100644 --- a/tests/wpunit/CheckoutMutationTest.php +++ b/tests/wpunit/CheckoutMutationTest.php @@ -85,181 +85,178 @@ function() { ); } - private function getCheckoutMutation() { - return ' - mutation checkout( $input: CheckoutInput! ) { - checkout( input: $input ) { - clientMutationId - order { - id - databaseId - currency - orderVersion - date - modified - status - discountTotal - discountTax - shippingTotal - shippingTax - cartTax - total - totalTax - subtotal - orderNumber - orderKey - createdVia - pricesIncludeTax - parent { - id - } - customer { - id - } - customerIpAddress - customerUserAgent - customerNote - billing { - firstName - lastName - company - address1 - address2 - city - state - postcode - country - email - phone - } - shipping { - firstName - lastName - company - address1 - address2 - city - state - postcode - country - } - paymentMethod - paymentMethodTitle - transactionId - dateCompleted - datePaid - cartHash - shippingAddressMapUrl - hasBillingAddress - hasShippingAddress - isDownloadPermitted - needsShippingAddress - hasDownloadableItem - downloadableItems { - nodes { - url - accessExpires - downloadId - downloadsRemaining - name - product { - databaseId - } - download { - downloadId - } - } - } - needsPayment - needsProcessing - metaData { - key - value - } - couponLines { - nodes { - databaseId - orderId - code - discount - discountTax - coupon { - id - } - } - } - feeLines { - nodes { - databaseId - orderId - amount - name - taxStatus - total - totalTax - taxClass - } - } - shippingLines { - nodes { - databaseId - orderId - methodTitle - total - totalTax - taxClass - } - } - taxLines { - nodes { - rateCode - label - taxTotal - shippingTaxTotal - isCompound - taxRate { - databaseId - } - } - } - lineItems { - nodes { - productId - variationId - quantity - taxClass - subtotal - subtotalTax - total - totalTax - taxStatus - product { - node { - ... on SimpleProduct { - id - } - ... on VariableProduct { - id - } - } - } - variation { - node { - id - } - } - } - } - } - customer { - id - } - result - redirect - } - } - '; - } + private function checkout( $input, $mutation = null ) { + if ( ! $mutation ) { + $mutation = ' + mutation checkout( $input: CheckoutInput! ) { + checkout( input: $input ) { + clientMutationId + order { + id + databaseId + currency + orderVersion + date + modified + status + discountTotal + discountTax + shippingTotal + shippingTax + cartTax + total + totalTax + subtotal + orderNumber + orderKey + createdVia + pricesIncludeTax + parent { + id + } + customer { + id + } + customerIpAddress + customerUserAgent + customerNote + billing { + firstName + lastName + company + address1 + address2 + city + state + postcode + country + email + phone + } + shipping { + firstName + lastName + company + address1 + address2 + city + state + postcode + country + } + paymentMethod + paymentMethodTitle + transactionId + dateCompleted + datePaid + cartHash + shippingAddressMapUrl + hasBillingAddress + hasShippingAddress + isDownloadPermitted + needsShippingAddress + hasDownloadableItem + downloadableItems { + nodes { + url + accessExpires + downloadId + downloadsRemaining + name + product { + databaseId + } + download { + downloadId + } + } + } + needsPayment + needsProcessing + metaData { + key + value + } + couponLines { + nodes { + databaseId + orderId + code + discount + discountTax + coupon { + id + } + } + } + feeLines { + nodes { + databaseId + orderId + amount + name + taxStatus + total + totalTax + taxClass + } + } + shippingLines { + nodes { + databaseId + orderId + methodTitle + total + totalTax + taxClass + } + } + taxLines { + nodes { + rateCode + label + taxTotal + shippingTaxTotal + isCompound + taxRate { + databaseId + } + } + } + lineItems { + nodes { + productId + variationId + quantity + taxClass + subtotal + subtotalTax + total + totalTax + taxStatus + product { + ... on SimpleProduct { + id + } + ... on VariableProduct { + id + } + } + variation { + id + } + } + } + } + customer { + id + } + result + redirect + } + } + '; + } private function getCartQuery() { return ' diff --git a/tests/wpunit/OrderMutationsTest.php b/tests/wpunit/OrderMutationsTest.php index 451eeef27..fc9ab5049 100644 --- a/tests/wpunit/OrderMutationsTest.php +++ b/tests/wpunit/OrderMutationsTest.php @@ -105,6 +105,7 @@ private function orderMutation( $input, $operation_name = 'createOrder', $input_ transactionId dateCompleted datePaid + createdVia cartHash shippingAddressMapUrl hasBillingAddress @@ -483,7 +484,7 @@ public function testUpdateOrderMutation() { ], 'paymentMethod' => 'bacs', 'paymentMethodTitle' => 'Direct Bank Transfer', - 'billing' => [ + 'billing' => array( 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -808,7 +809,7 @@ public function testDeleteOrderMutation() { ], 'paymentMethod' => 'bacs', 'paymentMethodTitle' => 'Direct Bank Transfer', - 'billing' => [ + 'billing' => array( 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -959,7 +960,7 @@ public function testDeleteOrderItemsMutation() { ], 'paymentMethod' => 'bacs', 'paymentMethodTitle' => 'Direct Bank Transfer', - 'billing' => [ + 'billing' => array( 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St',