Product::getProductsProperties(): 'id_image' returns 'en_default', not image

倖福魔咒の 提交于 2019-12-12 02:45:29

问题


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

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