From 3a0db735e47f7cdcf4c55f231cecb577f1aca76d Mon Sep 17 00:00:00 2001 From: Scott Kennedy Date: Mon, 22 May 2023 21:11:54 +0100 Subject: [PATCH 1/5] Add option to Change the created_via field. Can be useful when WooCommerce is being used from multiply sources. For example, with plugins like Point of Sale for WooCommerce. --- includes/mutation/class-order-create.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/includes/mutation/class-order-create.php b/includes/mutation/class-order-create.php index 6ca4f8e51..42372c734 100644 --- a/includes/mutation/class-order-create.php +++ b/includes/mutation/class-order-create.php @@ -107,8 +107,12 @@ public static function get_input_fields() { 'isPaid' => [ '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 +173,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 ); From c3235c0f39acc25a9aedbfe1e9c0eea66a14d9df Mon Sep 17 00:00:00 2001 From: Scott Kennedy Date: Mon, 22 May 2023 21:12:26 +0100 Subject: [PATCH 2/5] Rebase --- includes/mutation/class-order-create.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/includes/mutation/class-order-create.php b/includes/mutation/class-order-create.php index 42372c734..8e23ee1c8 100644 --- a/includes/mutation/class-order-create.php +++ b/includes/mutation/class-order-create.php @@ -107,13 +107,12 @@ public static function get_input_fields() { 'isPaid' => [ '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; } From c981aecc6801eed13f7f952d0a6e5fecf2895a5c Mon Sep 17 00:00:00 2001 From: Scott Kennedy Date: Mon, 23 Jan 2023 22:39:01 +0000 Subject: [PATCH 3/5] Add createdVia to unit tests --- tests/wpunit/CheckoutMutationTest.php | 347 +++++++++++++------------- tests/wpunit/OrderMutationsTest.php | 1 + 2 files changed, 173 insertions(+), 175 deletions(-) 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..c6f98ba2c 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 From 4563748ed2386bcb59edb1b5d086c33072b64b8a Mon Sep 17 00:00:00 2001 From: Scott Kennedy Date: Mon, 23 Jan 2023 22:41:54 +0000 Subject: [PATCH 4/5] Add createdVia to unit tests --- tests/wpunit/OrderMutationsTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/wpunit/OrderMutationsTest.php b/tests/wpunit/OrderMutationsTest.php index c6f98ba2c..7d828bb9e 100644 --- a/tests/wpunit/OrderMutationsTest.php +++ b/tests/wpunit/OrderMutationsTest.php @@ -239,7 +239,7 @@ public function testCreateOrderMutation() { ], 'paymentMethod' => 'bacs', 'paymentMethodTitle' => 'Direct Bank Transfer', - 'billing' => [ + 'billing' => array( 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -484,7 +484,7 @@ public function testUpdateOrderMutation() { ], 'paymentMethod' => 'bacs', 'paymentMethodTitle' => 'Direct Bank Transfer', - 'billing' => [ + 'billing' => array( 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -809,7 +809,7 @@ public function testDeleteOrderMutation() { ], 'paymentMethod' => 'bacs', 'paymentMethodTitle' => 'Direct Bank Transfer', - 'billing' => [ + 'billing' => array( 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -960,7 +960,7 @@ public function testDeleteOrderItemsMutation() { ], 'paymentMethod' => 'bacs', 'paymentMethodTitle' => 'Direct Bank Transfer', - 'billing' => [ + 'billing' => array( 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', From 8317b394ea7d97a8893d6cf9ae849d5a0da2a752 Mon Sep 17 00:00:00 2001 From: Scott Kennedy Date: Mon, 22 May 2023 21:38:26 +0100 Subject: [PATCH 5/5] Rebase --- tests/wpunit/OrderMutationsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/wpunit/OrderMutationsTest.php b/tests/wpunit/OrderMutationsTest.php index 7d828bb9e..fc9ab5049 100644 --- a/tests/wpunit/OrderMutationsTest.php +++ b/tests/wpunit/OrderMutationsTest.php @@ -239,7 +239,7 @@ public function testCreateOrderMutation() { ], 'paymentMethod' => 'bacs', 'paymentMethodTitle' => 'Direct Bank Transfer', - 'billing' => array( + 'billing' => [ 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St',