mirror of
https://github.com/wp-graphql/wp-graphql-woocommerce.git
synced 2026-08-14 12:53:44 +02:00
"isSession" field added to the "UpdateCustomerInput" type (#924)
This commit is contained in:
@@ -47,9 +47,10 @@ class Customer extends Model {
|
||||
* Customer constructor
|
||||
*
|
||||
* @param \WC_Customer|int|string $id - User ID.
|
||||
* @param bool $is_session - Whether the customer is a session.
|
||||
*/
|
||||
public function __construct( $id = 'session' ) {
|
||||
$this->data = 'session' === $id ? \WC()->customer : new WC_Customer( absint( $id ) );
|
||||
public function __construct( $id = 'session', $is_session = false ) {
|
||||
$this->data = 'session' === $id ? \WC()->customer : new WC_Customer( absint( $id ), $is_session );
|
||||
$allowed_restricted_fields = [
|
||||
'isRestricted',
|
||||
'isPrivate',
|
||||
|
||||
@@ -66,6 +66,10 @@ class Customer_Update {
|
||||
'description' => __( 'Meta data.', 'wp-graphql-woocommerce' ),
|
||||
'type' => [ 'list_of' => 'MetaDataInput' ],
|
||||
],
|
||||
'isSession' => [
|
||||
'type' => 'Boolean',
|
||||
'description' => __( 'Whether to save changes on the session or in the database', 'wp-graphql-woocommerce' ),
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -93,6 +97,7 @@ class Customer_Update {
|
||||
*/
|
||||
public static function mutate_and_get_payload() {
|
||||
return static function ( $input, AppContext $context, ResolveInfo $info ) {
|
||||
$is_session = isset( $input['isSession'] ) ? $input['isSession'] : false;
|
||||
$session_only = empty( $input['id'] ) && ! is_user_logged_in();
|
||||
$payload = null;
|
||||
|
||||
@@ -116,7 +121,7 @@ class Customer_Update {
|
||||
$customer_args = Customer_Mutation::prepare_customer_props( $input, 'update' );
|
||||
|
||||
// Create customer object.
|
||||
$customer = ! $session_only ? new WC_Customer( $payload['id'] ) : \WC()->customer;
|
||||
$customer = ! $session_only ? new WC_Customer( $payload['id'], $is_session ) : \WC()->customer;
|
||||
|
||||
// Copy billing address as shipping address.
|
||||
if ( isset( $input['shippingSameAsBilling'] ) && $input['shippingSameAsBilling'] ) {
|
||||
|
||||
Reference in New Issue
Block a user