Jump to content

Cannot Display All Active Products in my Custom Module


datshay

Recommended Posts

Hello,

 

I am on prestashop 1.5.5 and i am developing a custom module for my customer to display all the active products in the list.

 

I have a code as below : 

 

$products = Product::getProducts($this->context->language->id, 0, 100,'id_product','DESC');
$result = Product::getProductsProperties($this->context->language->id, $products);


$this->context->smarty->assign(array(
'products' => $result
));
I am able to get the list of all products but the images are not showing. The id_image is always en-default. I searched in the forum but didnt get a particular answer for this. Am i missing anything in the code ?
 
Can somebody please help me ?
 
Thank you !
 
Link to comment
Share on other sites

 

Hello,

 

I am on prestashop 1.5.5 and i am developing a custom module for my customer to display all the active products in the list.

 

I have a code as below : 

 

$products = Product::getProducts($this->context->language->id, 0, 100,'id_product','DESC');
$result = Product::getProductsProperties($this->context->language->id, $products);


$this->context->smarty->assign(array(
'products' => $result
));
I am able to get the list of all products but the images are not showing. The id_image is always en-default. I searched in the forum but didnt get a particular answer for this. Am i missing anything in the code ?
 
Can somebody please help me ?
 
Thank you !

 

 

hi..

 

you can use this code in smarty to image display

{$link->getImageLink($products.link_rewrite, $products.id_image, 'home_default')|escape:'html':'UTF-8'}

this code retrive the image src of product

 

tnaks..

Link to comment
Share on other sites

hi..

 

you can use this code in smarty to image display

{$link->getImageLink($products.link_rewrite, $products.id_image, 'home_default')|escape:'html':'UTF-8'}

this code retrive the image src of product

 

tnaks..

 

In the code of Nishith, replace $products by the key you defined in your foreach loop

 

And 'home_default' by the image size format you want

Link to comment
Share on other sites

Hi Nishith and okrSynolia,

 

Thank you for replying to my topic.

 

Well I tried nishith idea and replaced the $products variable and image size with my own code. But still it the image is not showing. Here is my TPL file code and a picture of what i get in the browser.

<div id="dtsloadmore" class="block clearfix">
{foreach from=$products item=product name=dtsloadmoreProducts}
    <a href="{$product.link|escape:'html'}" title="{$product.name|escape:html:'UTF-8'}" class="product_image">
	    <img src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'dts_loadmore')|escape:'html'}" alt="{$product.name|escape:html:'UTF-8'}" />
    </a>
    //To Print out the image path
    {$link->getImageLink($product.link_rewrite, $product.id_image, 'dts_loadmore')|escape:'html':'UTF-8'}
{/foreach}
</div>

preview.jpg

 

I checked the products array and the id_image value is en-default always. I dont know where am i missing.

Link to comment
Share on other sites

  • 11 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...