Jump to content

Order email, doing math calculations with the smarty variables?


Recommended Posts

Hello!

In the mails folder there's lots of cool html templates which are used for the emails which presta shop sends out. I am wanting to add a text field to 'order_conf.html' which basically does a calculation on the price, divides it by 11 and displays the result in another field. Using HTML and smarty in this document, how would this be possible?

It seems in this document I can only use certain varaibles, for example.
{total_paid}

But as soon as I type in a variable that it doesn't recognise it displays it as text.

I've tried this but it just displays as text:

{math equation="total_paid / 11}

I even tried going into Order.php in the classes folder and attempted to do the calculation there and send in a new variable, however when I tried to send in a new variable I get a hack attempt error, and I think it doesn't like me doing that.

Any ideas?

Thank you very much!

David

Share this post


Link to post
Share on other sites

You cannot do it that way, you need to set a new variable in the same place that {total_paid} gets set.
In there, you will be able to do math calculations.

{total_paid} is not a smarty code, it's a swift email "code"

Share this post


Link to post
Share on other sites

Thank you, when I set a new variable where total_paid is defined and pass it through with the array of other variables, I get the hack attempt error. Any ideas how I might go about fixing this?

Share this post


Link to post
Share on other sites
Thank you, when I set a new variable where total_paid is defined and pass it through with the array of other variables, I get the hack attempt error. Any ideas how I might go about fixing this?


Can you paste the original code and the changes you made?

Share this post


Link to post
Share on other sites

Sure!

I made some small changes to 'Orders.php', I am attempting to get the variable total_GST passed through, even if it holds the same value as the price.

It seems as soon as I make changes to $fieldsRequired, $fieldsSize and $fieldsValidate it gives me the hack attempt report.

Thank you! Here are the changes:

   /** @var float Total really paid */
   public         $total_GST;

   /** @var float Total to pay */
   public         $total_paid;



   protected    $fieldsRequired = array('id_address_delivery', 'id_address_invoice', 'id_cart', 'id_currency', 'id_lang', 'id_customer', 'id_carrier', 'payment', 'total_GST', 'total_paid', 'total_paid_real', 'total_products');
   protected    $fieldsSize = array('payment' => 33);
   protected    $fieldsValidate = array(
       'id_address_delivery' => 'isUnsignedId',
       'id_address_invoice' => 'isUnsignedId',
       'id_cart' => 'isUnsignedId',
       'id_currency' => 'isUnsignedId',
       'id_lang' => 'isUnsignedId',
       'id_customer' => 'isUnsignedId',
       'id_carrier' => 'isUnsignedId',
       'secure_key' => 'isMd5',
       'payment' => 'isGenericName',
       'recyclable' => 'isBool',
       'gift' => 'isBool',
       'gift_message' => 'isMessage',
       'total_discounts' => 'isPrice',
       'total_GST' => 'isPrice',
       'total_paid' => 'isPrice',
       'total_paid_real' => 'isPrice',
       'total_products' => 'isPrice',
       'total_shipping' => 'isPrice',
       'total_wrapping' => 'isPrice',
       'shipping_number' => 'isUrl'
   );



   public function getFields()
   {
       parent::validateFields();

       $fields['id_address_delivery'] = intval($this->id_address_delivery);
       $fields['id_address_invoice'] = intval($this->id_address_invoice);
       $fields['id_cart'] = intval($this->id_cart);
       $fields['id_currency'] = intval($this->id_currency);
       $fields['id_lang'] = intval($this->id_lang);
       $fields['id_customer'] = intval($this->id_customer);
       $fields['id_carrier'] = intval($this->id_carrier);
       $fields['secure_key'] = pSQL($this->secure_key);
       $fields['payment'] = pSQL($this->payment);
       $fields['module'] = pSQL($this->module);
       $fields['recyclable'] = intval($this->recyclable);
       $fields['gift'] = intval($this->gift);
       $fields['gift_message'] = pSQL($this->gift_message);
       $fields['shipping_number'] = pSQL($this->shipping_number);
       $fields['total_discounts'] = floatval($this->total_discounts);
       $fields['total_GST'] = floatval($this->total_paid);
       $fields['total_paid'] = floatval($this->total_paid);
       $fields['total_paid_real'] = floatval($this->total_paid_real);
       $fields['total_products'] = floatval($this->total_products);
       $fields['total_shipping'] = floatval($this->total_shipping);
       $fields['total_wrapping'] = floatval($this->total_GST);
       $fields['invoice_number'] = intval($this->invoice_number);
       $fields['delivery_number'] = intval($this->delivery_number);
       $fields['invoice_date'] = pSQL($this->invoice_date);
       $fields['delivery_date'] = pSQL($this->delivery_date);
       $fields['valid'] = intval($this->valid) ? 1 : 0;
       $fields['date_add'] = pSQL($this->date_add);
       $fields['date_upd'] = pSQL($this->date_upd);

       return $fields;
   }

Share this post


Link to post
Share on other sites

You are trying to change the wrong place.

The email variables for the order confirmations are set in /classes/PaymentModule.php

Line 330 is

'{total_paid}' => Tools::displayPrice($order->total_paid, $currency, false, false),



You can add

'{total_paid}' => Tools::displayPrice($order->total_paid, $currency, false, false),
'{total_GSM}' => Tools::displayPrice($order->total_paid / 10, $currency, false, false),



I used / 10, but you can use any math calculation you need.

Share this post


Link to post
Share on other sites
  • 6 months later...

I would like the same thing

I try in Classes/PaymentModule.php:

'{total_GSM}' => Tools::displayPrice($order->total_paid / 10, $currency, false, false), 



and mail : {total_GSM}

It doesn't work (not convert)

Can you help me please???

Share this post


Link to post
Share on other sites
  • 2 weeks later...
  • 11 months later...

I need the email variables for the order confirmationsPrestashop 2.5 when the order total is divided by 3,

example :

 

=> order total : 99£

=> 99/3 = 33£

 

In the email confirmation order :

 

 

" Dear custommer

 

Your paid 33£ per month"

 

An then, if the total order is 100€

 

=> 100£/3 = 33.33£

 

" Dear custommer

 

Your paid 33,33£ per month"

Share this post


Link to post
Share on other sites
  • 10 months later...

Sorry for a long time

 

I test follow instructions but doesn't work .

 

I changed version of prestashop. I'm 1.4.8.

 

In PaymentModule.php i add :

 

'{total_GSM}' => Tools::displayPrice($order->total_paid/3, $currency, false),

 

But in the mail automatic "Waiting for payment"

 

{total_GSM}

is not convert .

 

To remember, i would like divide {total-paid} in the email customer's when he pass order

Share this post


Link to post
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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More