问题
I've build a module to make a custom page with some products. I've tried to
//get all products
$products_partial = Product::getProducts($this->context->language->id, 0, 1000, 'name', 'asc');
$products = Product::getProductsProperties($this->context->language->id, $products_partial);
foreach ($products as $product)
{
//here comes some logic to select some products (not relevant for this question)
//echo the image ID
$results[] = $product;
}
$this->context->smarty->assign(array(
'products' => $results
));
//this is a copy of themes/default/product-list.tpl
$this->setTemplate("product-list.tpl");
Now all products are shown, but without the right image. It turns out that $product['id_image'] is set to 'en_default', but I don't know why. But why?
I've tried to search for the problem on the PrestaShop forums, and I found people with the same problem (1, 2), but there was no solution given.
回答1:
Look at a function, that sets the en_default
and I think it is clear, why it does, what it does.
public static function defineProductImage($row, $id_lang)
{
if (isset($row['id_image']))
if ($row['id_image'])
return $row['id_product'].'-'.$row['id_image'];
return Language::getIsoById((int)$id_lang).'-default';
}
This is from 1.5 version.
来源:https://stackoverflow.com/questions/19820924/productgetproductsproperties-id-image-returns-en-default-not-image