Showing friendly order number in notification email
Closed this issue · 14 comments
I'm trying to get the friendly order number to display in my order notification email but it's coming up blank.
I have other custom fields being displayed in there so I'm wondering if it's because the field isn't populated before the email notification is sent.
Do you have any insight into this? Have you been able to get the friendly order number to show in your notifications?
The answer to this one is in the readme I think.... The .content
trick.
Oh lord, can't believe I missed that!
Hmm still not working. Just getting "NONE".
Check the db... Have you set the initial number?
The numbers are working OK. I can see them in the CP and they display on regular templates. Even if I make a copy of the email notification template and display it in the browser (with a hardcoded order number). It's just within the email that this particular field isn't showing (other custom order fields are displaying).
I've slightly modded your plugin so it's using a custom order number format but that's literally just using
$orderNumber = 'CNH' . date('Ym') . rand(100,999);
instead of the sequential order numbers so I can't see how that would prevent it showing in the email. (yeah I know, client request but there'll be very very few orders on this site)
Ok late here... Will check my actual template tomorrow and have a think
Hey no worries. I appreciate any help you can give but also that this is a free plugin!
If I can work it out I'll let you know.
Morning Pete
Ok so I presume you have a line like this ... {% set ISOrderNumber = order.content.ISOrderNumber ?? 'NONE' %}
- except with your fieldname? And what you're getting is 'NONE' right? If you changed that word none to blah
you'd get blah
I presume?
If so, all I can think of is there is a mistake in the fieldname you're using at that spot. Because that's the exact line I use in my order receipt and it works fine. Maybe try dumping (or use kint) order.content
to see what is in there at that point?
Hi there,
I've already tried exactly that. If I dump out the order data then 'friendlyOrderNumber' is empty.
Interestingly though, I wasn't using the ternary format and just outputting the variable - yet I wasn't getting an error so it seems that it must be being set to '' and then updated again further along the line.
I'm going to take another look at it this morning and see if I can work out what's going on.
If I dump out the order data then 'friendlyOrderNumber' is empty.
I specifically mean inspecting order.content
not order
I guess. The data is in the content model but not saved to the db.
Hard to know what else could be going wrong - it's in daily use on a number of sites, so it definitely works!
Since you mentioned you have it working I will close this off.
Hi, I meant that I was going to try and change the point at which the friendly number was created and added to the order by using a different event. But haven't been able to get that to work either :(
If I inspect order.content then that also has the friendlyOrderNumber field as NULL.
I don't doubt it's working on a number of sites and it is creating the order number for me, it's just not showing in the notification email.
You'll be very happy to know I've managed to sort it out. Not exactly sure why it wasn't originally working but I'm using Multiadd so have changed your plugin to run on the multiAdd_cart.onBeforeMultiAddToCart event.
It won't be a problem since this is a bit of niche case site in which the customer will only ever be adding a single item (plus a hidden one, hence multiadd) to the order.
Well, it's very odd you need to do it, but I am glad you have it working for your needs!