问题
I want to get the product images using the Bigcommerce PHP library. How would I do that?
$products=Bigcommerce::getProducts();
foreach($products as $product) {
echo $product->name;
echo $product->price;
}//here i retrieve price and name of products
回答1:
The following code will get you the product images...
$products=Bigcommerce::getProducts();
foreach($products as $product) {
echo $product->name;
echo $product->price;
echo $product->images[0]->image_file
}
The line
echo $product->images[0]->image_file
will give you the first image for the specific product. In order to get more than one image, you would need to iterate through the list. To get the exact url, just append your store_url/product_images at the start of the image_file. So the exact url becomes
'https://store_url/product_images/'.$product->images[0]->image_file
Remember to replace "store_url" with your store link.
Let me know if you need any other assistance.
Cheers :)
回答2:
From the code, it looks like the getProductImages has not been implemented. I added a quick patch. Use this pull request if it has not been merged yet (https://github.com/bigcommerce/bigcommerce-api-php/pull/61)
The code looks like this -
$images = Bigcommerce::getProductsImages(243);
print_r($images)
来源:https://stackoverflow.com/questions/17693235/how-to-get-product-images-via-php-sdk