Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shopify API PHP: Updating a variant's attributes, specifically inventory quantity

Tags:

php

api

shopify

I'm using this PHP framework for use with Shopify's API

Can anyone help me with updating a product's variant attributes, specifically the inventory quantity?

The corresponding api call as listed in the Shopify docs is:

/admin/variants/#{id}.json

To update a product attribute such as the title it's a case of:

$fields = array('title' => 'My New Product Edit');

$api->product->modify(89605609, $fields);

Changing these to reflect a variant doesn't work in the same way.

As always, any help greatly appreciated.

like image 904
user1137277 Avatar asked Jun 18 '12 13:06

user1137277


2 Answers

The library you are using is deprecated. You should use one of the libraries mentioned here: http://wiki.shopify.com/Shopify_App_Development#.E2.80.9CI.E2.80.99m_a_PHP_developer.E2.80.9D

like image 86
Sandeep Shetty Avatar answered Nov 15 '22 12:11

Sandeep Shetty


you can use the following code and update variant values:

$product_array = array(
    'variant'=>array(               
    'id'=>#{id},
    'price'=>15.00
));

$put = $shopify('PUT /admin/variants/#{id}.json', array(), $product_array);

(See the relevant Shopify documentation)

like image 23
Tarun modi Avatar answered Nov 15 '22 13:11

Tarun modi