<?php
declare(strict_types=1);
// THIS FILE IS AUTO-GENERATED. DO NOT EDIT MANUALLY.
namespace Automattic\WooCommerce\Internal\Api\Autogenerated\GraphQLMutations;
use Automattic\WooCommerce\Api\Mutations\Products\UpdateProduct as UpdateProductCommand;
use Automattic\WooCommerce\Internal\Api\QueryInfoExtractor;
use Automattic\WooCommerce\Internal\Api\Utils;
use Automattic\WooCommerce\Internal\Api\Autogenerated\GraphQLTypes\Interfaces\Product as ProductInterface;
use Automattic\WooCommerce\Internal\Api\Autogenerated\GraphQLTypes\Input\UpdateProduct as UpdateProductInput;
use Automattic\WooCommerce\Internal\Api\Schema\ResolveInfo;
use Automattic\WooCommerce\Internal\Api\Schema\Type;
class UpdateProduct {
public static function get_field_definition(): array {
return array(
'type' => Type::nonNull( ProductInterface::get() ),
'description' => __( 'Update an existing product.', 'woocommerce' ),
'args' => array(
'input' => array(
'type' => Type::nonNull( UpdateProductInput::get() ),
'description' => __( 'The fields to update.', 'woocommerce' ),
),
),
'resolve' => array( self::class, 'resolve' ),
);
}
public static function resolve( mixed $root, array $args, mixed $context, ResolveInfo $info ): mixed {
Utils::check_current_user_can( 'manage_woocommerce' );
$command = \Automattic\WooCommerce\Api\Container::get( UpdateProductCommand::class );
$execute_args = array();
if ( array_key_exists( 'input', $args ) ) {
$execute_args['input'] = self::convert_update_product_input( $args['input'] );
}
$result = Utils::execute_command( $command, $execute_args );
return $result;
}
private static function convert_dimensions_input( array $data ): \Automattic\WooCommerce\Api\InputTypes\Products\DimensionsInput {
$input = new \Automattic\WooCommerce\Api\InputTypes\Products\DimensionsInput();
if ( array_key_exists( 'length', $data ) ) {
$input->mark_provided( 'length' );
$input->length = $data['length'];
}
if ( array_key_exists( 'width', $data ) ) {
$input->mark_provided( 'width' );
$input->width = $data['width'];
}
if ( array_key_exists( 'height', $data ) ) {
$input->mark_provided( 'height' );
$input->height = $data['height'];
}
if ( array_key_exists( 'weight', $data ) ) {
$input->mark_provided( 'weight' );
$input->weight = $data['weight'];
}
return $input;
}
private static function convert_update_product_input( array $data ): \Automattic\WooCommerce\Api\InputTypes\Products\UpdateProductInput {
$input = new \Automattic\WooCommerce\Api\InputTypes\Products\UpdateProductInput();
if ( array_key_exists( 'id', $data ) ) {
$input->mark_provided( 'id' );
$input->id = $data['id'];
}
if ( array_key_exists( 'name', $data ) ) {
$input->mark_provided( 'name' );
$input->name = $data['name'];
}
if ( array_key_exists( 'slug', $data ) ) {
$input->mark_provided( 'slug' );
$input->slug = $data['slug'];
}
if ( array_key_exists( 'sku', $data ) ) {
$input->mark_provided( 'sku' );
$input->sku = $data['sku'];
}
if ( array_key_exists( 'description', $data ) ) {
$input->mark_provided( 'description' );
$input->description = $data['description'];
}
if ( array_key_exists( 'short_description', $data ) ) {
$input->mark_provided( 'short_description' );
$input->short_description = $data['short_description'];
}
if ( array_key_exists( 'status', $data ) ) {
$input->mark_provided( 'status' );
$input->status = $data['status'];
}
if ( array_key_exists( 'product_type', $data ) ) {
$input->mark_provided( 'product_type' );
$input->product_type = $data['product_type'];
}
if ( array_key_exists( 'regular_price', $data ) ) {
$input->mark_provided( 'regular_price' );
$input->regular_price = $data['regular_price'];
}
if ( array_key_exists( 'sale_price', $data ) ) {
$input->mark_provided( 'sale_price' );
$input->sale_price = $data['sale_price'];
}
if ( array_key_exists( 'manage_stock', $data ) ) {
$input->mark_provided( 'manage_stock' );
$input->manage_stock = $data['manage_stock'];
}
if ( array_key_exists( 'stock_quantity', $data ) ) {
$input->mark_provided( 'stock_quantity' );
$input->stock_quantity = $data['stock_quantity'];
}
if ( array_key_exists( 'dimensions', $data ) ) {
$input->mark_provided( 'dimensions' );
$input->dimensions = null !== $data['dimensions'] ? self::convert_dimensions_input( $data['dimensions'] ) : null;
}
return $input;
}
}