How to get main product image

  • Posts: 89
  • Thank you received: 2
  • Hikashop Multisite
7 months 4 days ago #361013

Hi,

We are currently working on some custom module, but stuck with one issue on how to get the main product image?
All our products mostly have 4-5 images. We only need to have the main image only for the custom module.

Thanks.

Please Log in or Create an account to join the conversation.

  • Posts: 83007
  • Thank you received: 13398
  • MODERATOR
7 months 4 days ago #361016

Hi,

Supposing that HikaShop is already loaded, you can use such code:

$productClass = hikashop_get('class.product');
$product = $productClass->getProduct($product_id);
$mainImageData = $product->images[0];
$imageHelper = hikashop_get('helper.image');
$image = $imageHelper->getThumbnail($mainImageData->file_path, array('width' => 300, 'height' => 200), array('default' => true, 'forcesize'=> true, 'scale' = 'inside') );
if($image->success) {
 echo $image->url; // URL of the 300*200 px thumbnail of the main image
 echo $image->origin_url; // URL of the main image
}

Please Log in or Create an account to join the conversation.

Time to create page: 0.058 seconds
Powered by Kunena Forum