Question

I am currently trying to drag all my products from BC into a local DB so I can work with them. Limits is causing me a big headache!

Before this code worked fine to get all the products and SKUs

$filter = array('limit' => 200, 'page' => 1);
$products = Bigcommerce::getProducts($filter);

foreach ($products as $product)
{
$ParentSKU = $product->sku;
$BC_Product_ID = $product->id;
   if ($product->skus != '')
   {
   foreach ($product->skus as $sku)
   $ChildSKU = $sku->sku;
   $Child_BC_Product_ID = $sku->id;
   }
}

Now this is using the PHP library and works provided the product has less than 50 SKUs (I think this number is correct). This is because it is making a call to....

https://store.mybigcommerce.com/api/v2/products/#productid#/skus.json?max_id=9999&limit=250

And this result only returns 50.

Now i can receive them all by adding a filter limit like this....

https://store.mybigcommerce.com/api/v2/products/#productid#/skus.json?limit=250

250 is the max limit - which will be fine for the amount of configurable options I have per product. But how to I add this filter to my

$product->skus

command ? I have tried doing it like so...

$filtertest = array ('limit' => 200);
$product->skus($filtertest);

But when I var_dump this it seems to totally ignore the filter?? Any ideas how I can add the filter via this mechanism?

I wish BC would have an option to just show ALL SKUs parent/child in a single call as part of the export products as would make it a lot easier to work with!

Any help much appreciated!

Was it helpful?

Solution

Ok so rather than getting SKUs for each product I have found it easier to get ALL the SKUs separately.

Firstly I found out how many SKUs are available in total by CURLing the following URL.

/api/v2/products/skus/count.json

And the same for the parent products

/api/v2/products/count.json

The divided these by 100 (as I would page them by 100)

I then used the following commands in the PHP API provided by bigcommerce For SKUs..

Bigcommerce::getSkus($filter)    

For Products...

Bigcommerce::getProducts($filter)  

I then used the following filter.

$filter = array('limit' => 100, 'page' => $AmountOfPagesReturnedFromCurl);

This will then loop it through all the SKUs/Products which I can add SQL commands in the loop to add them to my DB.

I hope this is helpful to someone, I really enjoy developing with Bigcommerce.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top