aligent / bigcommerce-v3-api-php-client

PHP library to interact with the BigCommerce V3 API (https://developer.bigcommerce.com/api-reference#v3-rest-api)
GNU General Public License v3.0
13 stars 23 forks source link

syntax help #172

Closed Ctucker9233 closed 1 year ago

Ctucker9233 commented 1 year ago

I can get a single vendor, but for some reason I can't get the 'name' property. Can someone help me with the syntax?

$brands = $api->catalog()->brands()->getAllPages(['id:less' => 150])->getBrands();

        foreach ($brands as $brand) {
            $vendor = $api->catalog()->brand($brand->id)->get();
            dump($vendor->name)                
        }

I'm trying to get the name to match up to my database.

jswift commented 1 year ago

You don't need to request each brand from the API, you should be able to do the following:

$brands = $api->catalog()->brands()->getAll()->getBrands();

foreach ($brands as $brand) {
    echo $brand->name, PHP_EOL;
}

Note that if you don't want to deal with pages and are happy to wait you can call $brands = $client->catalog()->brands()->getAllPages()->getBrands(); to get every brand in one call.

jswift commented 1 year ago

oh, and the reason this code didn't work is because you missed the getBrand() off the end of the query, so the $vendor variable was actually the API Response variable