Josh
Josh

Reputation: 137

Bigcommerce API Update Inventory Levels (both normal inventory tracking and tracking by options)

Update 11/11/13: After doing some testing I'm running into some more problems using the bigcommerce php api. Searching a sku's property works fine for SKU's that are attached to options, but updating them I seem to be running into some problems...

Here is a sample snippet:

$filter = array('sku' => '230000120078');
$skus = Bigcommerce::getSkus($filter);
foreach($skus as $sku){
    $options = array('inventory_level' => 3);
    Bigcommerce::updateSku($sku->id, $options);
}

I must be missing something but I can't find to much documentation online. BigCommerce Documentation for updating sku makes it seem as if I have this right, but it doesn't seem to be working. Any suggestions?

Original Post:

This is more of a general question before I look to deep into solutions...

I read this post about updating inventory levels by SKUs and the answer suggests you can only update levels by product ids. Does this mean if you have a store with some products that track inventory by option sets (with SKUs attached to each option) you cannot update the inventory levels for each of these options?

Currently I just wrote a script that connects to our RFID database and grabs the current inventory levels and throws them into a csv file which I then upload every morning, but I'm trying to fully automate the process so I don't have to worry about selling out of items in between the 24 hours of new inventory.

Does anyone have any experience with this using the Bigcommerce api?

Upvotes: 2

Views: 1634

Answers (3)

Yosi Benezra
Yosi Benezra

Reputation: 36

So...

This requires a hybrid solution; if you look at the quick start guide (not very helpful) you'll find this

Currently, there are two ways to search for SKUs - GET /products?sku="something" or GET /products/skus?sku="something". The first call only returns product level SKU and not option level SKUs.

What they neglect to mention is that to get the product level SKU, the only method that works is the top one.

My solution was to include another function in the library that adjusted the path to just /products?skup=xxxxx

public static function getSkuTop($filter = false)
{
    $filter = Filter::create($filter);
    return self::getCollection('/products' . $filter->toQuery(), 'Sku');
}

and in my call I have a few simple bits of logic

$filter = array('sku' => '10026');
$skus = Bigcommerce::getSkus($filter);

if(is_array($skus)){
    foreach($skus as $sku){
        $sku->inventory_level = 27;
        $sku->update();
    }   
} else {
    $skus = Bigcommerce::getSkuTop($filter);
    if(is_array($skus)){
        foreach($skus as $sku){
            $options = array('inventory_level' => 28);
            Bigcommerce::updateProduct($sku->id, $options);
        }   
    }
}

May not be so great, but it's the only way I can get it to work!

Upvotes: 2

Josh
Josh

Reputation: 137

As far as actually updating the SKU I figured out the easiest way and that is the following. Instead of trying to run the updateSku function I do this...

$filter = array('sku' => '230000120078');
$skus = Bigcommerce::getSkus($filter);
foreach($skus as $sku){
    $sku->inventory_level = 4;
    $sku->update();
}

This does update the inventory for the associated sku.

As far as Paul's response, he is absolutely correct, and it lead me to this answer.

Upvotes: 1

Paul Hackney
Paul Hackney

Reputation: 11

Yes, I have been working on that same issue and the solution I came up with was to check if the SKU on the product level is blank. If so, the the inventory_level is managed by in the SKU resources underneath the product.

Upvotes: 1

Related Questions