Jump to content

Date of last added product


Recommended Posts

I suggest adding the following code in the appropriate PHP file for the TPL you are displaying the date in:

$result = Db::getInstance()->executeS('SELECT MAX(`date_add`) FROM `'._DB_PREFIX_.'product`');
$lastProductAddedDate = $result['MAX(`date_add`)'];
$smarty->assign('lastProductAddedDate', $lastProductAddedDate);



Then you can use {$lastProductAddedDate} in the TPL wherever you want the date displayed.

Link to comment
Share on other sites

  • 3 months later...

Thank you,

I am trying to use it on editorial module, which displays some text on homepage, whee in modules/editorial/editorial.php should I insert this code? Also will it work if i put {$lastProductAddedDate} in the text while editing the home text (i.e. not in .tpl)?

Link to comment
Share on other sites

No, you can't use Smarty code in the text editor on the configuration page. You can only use Smarty code in TPL files.

Change the hookHome function in modules/editorial/editorial.php from:

function hookHome($params)
{
   if (file_exists('modules/editorial/editorial.xml'))
   {
       if ($xml = simplexml_load_file('modules/editorial/editorial.xml'))
       {
           global $cookie, $smarty;
           $smarty->assign(array(
               'xml' => $xml,
               'homepage_logo' => file_exists('modules/editorial/homepage_logo.jpg'),
               'logo_subheading' => 'logo_subheading_'.$cookie->id_lang,
               'title' => 'title_'.$cookie->id_lang,
               'subheading' => 'subheading_'.$cookie->id_lang,
               'paragraph' => 'paragraph_'.$cookie->id_lang,
               'this_path' => $this->_path
           ));
           return $this->display(__FILE__, 'editorial.tpl');
       }
   }
   return false;
}



to:

function hookHome($params)
{
   if (file_exists('modules/editorial/editorial.xml'))
   {
       if ($xml = simplexml_load_file('modules/editorial/editorial.xml'))
       {
           global $cookie, $smarty;
           $result = Db::getInstance()->executeS('SELECT MAX(`date_add`) FROM `'._DB_PREFIX_.'product`');
           $lastProductAddedDate = $result['MAX(`date_add`)'];
           $smarty->assign(array(
               'xml' => $xml,
               'homepage_logo' => file_exists('modules/editorial/homepage_logo.jpg'),
               'logo_subheading' => 'logo_subheading_'.$cookie->id_lang,
               'title' => 'title_'.$cookie->id_lang,
               'subheading' => 'subheading_'.$cookie->id_lang,
               'paragraph' => 'paragraph_'.$cookie->id_lang,
               'this_path' => $this->_path,
               'lastProductAddedDate', $lastProductAddedDate
           ));
           return $this->display(__FILE__, 'editorial.tpl');
       }
   }
   return false;
}



Then you can put {$lastProductAddedDate} wherever you want in editorial.tpl.

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