gpt4 book ai didi

php - 使用 BigCommerce API 获取产品图片

转载 作者:搜寻专家 更新时间:2023-10-31 21:36:41 25 4
gpt4 key购买 nike

长话短说,几个月前,我使用 Bigcommerce API 为 WordPress 制作了一个插件,用于在小部件区域中获取产品。

现在我更新了单个文件“Bigcommerce.php”,现在函数 getProductImages () 不存在了。而且我似乎无法找到获取产品图片的新功能。也许是太晚了,我累了,或者只是瞎了眼。

请告诉我现在如何获取特定产品的图像。

查看下面使用的旧代码,我恢复到旧的“Bigcommerce.php”,它再次工作,但 ratehr 会使用新的方式。

    Bigcommerce::configure(array(
'store_url' => $store_url,
'username' => $username,
'api_key' => $api_key
));

Bigcommerce::setCipher('RC4-SHA');
Bigcommerce::verifyPeer(false);


$countProducts = 0;
$products = Bigcommerce::getProducts();
shuffle($products);
echo '<div class="BCStoreWidget">';


if (!$products) {
echo '<div class="BCerror">';
$error = Bigcommerce::getLastError();
echo $error->code;
echo $error->message;
echo '</div>';
} else {

foreach ($products as $product) {
$productImages = Bigcommerce::getProductImages($product->id);

echo '<h4>' . $product->name . '</h4>';
if ($productImages->image_file){
echo '<div class="pimage">';
echo '<a href="'. $store_url . $product->custom_url . '"><img src="' . $store_url . '/product_images/' . $productImages->image_file . '"></a>';
echo '</div>';
}

// echo '<p>' . substr($product->description,0,100) . '&nbsp;...</p>';
echo '<p>' . number_format($product->price, 2, '.', '') . '&nbsp; USD</p>';
echo '<p><a href="'. $store_url . $product->custom_url . '" class="button"> Buy Now </a></p>';
$countProducts++;
if ($countProducts == $max_show)
break;
}
}


echo '</div>';

先谢谢大家

最佳答案

只需获取产品对象的“images”属性即可获取产品图片。所以,您所要做的就是:

$productImages = $product->images;

您还可以使用 getCollection 函数直接访问图像:

Bigcommerce::getCollection('/products/'.$product_id.'/images/');

关于php - 使用 BigCommerce API 获取产品图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17604114/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com