stabman Posted March 20, 2013 Share Posted March 20, 2013 Hi guys, Running 1.4.8 and I was wondering how to display my smarty array (called via $smarty.post.customGB) on an email template. Something like this is easy to retrieve anywhere else but since the template is HTML I need a method. Can anyone help me? If there's anything else you need to know I'll post it. Thanks. Link to comment Share on other sites More sharing options...
vekia Posted March 20, 2013 Share Posted March 20, 2013 you should create variable in php and then insert it to Mail::Send function Link to comment Share on other sites More sharing options...
stabman Posted March 21, 2013 Author Share Posted March 21, 2013 Thanks although looking through Mail.php, I wouldn't even begin to know where or how to create the variable. Any tips on doing that though pointing out an example that's in the code would be just as helpful. Link to comment Share on other sites More sharing options...
vekia Posted March 21, 2013 Share Posted March 21, 2013 for the first please share the method that you use to send mails, ok? you use prestashop mail::send() or you use some external solution? Or something own? Link to comment Share on other sites More sharing options...
stabman Posted March 21, 2013 Author Share Posted March 21, 2013 Just the typical inbuilt send method in the Mail.php I believe. Haven't really messed with those kinds of files at all. Link to comment Share on other sites More sharing options...
vekia Posted March 21, 2013 Share Posted March 21, 2013 here is a part of send function: public static function Send($id_lang, $template, $subject, $template_vars, $to, $to_name = null, $from = null, $from_name = null, $file_attachment = null, $mode_smtp = null, $template_path = _PS_MAIL_DIR_, $die = false, $id_shop = null) as you see you've got above var: $template_vars you - should pass in this var all vars that you want to use in mail template How to pass variables? i will show you on example of order mail: Mail::Send($this->context->language->id, 'order_customer_comment', Mail::l('Message from a customer'), array( '{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname, '{email}' => $customer->email, '{id_order}' => (int)($order->id), '{order_name}' => $order->getUniqReference(), '{message}' => Tools::nl2br($msgText) ), $to, $toName, $customer->email, $customer->firstname.' '.$customer->lastname); so the answer is: you must create an array like array below: array( '{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname, '{email}' => $customer->email, '{id_order}' => (int)($order->id), '{order_name}' => $order->getUniqReference(), '{message}' => Tools::nl2br($msgText) ) thats all :-) Link to comment Share on other sites More sharing options...
stabman Posted March 21, 2013 Author Share Posted March 21, 2013 Cool I'll try it out. Link to comment Share on other sites More sharing options...
stabman Posted March 21, 2013 Author Share Posted March 21, 2013 Okay, here's my next problem: My variable is dynamically-created (hence $smarty.post.customGB) from a form. I don't think my site likes the prospect of referencing ('{cusGB}' => $smarty.post.customGB is definitely not gonna cut it) this so what's a good workaround? Link to comment Share on other sites More sharing options...
vekia Posted March 21, 2013 Share Posted March 21, 2013 you can get this variable in php controller -> $_POST['your_variable'] Link to comment Share on other sites More sharing options...
stabman Posted March 21, 2013 Author Share Posted March 21, 2013 (edited) To put things into perspective; A friend of mine has written this piece of code {foreach $smarty.post.customGB as $gb} {$gb}<br/> {/foreach} and it needs to get inserted into a mail template. With the help I got, I found out how to pass in the normal variables into the template but first I need to know how to assign this array to a global variable of my own creation. You mentioned php controller -> $_POST['your_variable'] but I don't know what php controller refers to (there are many controllers and such). I feel like I'm getting really close here. Edited March 21, 2013 by stabman (see edit history) Link to comment Share on other sites More sharing options...
alejcak Posted March 22, 2013 Share Posted March 22, 2013 (edited) Stabman and I are working on a project together and are having trouble passing the information from {$smarty.post.customGB} ***customGB is an array**** to be displayed in the order(displayed on the email template). We are up for any suggestions I have attached a few images to explain our problem. The prestashop 5-step-cart is where we are trying to get this working. I have used the {$smarty.post|print_r} to view the information passed. cart-step-2.jpg - has the text field where the information from [messages] is placed.(address step in cart) cart-step-3.jpg - the information from customGB is from the checkbox form.[messages] was passed to the next step(highlighted in yellow).(carrier step in cart) cart-step-3 select.jpg - when you select the checkbox, only those values are passed through into the customGB array.(carrier step in cart) cart-step-4.jpg - customGB array info has been passed.(highlighted in yellow)(payment step in cart) is it possible to attach the information(from smarty.post.customGB) to the [message], so that it will be displayed on the order email. We are up for any suggestions/solutions Any help will be much appreciated. Edited March 22, 2013 by alejcak (see edit history) Link to comment Share on other sites More sharing options...
Paul C Posted March 22, 2013 Share Posted March 22, 2013 (edited) The problem is that this is really non-trivial. Not sure I would be able to write a detailed how-to blind without seeing what's going on behind the scenes. A few observations/suggestions though: 1) The smarty.post.customGB issue is a bit of a red herring. All that variable does is store a copy of the data POSTed by a form. Within the order controller (i.e. back in the PHP world) you would access the POSTed variable using something like: $customGB = Tools:getValue('customGB','optional-default-value'); 2) There are several different ways that you could approach storing this additional data. You could override the Cart object and add an extra field (and also add the appropriate field in the associated database table) but that's kind of messy and I think over-complicating things for the future. A better approach might be to create a new object (and database table) that associates the cart_id with a serialised version of the $customGB array. If the number of options are always limited to a specific maximum number, then you can skip serialising the array and just store the options in separate fields. You can then use this anywhere you have a cart id to check if associated 'Gift Box' information exists and use it appropriately (e.g. in the admin area as well as in emails). EDIT: Actually your override can pass the additional template variables via the $extraVars parameter, so your override validateOrder function could simply call the parent valdateOrder() function AFTER you've retrieved the gift box data passing the result via $extraVars. MUCH simpler and more future-proof. 3) The actual display of the selected options in the order email is going to have to be done within the 'PaymentModule' class it looks like, as this is where the template variables are assigned and the email sent. The most straight-forward approach would likely be to override this and copy out the 'validateOrder' function from the core file. You can then modify this function in your override to also look up any associated Gift Box data and pass it to the email template along with all the other data (invoice and delivery addresses, products list etc.). 4) Once you've retrieved and assigned your data via smarty you can then code the order email template to display the data. I assume that this is an existing store, otherwise I would be strongly recommending you use 1.5.x for new developments!! Hope this helps! Edited March 22, 2013 by Paul C (see edit history) 1 Link to comment Share on other sites More sharing options...
stabman Posted March 22, 2013 Author Share Posted March 22, 2013 (edited) I appreciate your greatly detailed help. Thanks a lot! I have more questions to ask but since they will no longer have anything more to do with the original topic question and that question has already been answered for me, I will open a new one. Edited March 22, 2013 by stabman (see edit history) Link to comment Share on other sites More sharing options...
Paul C Posted March 22, 2013 Share Posted March 22, 2013 No problem, best of luck! I notice that my EDIT in the above is actually in the wrong place - it really refers to 3) not 2) so should probably be under there Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now