Jump to content

Show products data like products list page for the selected product ids


prestashop_newuser

Recommended Posts

 I want to display all of the data of the products just like the product loop page. For that I have an array of products id. The code s like this

$id_lang=Configuration::get('PS_LANG_DEFAULT');
    $id_products = array(2,3,4,6,7);
    $all_products = array();
    foreach ($id_products as $id_product ) {
      $product_id = $id_product['id_product'];
      $link = new Link();
      $image = Image::getCover($product_id);
      $url = $link->getProductLink($product_id);          
      $product = new Product($product_id);
      $imagePath = Link::getImageLink($product->link_rewrite,   $image['id_image'], 'home_default');          
      array_push($all_products, $product);
    }
    
        $this->context->smarty->assign(
            array(
              'all_products' => $all_products,
              'lang_id'      => $id_lang,
              'url'         => $url,
            )
        );

and in the smarty I have done my code like this

<ul>
     <!-- {$all_products|@print_r} -->
    {foreach from=$all_products item=product name=product}
    
    <li class="col-xs-12 col-sm-4 col-md-3  first-in-line">
    	<div class="product-container" itemscope itemtype="http://schema.org/Product">
    		<div class="left-block">
    			<div class="product-image-container">
    
    				<a class="product_img_link" href="{$url}" title="{$product->name|escape:'html':'UTF-8'}" itemprop="url">
    					<img class="replace-2x img-responsive" src="" >
    				</a> 
    				
    			</div>
    		</div>
    	</div>
    {/foreach}
    </ul>

Here in the smarty I have done copy and paste `product-list.tpl` files code as I want my custom loop should look exactly like that but it is showing many errors. So can someone kindly tell me how can I get the exactly look of the product list page with products id? Any help and suggestions will be really appreciable. Thanks

Link to comment
Share on other sites

It's better to call product-list.tpl than copy it. For example, category.tpl contains code the following code:

		{if $products}
			<div class="content_sortPagiBar clearfix">
            	<div class="sortPagiBar clearfix">
            		{include file="./product-sort.tpl"}
                	{include file="./nbr-product-page.tpl"}
				</div>
                <div class="top-pagination-content clearfix">
                	{include file="./product-compare.tpl"}
					{include file="$tpl_dir./pagination.tpl"}
                </div>
			</div>
			{include file="./product-list.tpl" products=$products}
			<div class="content_sortPagiBar">
				<div class="bottom-pagination-content clearfix">
					{include file="./product-compare.tpl" paginationId='bottom'}
                    {include file="./pagination.tpl" paginationId='bottom'}
				</div>
			</div>
		{/if}

You just need to pass the $products in the right format. I think you could copy the query from the Product:getProducts function, then add `id_product` IN (2,3,4,6,7) to the WHERE clause.

Link to comment
Share on other sites

It's better to call product-list.tpl than copy it. For example, category.tpl contains code the following code:

		{if $products}
			<div class="content_sortPagiBar clearfix">
            	<div class="sortPagiBar clearfix">
            		{include file="./product-sort.tpl"}
                	{include file="./nbr-product-page.tpl"}
				</div>
                <div class="top-pagination-content clearfix">
                	{include file="./product-compare.tpl"}
					{include file="$tpl_dir./pagination.tpl"}
                </div>
			</div>
			{include file="./product-list.tpl" products=$products}
			<div class="content_sortPagiBar">
				<div class="bottom-pagination-content clearfix">
					{include file="./product-compare.tpl" paginationId='bottom'}
                    {include file="./pagination.tpl" paginationId='bottom'}
				</div>
			</div>
		{/if}

You just need to pass the $products in the right format. I think you could copy the query from the Product:getProducts function, then add `id_product` IN (2,3,4,6,7) to the WHERE clause.

 

thanks for the reply. I have tried that, I have used getProducts() function from Product class but still I am not getting values like product image, still getting error like

 

Notice: Undefined index: price_tax_exc in /var/www/Prestashop/cache/smarty/compile/92/c5/39/92c53991fb98f787f26965c3dc699a52afa4a4f9.file.product-list.tpl.php on line 131

 

Notice: Undefined index: id_product_attribute in /var/www/Prestashop/cache/smarty/compile/92/c5/39/92c53991fb98f787f26965c3dc699a52afa4a4f9.file.product-list.tpl.php on line 245
 
Notice: Undefined index: allow_oosp in /var/www/Prestashop/cache/smarty/compile/92/c5/39/92c53991fb98f787f26965c3dc699a52afa4a4f9.file.product-list.tpl.php on line 246
 
So can you tell me how to solve this?
Edited by prestashop_newuser (see edit history)
Link to comment
Share on other sites

Sorry, it's hard for me to answer here. There are many variables and you must make sure the product array contains them all. You can try overriding the Category::getProducts to add a new parameter like id_products, then if it is set, you can change the WHERE clause to get just those products instead of all the category's products. Then you can override CategoryController to check for a certain query string and then pass the array of product IDs into the Category::getProducts function.

 

I'm not sure whether this is the best solution though. There's many ways it could be done. Once you're calling all the right functions, you should stop getting the notices.

Link to comment
Share on other sites

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...