phpclassic / php-shopify

PHP SDK for Shopify API
Apache License 2.0
573 stars 210 forks source link

Cannot create new variant #65

Open salvobunetto opened 5 years ago

salvobunetto commented 5 years ago

Shopify Api reference

Create a new product variant

POST /admin/products/#{product_id}/variants.json { "variant": { "option1": "Yellow", "price": "1.00" } }

With this PHP Code:

$newVariant = array(
        "option1" => "black",
         "price" => "20.00"
         );

$shopify->Product($product_id)->Variant->post($newVariant);

I recive this error:

Fatal error: Uncaught PHPShopify\Exception\CurlException: Request failed with HTTP Code 406.

tareqtms commented 5 years ago

@salvobunetto It seems like you have error in config part. Please post your config code.

NettoPassaro commented 5 years ago

@tareqtms I'm getting the exactly same problem...

My code:

        $config = array(
            'ShopUrl' => $this->shop_url,
            'ApiKey' => $this->api_key,
            'Password' => $this->password
        );
        ShopifySDK::config($config);
        $shopify = new ShopifySDK($config);

        $putArray = array('option1' => 'Yellow', 'price' => '1.00');
        $shopify->ProductVariant(999999999999)->post($putArray);

Result: Request failed with HTTP Code 406

NettoPassaro commented 5 years ago

@tareqtms i figured out what im doing wrong...

        $putArray = array('option1' => 'Yellow', 'price' => '1.00');
        $shopify->Product(4368899801181)->Variant->post($putArray);

That works perfectly... @salvobunetto