Closed (outdated)
Project:
Commerce Email
Version:
7.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
29 May 2012 at 09:08 UTC
Updated:
2 Jun 2020 at 18:23 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
johnpitcairn commentedHmm ... see also #1332698: Allow theming of [commerce-order:commerce-email-order-items].
Occurs to me you could use that and call views_embed_view() within the theme override as an interim solution.
Comment #2
johnpitcairn commentedIf the order id were passed in, which it isn't. Rats.
Comment #3
johnpitcairn commented@elmotri, this is a really good idea. Are you able to put an appropriate default view together? It would need to handle everything that commerce_email_order_items() does.
Comment #4
elmotri commentedThe view should be the same as the "commerce_cart_summary" view. I tested this and it worked. I had to set the permission "View own orders of any type". Here is the code:
I think there should be a separate view for the mail but you can simply copy the commerce_cart_summery view as the default view for email. Maybe some theming is needed.
Comment #5
johnpitcairn commentedThanks for that.
I think we should integrate this with the patch at #1332698: Allow theming of [commerce-order:commerce-email-order-items]. We need to ensure commerce_email_order_items() still returns the old table array if $theme == FALSE, and I think the view should be called from within the new theme function in that patch. If somebody wants to use a different view, or the old table code, or something else entirely, they can override the theme function.
OK to close this issue and continue in #1332698: Allow theming of [commerce-order:commerce-email-order-items] ?
Comment #6
johnpitcairn commentedHmm. Yes, we'd need to add a default view, and theme the view to add the appropriate inline styles, exactly replicating the current themed table output. That's more work than I have time for.
But, assuming the patch at #1332698: Allow theming of [commerce-order:commerce-email-order-items] gets committed, there's now nothing stopping anyone from overriding theme_commerce_email_order_items() to use a view, and also overriding the view theme function or .tpl file to add appropriate inline styles for html email.
Comment #7
summit commentedHi,
Does this https://drupal.org/node/1605586#comment-6240576 work with latest 2.x dev?
@Elmotri could you please explain how to use views as template for the commerce-email order notification (admin/client).
Thanks a lot in advance for your reply!
Greetings, Martijn
Comment #8
johnpitcairn commentedUpdate: the patch from #1332698: Allow theming of [commerce-order:commerce-email-order-items] has been commiteed to latest dev, so you can override that theme function in custom module code or in template.php to alter the default table, replace it with a view, or do whatever you want, without hacking the module.
Note that the problem with using a view, or making this views-based by default, is that Views does not support inline style markup, which is essential for good html email. There would need to be additional manipulation of the view theme output to add inline styles - therefore admins would not be able to just use the Views UI to change things - they'd also need to alter the theme output.
This issue should probably be closed as "won't fix" for that reason.
Comment #9
lmeurs commented@Summit: By writing a custom theme function you can easily generate views tables. By using Emogrifier (Drupal Module) it's possible to convert stylesheet rules to inline style attributes.
Thanks all!
EDIT: Or use
views_embed_view()which is shorter and more secure since it also checks permissions etc.Since the default display also outputs contextual links, we added a custom display to the "Shopping cart summary (Commerce Order)" view.
Comment #10
summit commentedHi @lmeurs,
I altered my commerce_cart_summary view to have shipping costs nicely under subtotal and to have it correctly shown for dutch customers.
These alterations are done by:
Will this alteration in the view also be visible in the email please?
Thanks a lot in advance for your reply!
Greetings, Martijn
Comment #11
lmeurs commented@summit: It will if your module's name is commerce_checkout_order. To be sure I tested the hook with my module's name and it was invoked on the cart and order preview pages, so the alterarions done by the hook will also be output in the e-mails when using a view.
Comment #12
summit commentedHi @lmeurs,
Thanks a lot for helping me so much. Very much appreciated!! I have still two errors using this method, which may have to do with registration of the function?, see: theme not registered: https://drupal.org/node/1406314#comment-5474364
Errors:
What should be the function call to registrate mytheme_commerce_email_order_items if this off course helps with the errors?
Greetings, Martijn
Comment #13
summit commentedHi, #12 was not really related. The Errors where gone with correct setting the htmlmail tpl.php files into the template subfolder of the theme.
https://drupal.org/node/1605586#comment-7875911 #9 working great. Would love to have commerce_email using views!
One add on if possible. Also place Address in the view so that information can also be gathered through this view.
Thanks for considering!
greetings, Martijn
Comment #14
waltercat commented@lmeurs Can you break down a little bit more as to what files need to be created and edited in order to generate a view in the email? I tried adding this code to my htmlmail--variable_email--commerce_email_admin_order.tpl.php file but nothing happened:
Not really sure if this can be directly added to the tpl or if it is supposed to be a module or something. If you could further clarify, that would be great!
Comment #15
summit commentedHi,
this code should be added to your TEMPLATE.PHP from your theme!
Then you can style your email through htmlmail.tpl.php
@lmeurs; Laurens, thanks a lot for bringing this into commerce_email. It is great to use views for this!
Greetings,
Martijn
Comment #16
lmeurs commented@waltercat: Like summit says. Put the
mytheme_commerce_email_order_items()hook inside your template.php file, changemythemeto the name of your theme and clear your caches.Your
htmlmail.tpl.phpfile should contain all the CSS (see attachment, I had to rename it to avoid drupal.org security warnings), also for the views table, and I invoke Emogrifier from there to generate inline styling. I know this should not be done from inside a template file, but I do not know which hook to invoke to alter the output of a template. Make sure the path to your Emogrifier library is correct and you do not need the Emogrifier Drupal module for this, just the Emogrifier library.Then, when calling
views_embed_view()on the default display as an admin, the view will get an 'Edit view' link prefixed. By adding ie. a block display named 'mail' to thecommerce_cart_summaryview and calling this display, the edit link will not be shown:@summit: You are welcome, it was nice meeting you!
Comment #17
summit commentedHi,
This is not working for this token using commerce_message to email an invoice to the customer.
I would very much like to send the commerce_cart_summary mail display in this email, but it keeps taking the original commerce_email table instead of the view.
Using the same token: [message:message-commerce-order:commerce-email-order-items]
It is working great using commerce_message order email, but it is not working using commerce_message custom invoice email.
Somehow the theme override is not triggered I think...
Greetings, Martijn
Comment #18
summit commentedI tried all weekend to get this working, but theme override no go.
With completely changing the function it worked: https://drupal.org/node/1605586#comment-6240576
Now everywhere where I call [message:message-commerce-order:commerce-email-order-items] the correct view is shown! Yoohoo.
I plead for making this module completely depending on views because views is the standard way for drupal and with https://drupal.org/node/1605586#comment-7939397 htmlmail.tpl.php it is much easier to theme the email!
I disagree with the fact the default table should not be views. The user sees a view on the checkout page, and it is only better to show the exact same view in an email as confirmation!
Greetings, Martijn
Comment #19
johnpitcairn commentedIt presumably doesn't work with message_order tokens because that's calling a different token chain. The commerce email token chain is [commerce-order:commerce-email-order-items].
Views should not be used by default because a view cannot apply inline css styling. You would still need to override a theme function or .tpl, or use an additional module to produce best-practice html email (with inline styles). For many users this would be difficult or impossible.
Comment #20
summit commentedHi, I understand, but how to get to this token through another token chain?
Is not working within that chain [message:message-commerce-order:commerce-email-order-items], and for other purposes, I need commerce_message.
The chain [message:message-commerce-order:commerce-email-order-items] comes back to the commerce-email-order-items from this module..
Thanks a lot for your reply in advance!
Greetings, Martijn
Comment #21
johnpitcairn commentedI'd have to take a look at how message_order implements its token, but I can't right now. Have you tried the message_order issue queue?
(PS: I am not the commerce_email maintainer)
Comment #22
summit commentedHi,
I made these issues within Commerce Message issue queue: https://drupal.org/node/2109863 (because my problem is with the invoice email) and https://drupal.org/node/2110431 (because I would very much like the token chain [message:message-commerce-order:commerce-email-order-items] be themable).
Right now the only working solution for me is hacking commerce_email and changing function commerce_email_order_items like in https://drupal.org/node/1605586#comment-6240576
Greetings, Martijn
Comment #23
lanceh1412 commentedThanks. #16 This works for me with 'default' but not 'mail'. I've added a block display called 'mail' but I no longer get the token substitution. Is there something else that needs to be done to get the block to display?
Comment #24
johnatan123 commentedHi can you help me please ? i used this..
then i themed it and it works great.. but only as an administrator.. when i do an order as an anonymous, the view table is not showing up in email..
any ideas how to fix it?
Thanks
Comment #25
pyxio commented@johnatan123 hi, did you ever solve this? i have same exact problem :( please let me know. thanks!
Comment #26
lmeurs commented@johnatan123 & @drupalstrap: Try temporarily giving anonymous users "View any Product product" permission at
admin/people/permissions(ignore the permission's warning for now). If this solves your problem, see #1303194: Clarify security implications of granting "View any Product product" permission, especially my comment at #56 and rszrama's (developer at Commerce Guys) comment at #57.Comment #27
pyxio commented@johnatan (anybody else with the same problem) - i solved simply via user permissions ... under orders section enable anonymous users to view their own orders. seems simple but this not commerce default so you need to tick that box! Cheers
Comment #28
pyxio commented@Imeurs - just saw your post! thanks ... however i think the one is view own order permissions. anyway, playing around with both will get the items to show. thanks so much for the awesome function! cheers kevin
Comment #29
jcherbert commented@lanceh1412, I had the same problem as #23, I found that by going to export view the block definition was:
$handler = $view->new_display('block', 'mail', 'block_2');
then, using:
return views_embed_view('commerce_cart_summary', 'block_2', $order_wrapper->getIdentifier());
in template.php, this worked.
Comment #30
Tommy_001 commentedI know this very late in the chain, but I just wanted to say thank you Imeurs, for the tips regarding how to theme the template and how to get rid of the contextual link. Thanks!
Comment #31
rszrama commented