phpclassic / php-shopify

PHP SDK for Shopify API
Apache License 2.0
568 stars 211 forks source link

Reordering Product Option Values -> Various errors #263

Open conorseed opened 2 years ago

conorseed commented 2 years ago

Hey :) Looking at reordering the values of a specific product option named "Delivery Option". There's over 1000 products and most have this as an option field, and they all need reordering so that "Rural Delivery" is last. Screen Shot 2022-09-07 at 4 16 51 PM

I can query the products and reorder the options just fine. However, I can't update the product. I've tried the below rest query:

$newProduct = array(
            "options" => $product['options']
    );
    $result = $shopify->Product($product['id'])->put($newProduct);

But this results in Request failed with HTTP Code 406.

I've also tried a graphql query to update as below:

$graphQL = <<<Query
    mutation updateProductOptions(\$input: ProductInput!) {
        productUpdate(input: \$input) {
            product {
              title, options{name, values}
            }
            userErrors {
              message
              field
            }
          }
      }
    Query;

    $variables = [
        "input" => [
            "id" => $product['id'],
            "options" => $product['options'],
        ]
    ];
    $result = $shopify->GraphQL->post($graphQL, null, null, $variables);

And this results in this error: Variable $input of type ProductInput! was provided invalid value for options.0 (Could not coerce value "{\"name\"=>\"Delivery Option\", \"values\"=>[\"Ground Floor CBD\", \"Residential & Suburban Commercial\", \"Above Ground Floor Delivery\", \"Rural Delivery\"]}" to String), options.1 (Could not coerce value "{\"name\"=>\"Colours\", \"values\"=>[\"Black PU Leather - KG_SWT_PU\", \"Navy Fabric - KG_SWT_N_ASS\", \"Black Fabric - KG_SWT_B_ASS\"]}" to String)

Can anyone see what's going on here?