Fetch Product Images with BigCommerce API

徘徊边缘 提交于 2019-12-10 21:13:55

问题


Long story short a couple months ago i made a plugin for WordPress with the Bigcommerce API to fetch products in the Widget Area.

Now I have updated the Single File "Bigcommerce.php" and now the Function getProductImages () is none existent. And I cant seem to find the new function to get the Product Images. Maybe its just to late and Im tired or just plain Blind.

Please let me know how to fetch now the image for a specific product.

See below for the old code used i reverted back to the Old "Bigcommerce.php" and it works again but would ratehr use the new way.

    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>';

Thank you all in Advance


回答1:


You can get product images just by getting the "images" attribute of the product object. So, all you have to do is:

$productImages = $product->images;

You can also access images directly using the getCollection function:

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


来源:https://stackoverflow.com/questions/17604114/fetch-product-images-with-bigcommerce-api

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