How to get Product images via PHP SDK

回眸只為那壹抹淺笑 提交于 2019-12-12 02:33:28

问题


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

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