How to update “inventory_level” of product by sku id in Bigcommerce?

让人想犯罪 __ 提交于 2019-12-30 03:26:27

问题


I am trying to update the inventory level of a products but unfortunately not getting success.Here is my code. I want to update product's "inventory_level" but enable to do so..

<?php

require "bigcommerce.php";
use Bigcommerce\Api\Client as Bigcommerce;


Bigcommerce::configure(array(
    'store_url' => 'https://store-nos85a.mybigcommerce.com/',
    'username' => 'admin',
    'api_key' => '4b7c4bba19f290a728e00be6ae7133cda71f477b'
    ));

Bigcommerce::setCipher('RC4-SHA');
Bigcommerce::verifyPeer(false);
            $product = Bigcommerce::getProduct(76); 
            print_r($product->skus);
                       foreach($product->skus as $sku)
                        {

                            if($sku->id==5)
                                {
                              $fields = array("inventory_level"=>112);
                              Bigcommerce::updateProduct(76,$fields);
                                }
                            echo "id :  ".$sku->id;
                            echo " Invntory Level: ".$sku->inventory_level."<br/>";
                            echo " SKU : ".$sku->sku."<br/>";

                        }


?>

Here " Bigcommerce::updateProduct(76,$field); " is not working..
Please Help me..
Thanks..

回答1:


I am trying to do the same thing (different programming language). I have a call into their support. It seems like you still must reference the product_id.

You cannot update simply by SKU. You must know the product_id. I got around this by requesting all products and loading the response into an array (product_id, sku, etc.). I then read thru the array, get the quantity from our system using the SKU, and post (PUT) the inventory_level using the associated product_id.

IMHO this is a huge oversight on their part. Who cares what the product_id is on the website?

I have asked for an enhancement that allows updating by SKU.




回答2:


No need to download ALL products, why not retrieve JUST the product that has the sku you need?

GET: /api/v2/products?sku=sku-that-I'm-interested-in

parse the response for the id (that's the product ID for the product with that SKU)

Then do a PUT using that product ID.



来源:https://stackoverflow.com/questions/19273118/how-to-update-inventory-level-of-product-by-sku-id-in-bigcommerce

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!