Add custom order information to notification email

  • Posts: 45
  • Thank you received: 0
9 years 2 weeks ago #220415

-- HikaShop version -- : 2.6.0
-- Joomla version -- : 3.4.1

Hi,

In the cart I added code to show the discount percentage that they got and their advantage. That is this code:

      		<?php $total_amount = $this->currencyHelper->format($this->total->prices[0]->price_value_with_tax, $this->total->prices[0]->price_currency_id); 
			$percentage = $this->row->discount->discount_percent_amount;
			$perc_calc = 100 - $this->row->discount->discount_percent_amount;
			$perc_text = 1*$this->row->discount->discount_percent_amount.'%';
			$price_total = $this->total->prices[0]->price_value_with_tax;
			$advantage = (((100 / $perc_calc ) * $price_total * $percentage)) / 100 ;
			$advantage_format = number_format($advantage, 2);
			$value_order = ($price_total / $perc_calc) *100;
			$value_order_format = number_format($value_order, 2);

			echo "<p>The purchasing amount is € " . $price_total . ". With your discount " . $perc_text . " this means an advantage of <b>€ " . $advantage_format . "</b>. (The commercial store value is: € " . $value_order_format . ").</p><br />";
	?>

How can I get this information in the notification email as well? I tried different things, but they end up with errors in the email or blank pages...

Thanks in advance.

Please Log in or Create an account to join the conversation.

  • Posts: 82908
  • Thank you received: 13378
  • MODERATOR
9 years 2 weeks ago #220422

Hi,

In the order notifications, the information on the discount is not available.
So you can have such code unless you add some more custom code before that to load the discount and precalculate it and the prices of the product.
So you'll want to call the getPrices function of class.currency and give it the necessary parameters so that it can load the prices of the product and then you'll be able to use that code.

Please Log in or Create an account to join the conversation.

  • Posts: 45
  • Thank you received: 0
9 years 2 weeks ago #220454

Just an idea: would it be a solution to save the echo as a variable and put it in a session?

Please Log in or Create an account to join the conversation.

  • Posts: 82908
  • Thank you received: 13378
  • MODERATOR
9 years 2 weeks ago #220466

Hi,

It depends.
It will work for the order creation notification and the order admin notification, but it won't work for the order status notification in most cases as this email is usually sent with the payment gateway notifies your HikaShop that the payment has been made and thus, at that point, you're in the user session of the payment gateway, not the user session of the customer.

Please Log in or Create an account to join the conversation.

  • Posts: 45
  • Thank you received: 0
9 years 2 weeks ago #220600

Hi,

Well, I only need it in the order creation email, so that can be a good solution.

I've added the variable to the session and can use it on other pages. But how can I set it in the email? I guess I need to add it to the preload version and HTML version? But how? :unsure:

Thanks again.

Please Log in or Create an account to join the conversation.

  • Posts: 82908
  • Thank you received: 13378
  • MODERATOR
9 years 2 weeks ago #220635

Hi,

You can add it directly in the HTML version.
For example:

<?php echo $_SESSION['my_variable'];

Please Log in or Create an account to join the conversation.

  • Posts: 45
  • Thank you received: 0
9 years 1 week ago #220796

Thanks, but didn't work. What i did was the following:

1. I set the variable in the cart - showcart view.
2. In the checkout-cart view I load it and it does show the value I want.
3. I used several codes to try to get it in the email, but it remains empty or throwes a 500-error.

This code works in the checkout, but throws a 500-error in the email:

<?php
// Grab session ##
$session = JFactory::getSession();
$value_format = $session->get('value_format');
echo $value_format;
?>

I also tried the following codes, but they remained without result/data (but no error):
<?php // echo $_SESSION['value_format']; ?> 
and
<?php // print "{$_SESSION['value_format']}"; ?>

Thanks, hope you can help me with this.

Please Log in or Create an account to join the conversation.

  • Posts: 45
  • Thank you received: 0
9 years 1 week ago #221016

Well, I managed to get this to work. The code needed to be altered a little.

Maybe it can help someone else in the future, so this is what I did:

In cart - showcart.php I added the following code to get the variables in the session:

 <?php   
    $session = JFactory::getSession();
$registry = $session->get('registry');
$session->set('value_format', $value_format);
$registry->set('value_format', $value_format);
  ?>

In the email HTML-version I added the following code:
<?php
// Grab session ##
$session = JFactory::getSession();
$value_format = $session->get('value_format');
echo $value_format;
?>

One tip if you want to know what Joomla stored in the session (this helped me a lot):
<?php
$registry = $session->get('registry');
echo $registry;
?>

Maybe it could be better or cleaner, but it works!

So, maybe someone can help me with my other question ??? ;)

Last edit: 9 years 1 week ago by Squashtoppertje.

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
9 years 1 week ago #220953

Hi,

Just to be sure, when using the echo or print, the lines were not commented ?
Where in the email do you have placed this code ? In the preload part ?

Please Log in or Create an account to join the conversation.

  • Posts: 45
  • Thank you received: 0
9 years 1 week ago #221070

Hi,

You mean that last code? I placed in the HTML-version. The lines were readable, allthough a bit messy. But was just to give me some more info.

I also used that code on the checkout-cart view.

Please Log in or Create an account to join the conversation.

Time to create page: 0.082 seconds
Powered by Kunena Forum