Skip to content

Commit 1a2410f

Browse files
committed
ConnectionPaginationTest added
1 parent 4ff4207 commit 1a2410f

File tree

6 files changed

+488
-2
lines changed

6 files changed

+488
-2
lines changed

includes/data/connection/class-product-connection-resolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,6 @@ public function sanitize_input_fields( array $where_args ) {
619619
* @return bool
620620
*/
621621
public function is_valid_offset( $offset ) {
622-
return $this->$this->is_valid_post_offset( $offset );
622+
return $this->is_valid_post_offset( $offset );
623623
}
624624
}

includes/data/mutation/class-checkout-mutation.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,4 +568,36 @@ public static function get_value( $input ) {
568568
}
569569
return apply_filters( 'default_checkout_' . $input, $value, $input );
570570
}
571+
572+
/**
573+
* Add meta data not set in WC_Checkout::create_order().
574+
*
575+
* @param int $order_id Order ID.
576+
* @param array $meta_data Order meta data.
577+
* @param array $input Order properties.
578+
* @param AppContext $context AppContext instance.
579+
* @param ResolveInfo $info ResolveInfo instance.
580+
*/
581+
public static function add_order_meta( $order_id, $meta_data, $input, $context, $info ) {
582+
$order = \WC_Order_Factory::get_order( $order_id );
583+
584+
if ( $meta_data ) {
585+
foreach ( $meta_data as $meta ) {
586+
$order->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' );
587+
}
588+
}
589+
590+
/**
591+
* Action called before changes to order meta are saved.
592+
*
593+
* @param WC_Order $order WC_Order instance.
594+
* @param array $meta_data Order meta data.
595+
* @param array $props Order props array.
596+
* @param AppContext $context Request AppContext instance.
597+
* @param ResolveInfo $info Request ResolveInfo instance.
598+
*/
599+
do_action( 'woocommerce_graphql_before_checkout_meta_save', $order, $meta_data, $input, $context, $info );
600+
601+
$order->save();
602+
}
571603
}

includes/data/mutation/class-order-mutation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static function authorized( $mutation = 'create', $input, $context, $info
4747
* @param AppContext $context AppContext instance.
4848
* @param ResolveInfo $info ResolveInfo instance.
4949
*
50-
* @return WC_Order
50+
* @return integer
5151
*
5252
* @throws UserError Error creating order.
5353
*/

includes/mutation/class-checkout.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ public static function get_input_fields() {
7171
'type' => 'CreateAccountInput',
7272
'description' => __( 'Create new customer account', 'wp-graphql-woocommerce' ),
7373
),
74+
'metaData' => array(
75+
'type' => array( 'list_of' => 'MetaDataInput' ),
76+
'description' => __( 'Order meta data', 'wp-graphql-woocommerce' ),
77+
),
7478
);
7579
}
7680

@@ -136,6 +140,11 @@ public static function mutate_and_get_payload() {
136140
throw new UserError( $order_id->get_error_message( 'checkout-error' ) );
137141
}
138142

143+
// Add meta data.
144+
if ( ! empty( $input['metaData'] ) ) {
145+
Checkout_Mutation::add_order_meta( $order_id, $input['metaData'], $input, $context, $info );
146+
}
147+
139148
/**
140149
* Action called after checking out.
141150
*

tests/wpunit/CheckoutMutationsTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ private function checkout( $input ) {
151151
}
152152
needsPayment
153153
needsProcessing
154+
metaData {
155+
key
156+
value
157+
}
154158
couponLines {
155159
nodes {
156160
itemId
@@ -283,6 +287,12 @@ public function testCheckoutOrderMutation() {
283287
'postcode' => '12345',
284288
'country' => 'US',
285289
),
290+
'metaData' => array(
291+
array(
292+
'key' => 'test_key',
293+
'value' => 'test value',
294+
),
295+
)
286296
);
287297

288298
/**
@@ -311,6 +321,16 @@ public function testCheckoutOrderMutation() {
311321
'order' => array_merge(
312322
$this->order->print_query( $order->get_id() ),
313323
array(
324+
'metaData' => array(
325+
array(
326+
'key' => 'is_vat_exempt',
327+
'value' => 'no',
328+
),
329+
array(
330+
'key' => 'test_key',
331+
'value' => 'test value',
332+
),
333+
),
314334
'couponLines' => array(
315335
'nodes' => array_reverse(
316336
array_map(
@@ -496,6 +516,12 @@ public function testCheckoutOrderMutationWithNewAccount() {
496516
'order' => array_merge(
497517
$this->order->print_query( $order->get_id() ),
498518
array(
519+
'metaData' => array(
520+
array(
521+
'key' => 'is_vat_exempt',
522+
'value' => 'no',
523+
),
524+
),
499525
'couponLines' => array(
500526
'nodes' => array_reverse(
501527
array_map(
@@ -687,6 +713,12 @@ public function testCheckoutOrderMutationWithNoAccount() {
687713
'order' => array_merge(
688714
$this->order->print_restricted_query( $order->get_id() ),
689715
array(
716+
'metaData' => array(
717+
array(
718+
'key' => 'is_vat_exempt',
719+
'value' => 'no',
720+
),
721+
),
690722
'couponLines' => array(
691723
'nodes' => array_reverse(
692724
array_map(

0 commit comments

Comments
 (0)