VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: Kuubs on April 02, 2020, 15:18:01 PM

Title: Get product image by id
Post by: Kuubs on April 02, 2020, 15:18:01 PM
Hello,

I want. to display the child products images in a certain way. I have this code, but it doesn't get the images attached to the product:


$productModel = VmModel::getModel('Product');
$products = $productModel->getProductChildIds( $product->virtuemart_product_id);

foreach ($products as $key => $value) {

$childprod = $productModel->getProduct($value);

}



But there isn't anything regarind images in this object. Does anyone know ho I get the image of this certain product?
Title: Re: Get product image by id
Post by: Kuubs on April 02, 2020, 15:28:04 PM
Fixed it.


Needed to add


$productModel->addImages($childprod,1);
Title: Re: Get product image by id
Post by: beltoforion on April 02, 2020, 20:02:58 PM
hey hubbs can you post your full fixed code?
Title: Re: Get product image by id
Post by: Kuubs on April 12, 2020, 21:48:46 PM
Quote from: beltoforion on April 02, 2020, 20:02:58 PM
hey hubbs can you post your full fixed code?

Yeah sure:



<?php 

$productModel 
VmModel::getModel('Product');

$products $productModel->getProductChildIds$product->virtuemart_product_id);

foreach (
$products as $key => $value) {

$childprod $productModel->getProduct($value);

$productModel->addImages($childprod,1);

}

?>




Let me know if this works for you!