Jump to content

Problem overriding block specials home


Recommended Posts

Hi,

 

I overrode the block specials home template but now the specials products seem empty.

I created a file blockspecials-home.tpl in themes/mytheme/modules/blockspecials. I just added text and the modification is taken into account but the variable $specials returns nothing so I have the message "No special products at this time.".

 

I specify that I have specials products. They are displayed if i remove my override.

This is the content of my file

<p>{l s='Hello' mod='blockspecials'}</p>
{if isset($specials) && $specials}
	{include file="$tpl_dir./product-list.tpl" products=$specials class='blockspecials tab-pane' id='blockspecials'}
{else}
<ul id="blockspecials" class="blockspecials tab-pane">
	<li class="alert alert-info">{l s='No special products at this time.' mod='blockspecials'}</li>
</ul>
{/if}

I just added a paragraph...

 

Do I need to declare the variable $specials as global or do something else?

 

Sorry, but now it works...I just change the variable _PS_MODE_DEV_ to true. I put it to false again and it works.

I don't know happened... :huh:

Edited by titchagcreation (see edit history)
  • Thanks 1
Link to comment
Share on other sites

Actually, I go further with the analysis of the module block specials.

I had this initial problem again after my browser crashed ( so I reset all my browser sessions). 

I viewed the BlockSpecials class. The list of specials products is given by the static variable $cache_specials which is generated in hookDisplayHomeTab(...) and hookRightColumn(...) but this variable is only generated if the blockspecials.tpl or the tab.tpl are not cached. It is weird! Because if the templates are not modified this variable is not calculated anymore...so if you change the special products (add/remove/update) the list is not refreshed on the user browser.

In my case, my session was reset so the static variable $cache_specials was reinitialized and the list of products disappeared. After I cleared the cache of the templates, this variable was calculated again and the list of products appeared again.

Personnally, I overrode the BlockSpecials class and redefined the hookDisplayHomeTabContent(...) function. I didn't redefine hookRightColumn(...) because I don't need it (I don't display the right hook). In the redefined method, I force the calculation of BlockSpecials::$cache_specials so I am sure that the list is always up-to-date.

public function hookDisplayHomeTabContent($params)
	{
		if (Configuration::get('PS_CATALOG_MODE'))
			return;
		
		BlockSpecials::$cache_specials = Product::getPricesDrop((int)$params['cookie']->id_lang, 0, Configuration::get('BLOCKSPECIALS_SPECIALS_NBR'));

		if (!$this->isCached('blockspecials-home.tpl', $this->getCacheId('blockspecials-home')))
		{
			$this->smarty->assign(array(
				'specials' => BlockSpecials::$cache_specials,
				'homeSize' => Image::getSize(ImageType::getFormatedName('home'))
			));
		}

		if (BlockSpecials::$cache_specials === false)
			return false;

		return $this->display(__FILE__, 'blockspecials-home.tpl', $this->getCacheId('blockspecials-home'));
	}

I am the only one who had problems with this block?

  • Like 1
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...