Get product image path
7 years 5 months ago #307472
by kyratn
Get product image path was created by kyratn
Hi,
How would i get product image in custom module. Doing like this:
Doesn't return image at all inside product variable.
The only way i could get it, was using sql query like this:
But i think there should be a better way doing this with hikashop code it self??
Please advise.
Thank you
How would i get product image in custom module. Doing like this:
Code:
<?php
$productClass = hikashop_get('class.product');
$product = $productClass->get($id);
var_dump($product);
?>
Doesn't return image at all inside product variable.
The only way i could get it, was using sql query like this:
Code:
$db = JFactory::getDbo();
$sql = 'SELECT file_path FROM '.hikashop_table('file').' WHERE file_type="product" AND file_ref_id='.$id;
$db->setQuery($sql);
$path = $db->loadObjectList();
But i think there should be a better way doing this with hikashop code it self??
Please advise.
Thank you
Please Log in or Create an account to join the conversation.
7 years 5 months ago #307474
by nicolas
Replied by nicolas on topic Get product image path
Hi,
If you do this, you'll get the images data preloaded in $product:
Then, if you want the URL of the image it's really easy:
And you can replace images/com_hikashop/upload/ with the path you actually configured in the "upload folder" setting of the HikaShop configuration if you changed the default one.
If you do this, you'll get the images data preloaded in $product:
Code:
<?php
$productClass = hikashop_get('class.product');
$product = $productClass->getProduct($id);
var_dump($product);
?>
Code:
<?php
foreach($product->images as $image) {
echo JURI::base(true).'images/com_hikashop/upload/'.$image->file_path;
}
?>
The following user(s) said Thank You: kyratn
Please Log in or Create an account to join the conversation.
7 years 5 months ago #307494
by kyratn
Replied by kyratn on topic Get product image path
Hi,
Well that's strange. Doing var_dump($product) i couldn't see image or file path at all... Now it works.
Thank you
Well that's strange. Doing var_dump($product) i couldn't see image or file path at all... Now it works.
Thank you
Please Log in or Create an account to join the conversation.
7 years 5 months ago #307495
by nicolas
Replied by nicolas on topic Get product image path
Hi,
The code you gave in your first message was using the "get" function of class.product which doesn't load the images. The code I gave you uses the "getProduct" function which also load the images.
The code you gave in your first message was using the "get" function of class.product which doesn't load the images. The code I gave you uses the "getProduct" function which also load the images.
The following user(s) said Thank You: kyratn
Please Log in or Create an account to join the conversation.
7 years 5 months ago #307535
by kyratn
Replied by kyratn on topic Get product image path
Hi,
Thank you Nicolas. I haven't noticed it
Would be great if you could improve development documantation under code samples. Because sometimes it's hard to find some code samples even via forum.
Thank you
Thank you Nicolas. I haven't noticed it
Would be great if you could improve development documantation under code samples. Because sometimes it's hard to find some code samples even via forum.
Thank you
The following user(s) said Thank You: nicolas
Please Log in or Create an account to join the conversation.
Time to create page: 0.050 seconds