Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Add a message at top of page


alexloh

Recommended Posts

If you want it exactly like that with the little WARNING image thing in /catalog/includes/header.php around like 51 locate:

 

if ($messageStack->size('header') > 0) {
echo $messageStack->output('header');
 }

 

Just ABOVE that add:

 

$messageStack->add('header', 'This is a message at the top of the screen ... write whatever you want!', 'warning');

 

Ofcourse changing This is a message at the top of the screen ... write whatever you want! to your text ...

 

If you dont want the warning icon then use:

 

$messageStack->add('header', 'This is a message at the top of the screen ... write whatever you want!');

 

PLEASE BACKUP YOUR FILE BEFORE MAKING CHANGES!!

Link to comment
Share on other sites

Thanks, sLaV-, for your prompt answer :)

 

One more question... If I want to change the background color of the above said message, where is the line of code that I should modify?

 

That would require a bit more work than you think ... the class is controlled by CSS with this line in your stylesheet.css file:

 

.messageStackError, .messageStackWarning { font-family: Verdana, Arial, sans-serif; font-size: 10px; background-color: #ffb3b5; }

 

you COULD change that background-color property to whatever you want as your background colour, however doing so will change the background colour for ALL that use this class - all errors and warning which is something you DONT want to do!

 

to accomplish something like that you'd need to create a new instance of messageStack then use a new class to define its properties

 

ok do lets start from the start ... first thing is in /catalog/includes/header.php that lines of code I told you to add, we need to change them....so change:

 

$messageStack->add('header', 'This is a message at the top of the screen ... write whatever you want!', 'warning');

 

to:

 

$messageStack->add('personal', 'This is a message at the top of the screen ... write whatever you want!', 'personal');
if ($messageStack->size('personal') > 0) {
echo $messageStack->output('personal');
 }

 

remember that needs to go ABOVE the

if ($messageStack->size('header') > 0) {
echo $messageStack->output('header');
 }

bit of code!

 

ok next open /catalog/includes/classes/message_stack.php ... find this bit of code:

// class methods
function add($class, $message, $type = 'error') {
  if ($type == 'error') {
	$this->messages[] = array('params' => 'class="messageStackError"', 'class' => $class, 'text' => tep_image(DIR_WS_ICONS . 'error.gif', ICON_ERROR) . ' ' . $message);
  } elseif ($type == 'warning') {
	$this->messages[] = array('params' => 'class="messageStackWarning"', 'class' => $class, 'text' => tep_image(DIR_WS_ICONS . 'warning.gif', ICON_WARNING) . ' ' . $message);
  } elseif ($type == 'success') {
	$this->messages[] = array('params' => 'class="messageStackSuccess"', 'class' => $class, 'text' => tep_image(DIR_WS_ICONS . 'success.gif', ICON_SUCCESS) . ' ' . $message);
  } else {
	$this->messages[] = array('params' => 'class="messageStackError"', 'class' => $class, 'text' => $message);
  }
}

 

and change it to:

 

// class methods
function add($class, $message, $type = 'error') {
  if ($type == 'error') {
	$this->messages[] = array('params' => 'class="messageStackError"', 'class' => $class, 'text' => tep_image(DIR_WS_ICONS . 'error.gif', ICON_ERROR) . ' ' . $message);
  } elseif ($type == 'warning') {
	$this->messages[] = array('params' => 'class="messageStackWarning"', 'class' => $class, 'text' => tep_image(DIR_WS_ICONS . 'warning.gif', ICON_WARNING) . ' ' . $message);
  } elseif ($type == 'personal') {
	$this->messages[] = array('params' => 'class="messageStackPersonal"', 'class' => $class, 'text' => tep_image(DIR_WS_ICONS . 'warning.gif', ICON_WARNING) . ' ' . $message);
  } elseif ($type == 'success') {
	$this->messages[] = array('params' => 'class="messageStackSuccess"', 'class' => $class, 'text' => tep_image(DIR_WS_ICONS . 'success.gif', ICON_SUCCESS) . ' ' . $message);
  } else {
	$this->messages[] = array('params' => 'class="messageStackError"', 'class' => $class, 'text' => $message);
  }
}

 

PLEASE NOTE: The above bit will display the warning icon next to the text, if you do NOT wish to have the warning icon thing before the text, change the above to:

 

// class methods
function add($class, $message, $type = 'error') {
  if ($type == 'error') {
	$this->messages[] = array('params' => 'class="messageStackError"', 'class' => $class, 'text' => tep_image(DIR_WS_ICONS . 'error.gif', ICON_ERROR) . ' ' . $message);
  } elseif ($type == 'warning') {
	$this->messages[] = array('params' => 'class="messageStackWarning"', 'class' => $class, 'text' => tep_image(DIR_WS_ICONS . 'warning.gif', ICON_WARNING) . ' ' . $message);
  } elseif ($type == 'personal') {
	$this->messages[] = array('params' => 'class="messageStackPersonal"', 'class' => $class, 'text' => $message);
  } elseif ($type == 'success') {
	$this->messages[] = array('params' => 'class="messageStackSuccess"', 'class' => $class, 'text' => tep_image(DIR_WS_ICONS . 'success.gif', ICON_SUCCESS) . ' ' . $message);
  } else {
	$this->messages[] = array('params' => 'class="messageStackError"', 'class' => $class, 'text' => $message);
  }
}

 

Lastly open /catalog/stylesheet.css and add a new class messageStackPersonal defining what you would like it to look like...

 

e.g - if you just want to change the background color use:

 

.messageStackPersonal { font-family: Verdana, Arial, sans-serif; font-size: 10px; background-color: #00ff00; }

 

The above will give you a green background - all we changed there was background-color: #00ff00;

 

PLEASE BACKUP ALL FILES BEFORE MAKING THESE CHANGES AS I HAVE NOT TESTED THIS SO NOT 100% SURE IF IT'LL WORK!!!!!!

Link to comment
Share on other sites

Thanks again, sLaV-, for your detailed guide/tutorial. I followed your guide exactly and it works as expected.

 

To have you in this support forum is really a blessing! Therefore you deserved for my 5-stars rating ***** :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...