Files
Geoff TaylorandGitHub 088d337ef5 fix: address WordPress.org plugin review (rename + prefixing + headers) (#1019)
* fix: address WordPress.org plugin review feedback

- Prefix the session transaction queue transient with the plugin's
  graphql_woocommerce_ namespace instead of the generic "woo_" word, to
  avoid collisions (Plugin Directory: prefix data storage).
- Declare the WooCommerce dependency via the "Requires Plugins: woocommerce"
  plugin header.
- Bump README.txt "Tested up to" to 7.0.
- Ship composer.json in the distributed plugin (drop it, and composer.lock,
  from composer archive excludes) so the build is reproducible/reviewable.

* chore: rename plugin to "GraphQL for eCommerce" for trademark compliance

The WordPress.org plugin review flagged the display name/slug for beginning
with the "WPGraphQL" trademark (and the "WooGraphQL" portmanteau of the
WooCommerce mark), which can imply official affiliation.

- Display name (plugin header + readme title) -> "GraphQL for eCommerce".
- Slug/text domain -> "graphql-for-ecommerce" (header, all i18n string
  literals, and the PHPCS WordPress.WP.I18n text_domain config).
- Update user-facing notices/errors that named the old plugin.

"WooGraphQL" remains the project's informal nickname (repo, docs, community),
just not in the WordPress.org directory's official name/slug. Internal file
names and GitHub URLs are unchanged.

* fix: keep test-only dev deps out of the committed composer.json

The committed manifest mirrors develop (lint/stan dev deps only); CI adds the
test suite deps at runtime via `composer installTestEnv`. A previous commit
captured the installTestEnv-modified composer.json, desyncing it from
composer.lock and breaking `composer install` in CI.

* chore: regenerate composer.lock (refresh dev dependencies)

Regenerate the lock from the manifest so it is in sync (fixes the CI
`composer install` failure) and refresh dependencies in the process —
firebase/php-jwt v7.0.4 -> v7.1.0 plus 11 others, with vendor-prefixed
re-strauss'd to match. Full wpunit suite passes against the updated deps
(305 tests, 835 assertions).

* chore: rename text domain in createdVia/attribution strings from #1018

#1018 (createdVia + order attribution) merged into develop after the rename
commit was authored, so its new i18n strings still used the old
'wp-graphql-woocommerce' text domain. Update them to 'graphql-for-ecommerce'
to match the rename.
2026-06-30 10:16:21 -04:00

182 lines
5.0 KiB
PHP

<?php
/**
* Registers "updateCustomer" mutation
*
* @package WPGraphQL\WooCommerce\Mutation
* @since 0.1.0
*/
namespace WPGraphQL\WooCommerce\Mutation;
use GraphQL\Error\UserError;
use GraphQL\Type\Definition\ResolveInfo;
use WC_Customer;
use WPGraphQL\AppContext;
use WPGraphQL\Mutation\UserCreate;
use WPGraphQL\Mutation\UserUpdate;
use WPGraphQL\WooCommerce\Data\Mutation\Customer_Mutation;
use WPGraphQL\WooCommerce\Model\Customer;
/**
* Class - Customer_Update
*/
class Customer_Update {
/**
* Registers mutation
*
* @return void
*/
public static function register_mutation() {
register_graphql_mutation(
'updateCustomer',
[
'inputFields' => self::get_input_fields(),
'outputFields' => self::get_output_fields(),
'mutateAndGetPayload' => self::mutate_and_get_payload(),
]
);
}
/**
* Defines the mutation input field configuration
*
* @return array
*/
public static function get_input_fields() {
return array_merge(
UserCreate::get_input_fields(),
[
'id' => [
'type' => 'ID',
'description' => static function () {
return __( 'The ID of the user', 'graphql-for-ecommerce' );
},
],
'billing' => [
'type' => 'CustomerAddressInput',
'description' => static function () {
return __( 'Customer billing information', 'graphql-for-ecommerce' );
},
],
'shipping' => [
'type' => 'CustomerAddressInput',
'description' => static function () {
return __( 'Customer shipping address', 'graphql-for-ecommerce' );
},
],
'shippingSameAsBilling' => [
'type' => 'Boolean',
'description' => static function () {
return __( 'Customer shipping is identical to billing address', 'graphql-for-ecommerce' );
},
],
'metaData' => [
'description' => static function () {
return __( 'Meta data.', 'graphql-for-ecommerce' );
},
'type' => [ 'list_of' => 'MetaDataInput' ],
],
'isSession' => [
'type' => 'Boolean',
'description' => static function () {
return __( 'Whether to save changes on the session or in the database', 'graphql-for-ecommerce' );
},
],
]
);
}
/**
* Defines the mutation output field configuration
*
* @return array
*/
public static function get_output_fields() {
return [
'customer' => [
'type' => 'Customer',
'resolve' => static function ( $payload ) {
return new Customer( $payload['id'] );
},
],
];
}
/**
* Defines the mutation data modification closure.
*
* @return callable
*/
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;
if ( ! $session_only ) {
// Get closure from "UserRegister::mutate_and_get_payload".
$update_user = UserUpdate::mutate_and_get_payload();
if ( ! isset( $input['id'] ) ) {
$input['id'] = get_current_user_id();
}
// Update customer with core UserUpdate closure.
$payload = $update_user( $input, $context, $info );
if ( empty( $payload ) ) {
throw new UserError( __( 'Failed to update customer.', 'graphql-for-ecommerce' ) );
}
}
// Map all of the args from GQL to WC friendly.
$customer_args = Customer_Mutation::prepare_customer_props( $input, 'update' );
// Create customer object.
$customer = ! $session_only ? new WC_Customer( $payload['id'], $is_session ) : \WC()->customer;
// Copy billing address as shipping address.
if ( isset( $input['shippingSameAsBilling'] ) && $input['shippingSameAsBilling'] ) {
$customer_args['shipping'] = array_merge(
Customer_Mutation::empty_shipping(),
array_intersect_key( $customer->get_billing( 'edit' ), Customer_Mutation::empty_shipping() )
);
}
// Update customer fields.
foreach ( $customer_args as $prop => $value ) {
// If field group like 'shipping' or 'billing'.
if ( ! empty( $value ) && \is_array( $value ) ) {
// Check if group field has set function and assigns new value.
foreach ( $value as $field => $field_value ) {
if ( is_callable( [ $customer, "set_{$prop}_{$field}" ] ) ) {
$customer->{"set_{$prop}_{$field}"}( $field_value );
}
}
// If field has set function and assigns new value.
} elseif ( is_callable( [ $customer, "set_{$prop}" ] ) ) {
$customer->{"set_{$prop}"}( $value );
}
}
// Set meta data.
if ( ! empty( $input['metaData'] ) ) {
Customer_Mutation::input_meta_data_mapping( $customer, $input['metaData'] );
}
// Save customer and get customer ID.
$customer->save();
if ( $session_only ) {
do_action( 'woographql_update_session', true );
}
// Return payload.
return ! empty( $payload ) ? $payload : [ 'id' => 'session' ];
};
}
}