Jump to content

Block new products does not show in a new module / hook


Recommended Posts

Hi,

 

I'm trying to figure out why my loop for blocknewproducts does not work in my new module / hook.

 

In my footer.tpl, I have this

<div class="lastRowPageRight col-md-9">
 {hook h='displayLastRowHomePage' mod='blocknewproducts'}
</div>

And for the module blocknewproducts, it have been hooked correctly in my backoffice admin.

 

Capture.JPG

 

Also, I have generated this part of code in the .php file.

public function hookDisplayLastRowHomePage($params)
	{
	    	if (!Configuration::get('PS_BLOCK_NEWPRODUCTS_DISPLAY') && !($newProducts = Product::getNewProducts((int)$params['cookie']->id_lang, 0, (int)Configuration::get('NEW_PRODUCTS_NBR'))))
		return;


		$this->smarty->assign(array(
		'new_products' => $newProducts,
		'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
		));
		return $this->display(__FILE__, 'blocknewproducts.tpl');
	}

In the main template file, it says : {if $new_products !== false} and it starts the foreach. On the reel "New products" page I can see them, but in my new module, nothing shows.

 

Any idea?

Edited by okidoo (see edit history)
Link to comment
Share on other sites

perhaps this if condition returns "return" 

	    	if (!Configuration::get('PS_BLOCK_NEWPRODUCTS_DISPLAY') && !($newProducts = Product::getNewProducts((int)$params['cookie']->id_lang, 0, (int)Configuration::get('NEW_PRODUCTS_NBR'))))
		return;

have you tested it without this return?

Link to comment
Share on other sites

When you ask without return? Are you trying to tell me to do this?

public function hookDisplayLastRowHomePage($params)
	{
		$this->smarty->assign(array(
		'new_products' => $newProducts,
		'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
		));
		return $this->display(__FILE__, 'blocknewproducts.tpl');
	}

This is what I have tried and the output returns only my <ul>

 

I think it might be my loop in the .tpl file that could be broken.

 

Here is my code from my theme module/block/ .tpl

<!-- MODULE Block new products -->

<section id="new-products_block_right" class="block products_block column_box">

	<h4 class="title_block"><span class="couleur_mauve bold">{l s='New products' mod='blocknewproducts'}</span></h4>

	<div class="block_content toggle_content">

	{if $new_products !== false}

		<ul class="products">

		{foreach from=$new_products item=newproduct name=myLoop}

        	<li class="shop_box clearfix ajax_block_product col-md-3 {if $smarty.foreach.myLoop.first}first_item{elseif $smarty.foreach.myLoop.last}last_item{else}item{/if}">

     

                	<a class="products_block_img" href="{$newproduct.link|escape:'html'}" title="{$newproduct.legend|escape:html:'UTF-8'}"><img src="{$link->getImageLink($newproduct.link_rewrite, $newproduct.id_image, 'medium_default')|escape:'html'}" alt="{$newproduct.legend|escape:html:'UTF-8'}" /></a>

         

                <div >

            	<h5 class="s_title_block">

					<a class="product_link" href="{$newproduct.link|escape:'html'}" title="{$newproduct.name|escape:html:'UTF-8'}">{$newproduct.name|strip_tags:'UTF-8'|truncate:22:'...'}</a>

            	</h5>

            	
            		
				{if $newproduct.description_short}

            		<p class="product_desc">{$newproduct.description_short|strip_tags:'UTF-8'|truncate:60:'...'}</p>

                    <a href="{$newproduct.link|escape:'html'}" class="lnk_more">{l s='Read more' mod='blocknewproducts'} <i class="icon-caret-right"></i></a>

            	{/if}

                </div>

            </li>

		{/foreach}

		</ul>

		<a href="{$link->getPageLink('new-products')|escape:'html'}" title="{l s='All new products' mod='blocknewproducts'}" class="btn btn-default button_large">{l s='All new products' mod='blocknewproducts'}</a>

	{else}

		<p>» {l s='Do not allow new products at this time.' mod='blocknewproducts'}</p>

	{/if}

	</div>

</section>

<!-- /MODULE Block new products -->
Link to comment
Share on other sites

×
×
  • Create New...