Skip to content

Commit 6b58174

Browse files
authored
"isSession" field added to the "UpdateCustomerInput" type (#924)
1 parent 3baeb2b commit 6b58174

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

includes/model/class-customer.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ class Customer extends Model {
4747
* Customer constructor
4848
*
4949
* @param \WC_Customer|int|string $id - User ID.
50+
* @param bool $is_session - Whether the customer is a session.
5051
*/
51-
public function __construct( $id = 'session' ) {
52-
$this->data = 'session' === $id ? \WC()->customer : new WC_Customer( absint( $id ) );
52+
public function __construct( $id = 'session', $is_session = false ) {
53+
$this->data = 'session' === $id ? \WC()->customer : new WC_Customer( absint( $id ), $is_session );
5354
$allowed_restricted_fields = [
5455
'isRestricted',
5556
'isPrivate',

includes/mutation/class-customer-update.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ public static function get_input_fields() {
6666
'description' => __( 'Meta data.', 'wp-graphql-woocommerce' ),
6767
'type' => [ 'list_of' => 'MetaDataInput' ],
6868
],
69+
'isSession' => [
70+
'type' => 'Boolean',
71+
'description' => __( 'Whether to save changes on the session or in the database', 'wp-graphql-woocommerce' ),
72+
],
6973
]
7074
);
7175
}
@@ -93,6 +97,7 @@ public static function get_output_fields() {
9397
*/
9498
public static function mutate_and_get_payload() {
9599
return static function ( $input, AppContext $context, ResolveInfo $info ) {
100+
$is_session = isset( $input['isSession'] ) ? $input['isSession'] : false;
96101
$session_only = empty( $input['id'] ) && ! is_user_logged_in();
97102
$payload = null;
98103

@@ -116,7 +121,7 @@ public static function mutate_and_get_payload() {
116121
$customer_args = Customer_Mutation::prepare_customer_props( $input, 'update' );
117122

118123
// Create customer object.
119-
$customer = ! $session_only ? new WC_Customer( $payload['id'] ) : \WC()->customer;
124+
$customer = ! $session_only ? new WC_Customer( $payload['id'], $is_session ) : \WC()->customer;
120125

121126
// Copy billing address as shipping address.
122127
if ( isset( $input['shippingSameAsBilling'] ) && $input['shippingSameAsBilling'] ) {

0 commit comments

Comments
 (0)