mirror of
https://github.com/wp-graphql/wp-graphql-woocommerce.git
synced 2026-08-14 12:53:44 +02:00
* devops: WC email template tests, COT cursor HPOS fix, checkout account auth WC Email Template Tests: - Add WooCommerceEmailTemplatesTest verifying WC email templates are used for registerCustomer, checkout with account creation, and password reset - Use MockPHPMailer to capture emails and verify HTML content type - Disable deferred transactional emails during tests via GRAPHQL_TESTING flag COT Cursor HPOS Fix: - Fix COT_Cursor::compare_with to resolve orderby aliases and legacy meta keys (_order_total, _date_completed, etc.) to COT column names - Add resolve_orderby_alias() mapping short aliases and meta keys to columns - Add DB_Hooks::clean_query_vars to translate post_* and meta_key orderby to COT-compatible equivalents via woocommerce_order_query_args filter Checkout Account Authentication: - Add authenticate field to CreateAccountInput type - Gate wc_set_customer_auth_cookie() behind authenticate flag in checkout mutation so account creation doesn't auto-authenticate by default Closes #882 * devops: codeception.dist.yml updated * fix: Functional test cleanup and CI coverage condition Test fixes: - Enable authorizing URL fields in ProtectedRouterCest and DownloadableItemAuthCest via setWooGraphQLSetting - Add stale data cleanup (sessions, users, products, orders) to GraphQLE2E _setupStore/getCatalog/setupStoreAndUsers - Fix CartTransactionQueueCest and CartQueriesTest for test isolation CI: - Only run coverage job when at least one upstream job succeeds * chore: Linter compliances met * fix: HPOS order mutation data loss and CI coverage condition Refactor order create/update mutations to set all props on a single WC_Order instance before saving, mirroring the WC REST API pattern. Previously, separate add_order_meta() and add_items() calls each loaded their own order instance and saved independently, causing HPOS data loss for payment method, addresses, and other fields. Also fix CI coverage job to only run when all upstream jobs succeed, and correct test assertions for RAW format line item totals. Closes #591 * chore: Linter compliances met * chore: Remove dead code from Order_Mutation after prepare_order refactor Removes add_items() and update_address() which are no longer called after the prepare_order() consolidation. * chore: Remove dead code add_order_meta and update_item_meta_data
157 lines
5.3 KiB
PHP
157 lines
5.3 KiB
PHP
<?php
|
|
/**
|
|
* Model - Customer
|
|
*
|
|
* Models WooCommerce post-type data
|
|
*
|
|
* @package WPGraphQL\WooCommerce\Model
|
|
* @since 0.0.1
|
|
*/
|
|
|
|
namespace WPGraphQL\WooCommerce\Model;
|
|
|
|
use GraphQLRelay\Relay;
|
|
use WC_Customer;
|
|
use WPGraphQL\Model\Model;
|
|
|
|
/**
|
|
* Class Customer
|
|
*
|
|
* @property int $ID
|
|
* @property string $id
|
|
* @property int $databaseId
|
|
* @property bool $isVatExempt
|
|
* @property bool $hasCalculatedShipping
|
|
* @property bool $calculatedShipping
|
|
* @property int $orderCount
|
|
* @property float $totalSpent
|
|
* @property string $username
|
|
* @property string $email
|
|
* @property string $firstName
|
|
* @property string $lastName
|
|
* @property string $displayName
|
|
* @property string $role
|
|
* @property string $date
|
|
* @property string $modified
|
|
* @property array $billing
|
|
* @property array $shipping
|
|
* @property bool $isPayingCustomer
|
|
* @property int $last_order_id
|
|
*
|
|
* @package WPGraphQL\WooCommerce\Model
|
|
*/
|
|
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', $is_session = false ) {
|
|
$this->data = 'session' === $id ? \WC()->customer : new WC_Customer( absint( $id ), $is_session );
|
|
$allowed_restricted_fields = [
|
|
'isRestricted',
|
|
'isPrivate',
|
|
'isPublic',
|
|
'id',
|
|
'databaseId',
|
|
];
|
|
|
|
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
|
|
$restricted_cap = apply_filters( 'customer_restricted_cap', 'session' === $id ? '' : 'list_users' );
|
|
|
|
parent::__construct( $restricted_cap, $allowed_restricted_fields, $this->data->get_id() );
|
|
}
|
|
|
|
/**
|
|
* Forwards function calls to WC_Data sub-class instance.
|
|
*
|
|
* @param string $method - function name.
|
|
* @param array $args - function call arguments.
|
|
* @return mixed
|
|
*/
|
|
public function __call( $method, $args ) {
|
|
return $this->data->$method( ...$args );
|
|
}
|
|
|
|
/**
|
|
* Initializes the Customer field resolvers.
|
|
*/
|
|
protected function init() {
|
|
if ( empty( $this->fields ) ) {
|
|
$this->fields = [
|
|
'ID' => function () {
|
|
return ( ! empty( $this->data->get_id() ) ) ? $this->data->get_id() : \WC()->session->get_customer_id();
|
|
},
|
|
'id' => function () {
|
|
return ! empty( $this->data->get_id() )
|
|
? Relay::toGlobalId( 'user', $this->data->get_id() )
|
|
: 'guest';
|
|
},
|
|
'databaseId' => function () {
|
|
return ! empty( $this->ID ) ? $this->ID : null;
|
|
},
|
|
'isVatExempt' => function () {
|
|
return ! is_null( $this->data->get_is_vat_exempt() ) ? $this->data->get_is_vat_exempt() : null;
|
|
},
|
|
'hasCalculatedShipping' => function () {
|
|
return ! is_null( $this->data->has_calculated_shipping() ) ? $this->data->has_calculated_shipping() : null;
|
|
},
|
|
'calculatedShipping' => function () {
|
|
return ! is_null( $this->data->get_calculated_shipping() ) ? $this->data->get_calculated_shipping() : null;
|
|
},
|
|
'orderCount' => function () {
|
|
return ! is_null( $this->data->get_order_count() ) ? $this->data->get_order_count() : null;
|
|
},
|
|
'totalSpent' => function () {
|
|
return ! is_null( $this->data->get_total_spent() ) ? $this->data->get_total_spent() : null;
|
|
},
|
|
'username' => function () {
|
|
return ( ! empty( $this->data->get_username() ) ) ? $this->data->get_username() : null;
|
|
},
|
|
'email' => function () {
|
|
return ( ! empty( $this->data->get_email() ) ) ? $this->data->get_email() : null;
|
|
},
|
|
'firstName' => function () {
|
|
return ( ! empty( $this->data->get_first_name() ) ) ? $this->data->get_first_name() : null;
|
|
},
|
|
'lastName' => function () {
|
|
return ( ! empty( $this->data->get_last_name() ) ) ? $this->data->get_last_name() : null;
|
|
},
|
|
'displayName' => function () {
|
|
return ( ! empty( $this->data->get_display_name() ) ) ? $this->data->get_display_name() : null;
|
|
},
|
|
'role' => function () {
|
|
return ( ! empty( $this->data->get_role() ) ) ? $this->data->get_role() : null;
|
|
},
|
|
'date' => function () {
|
|
return ( ! empty( $this->data->get_date_created() ) ) ? $this->data->get_date_created() : null;
|
|
},
|
|
'modified' => function () {
|
|
return ( ! empty( $this->data->get_date_modified() ) ) ? $this->data->get_date_modified() : null;
|
|
},
|
|
'billing' => function () {
|
|
return ( ! empty( $this->data->get_billing() ) ) ? $this->data->get_billing() : null;
|
|
},
|
|
'shipping' => function () {
|
|
return ( ! empty( $this->data->get_shipping() ) ) ? $this->data->get_shipping() : null;
|
|
},
|
|
'isPayingCustomer' => function () {
|
|
return ( ! is_null( $this->data->get_is_paying_customer() ) ) ? $this->data->get_is_paying_customer() : null;
|
|
},
|
|
/**
|
|
* Connection resolvers fields
|
|
*
|
|
* These field resolvers are used in connection resolvers to define WP_Query argument
|
|
* Note: underscore naming style is used as a quick identifier
|
|
*/
|
|
'last_order_id' => function () {
|
|
return ( ! empty( $this->data->get_last_order() ) ) ? $this->data->get_last_order()->get_id() : null;
|
|
},
|
|
];
|
|
}//end if
|
|
|
|
parent::prepare_fields();
|
|
}
|
|
}
|