2026-03-20 13:31:13 -04:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Mutation - updateProduct
|
|
|
|
|
*
|
|
|
|
|
* Registers mutation for updating a product.
|
|
|
|
|
*
|
|
|
|
|
* @package WPGraphQL\WooCommerce\Mutation
|
2026-03-31 11:06:51 -04:00
|
|
|
* @since 1.0.0
|
2026-03-20 13:31:13 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace WPGraphQL\WooCommerce\Mutation;
|
|
|
|
|
|
|
|
|
|
use WPGraphQL\WooCommerce\Model\Product;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class Product_Update
|
|
|
|
|
*/
|
|
|
|
|
class Product_Update {
|
|
|
|
|
/**
|
|
|
|
|
* Registers mutation
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public static function register_mutation() {
|
|
|
|
|
register_graphql_mutation(
|
|
|
|
|
'updateProduct',
|
|
|
|
|
[
|
|
|
|
|
'inputFields' => self::get_input_fields(),
|
|
|
|
|
'outputFields' => self::get_output_fields(),
|
|
|
|
|
'mutateAndGetPayload' => [ Product_Create::class, 'mutate_and_get_payload' ],
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Defines the mutation input field configuration
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public static function get_input_fields() {
|
|
|
|
|
return array_merge(
|
2026-04-02 18:59:48 -04:00
|
|
|
Product_Create::get_input_fields(),
|
2026-03-20 13:31:13 -04:00
|
|
|
[
|
2026-04-02 18:59:48 -04:00
|
|
|
'id' => [
|
2026-03-20 13:31:13 -04:00
|
|
|
'type' => [ 'non_null' => 'ID' ],
|
2026-03-30 23:37:51 -04:00
|
|
|
'description' => static function () {
|
2026-06-30 10:16:21 -04:00
|
|
|
return __( 'Unique identifier for the product.', 'graphql-for-ecommerce' );
|
2026-03-30 23:37:51 -04:00
|
|
|
},
|
2026-03-20 13:31:13 -04:00
|
|
|
],
|
2026-04-02 18:59:48 -04:00
|
|
|
'name' => [
|
|
|
|
|
'type' => 'String',
|
|
|
|
|
'description' => static function () {
|
2026-06-30 10:16:21 -04:00
|
|
|
return __( 'Name of the product.', 'graphql-for-ecommerce' );
|
2026-04-02 18:59:48 -04:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
]
|
2026-03-20 13:31:13 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Defines the mutation output field configuration
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public static function get_output_fields() {
|
|
|
|
|
return [
|
|
|
|
|
'product' => [
|
|
|
|
|
'type' => 'Product',
|
|
|
|
|
'resolve' => static function ( $payload ) {
|
|
|
|
|
return new Product( $payload['id'] );
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|