show variants name in orders
- nico.van.leeuwen
-
Topic Author
- Offline
Less
More
4 months 1 week ago #371884
by nico.van.leeuwen
show variants name in orders was created by nico.van.leeuwen
-- HikaShop version -- : 6.4.1
-- Joomla version -- : 6.1.0
-- PHP version -- : 8.4
Hi, just wondering if it would be possible to list the chosen variants with a product in the order details / invoice?
So for example:
By a men's shoe and show in the order details that you chose the variant blue, longs laces, extra polish etc.
Now it is showing the product code that is automatically generates when adding variants. This is not very readable
-- Joomla version -- : 6.1.0
-- PHP version -- : 8.4
Hi, just wondering if it would be possible to list the chosen variants with a product in the order details / invoice?
So for example:
By a men's shoe and show in the order details that you chose the variant blue, longs laces, extra polish etc.
Now it is showing the product code that is automatically generates when adding variants. This is not very readable
Please Log in or Create an account to join the conversation.
4 months 1 week ago #371887
by nicolas
Replied by nicolas on topic show variants name in orders
Hi,
This is already the case. The selected choice should appear in the invoice, order details, etc.
If you don't see it, it's likely because you have custom CSS code which hides it. You probably added your CSS to hide it on the product page but your CSS is not narrow enough to target only the product page and thus it affects other pages where you want it displayed.
Now, that's just a theory, because you didn't provide the URL of a product page, so I can't confirm the situation on the website. But based on what you said and what I know, it's the most probable.
This is already the case. The selected choice should appear in the invoice, order details, etc.
If you don't see it, it's likely because you have custom CSS code which hides it. You probably added your CSS to hide it on the product page but your CSS is not narrow enough to target only the product page and thus it affects other pages where you want it displayed.
Now, that's just a theory, because you didn't provide the URL of a product page, so I can't confirm the situation on the website. But based on what you said and what I know, it's the most probable.
Please Log in or Create an account to join the conversation.
- nico.van.leeuwen
-
Topic Author
- Offline
4 months 1 week ago - 4 months 1 week ago #371893
by nico.van.leeuwen
Replied by nico.van.leeuwen on topic show variants name in orders
Hi,
My bad, I've been mixing variant names and characteristics.
Yes you see the variant product_code but this is made from the ID's of the characteristics ID's and by default not very readable
Any chance to have the products shown in the cart/invoice with the values of the chosen characteristics ?
EDIT: I see some overrides that might be the issue. This was a "inherited" shop so I will do some cleanup first to see if that is the issue.
My bad, I've been mixing variant names and characteristics.
Yes you see the variant product_code but this is made from the ID's of the characteristics ID's and by default not very readable
Any chance to have the products shown in the cart/invoice with the values of the chosen characteristics ?
EDIT: I see some overrides that might be the issue. This was a "inherited" shop so I will do some cleanup first to see if that is the issue.
Last edit: 4 months 1 week ago by nico.van.leeuwen. Reason: update
Please Log in or Create an account to join the conversation.
- nico.van.leeuwen
-
Topic Author
- Offline
2 months 2 weeks ago #372504
by nico.van.leeuwen
Replied by nico.van.leeuwen on topic show variants name in orders
Hi,
I've checked a pretty empty test site and configured characteristics.
But unfortunately I cannot seem to get the name/value of this in the order e-mail.
The only thing that I see in the e-mails is the product code and the variant name.
Would it be possible to have something like this in the order e-mail:
Product name
characteristic1 name - value
characteristic2 name - value
This so someone who ordered a product with multiple variants can easily see what they ordered?
Now the order e-mail is a bit of a mystery when you have a lot of variants.
I've checked a pretty empty test site and configured characteristics.
But unfortunately I cannot seem to get the name/value of this in the order e-mail.
The only thing that I see in the e-mails is the product code and the variant name.
Would it be possible to have something like this in the order e-mail:
Product name
characteristic1 name - value
characteristic2 name - value
This so someone who ordered a product with multiple variants can easily see what they ordered?
Now the order e-mail is a bit of a mystery when you have a lot of variants.
Please Log in or Create an account to join the conversation.
2 months 2 weeks ago #372509
by nicolas
Replied by nicolas on topic show variants name in orders
Hi,
The product name + value 1 + value 2 will be displayed automatically.
However, if you provide a variant name, then it will override this display to only display the variant name. I think that's where your issue comes from, no ?
The product name + value 1 + value 2 will be displayed automatically.
However, if you provide a variant name, then it will override this display to only display the variant name. I think that's where your issue comes from, no ?
Please Log in or Create an account to join the conversation.
- nico.van.leeuwen
-
Topic Author
- Offline
2 months 2 weeks ago #372517
by nico.van.leeuwen
Replied by nico.van.leeuwen on topic show variants name in orders
Hi, yes, after looking very closely this is what is happening.
So now the question is how can I change the display of the product name that is now a link to look more like this:
Product name
characteristic1 name - value
characteristic2 name - value
I looked into the e-mail template but not very sure what to change.
That would make an order much better readable when having a lot of variants.
So now the question is how can I change the display of the product name that is now a link to look more like this:
Product name
characteristic1 name - value
characteristic2 name - value
I looked into the e-mail template but not very sure what to change.
That would make an order much better readable when having a lot of variants.
Please Log in or Create an account to join the conversation.
2 months 2 weeks ago #372520
by nicolas
Replied by nicolas on topic show variants name in orders
Hi,
Good news: the characteristics chosen at purchase are already stored on each order line (in the order_product_options field of the order product), so we can rebuild a readable block at display time from that stored data. Because it reads what was stored, it also works for orders already placed.
1) Add this small helper to the preload of the email. It reads the characteristics stored on an order line and returns one line per characteristic as "axis name - value":
2) Then, still in the preload, change:
to:
Paste the helper from step 1 at the top of the file, right after the opening php tag.
Good news: the characteristics chosen at purchase are already stored on each order line (in the order_product_options field of the order product), so we can rebuild a readable block at display time from that stored data. Because it reads what was stored, it also works for orders already placed.
1) Add this small helper to the preload of the email. It reads the characteristics stored on an order line and returns one line per characteristic as "axis name - value":
Code:
if(!function_exists('hikashopOrderVariantLines')) {
function hikashopOrderVariantLines($orderProduct) {
$chars = @$orderProduct->order_product_options;
if(is_string($chars))
$chars = hikashop_unserialize($chars);
if(empty($chars) || !is_array($chars))
return '';
// the stored rows hold the value and its axis id, but not the axis name,
// so resolve the axis (parent characteristic) names in one query
$axisIds = array();
foreach($chars as $c) {
if(is_object($c) && !empty($c->characteristic_value) && !empty($c->characteristic_parent_id))
$axisIds[(int)$c->characteristic_parent_id] = (int)$c->characteristic_parent_id;
}
if(empty($axisIds))
return '';
$db = JFactory::getDBO();
$db->setQuery('SELECT characteristic_id, characteristic_value FROM '.hikashop_table('characteristic').
' WHERE characteristic_id IN ('.implode(',', $axisIds).')');
$axes = $db->loadObjectList('characteristic_id');
$lines = array();
foreach($chars as $c) {
if(!is_object($c) || empty($c->characteristic_value) || empty($c->characteristic_parent_id))
continue;
$axisId = (int)$c->characteristic_parent_id;
$axis = isset($axes[$axisId]) ? hikashop_translate($axes[$axisId]->characteristic_value) : '';
$value = hikashop_translate($c->characteristic_value);
$lines[] = ($axis !== '' ? $axis.' - ' : '').$value;
}
if(empty($lines))
return '';
return '<br/>'.implode('<br/>', $lines);
}
}
2) Then, still in the preload, change:
Code:
$t = '<p>' . $item->order_product_name;
Code:
$t = '<p>' . $item->order_product_name . hikashopOrderVariantLines($item);
Please Log in or Create an account to join the conversation.
- nico.van.leeuwen
-
Topic Author
- Offline
2 months 2 weeks ago #372526
by nico.van.leeuwen
Replied by nico.van.leeuwen on topic show variants name in orders
Hi, we love good news 
It works in the admin e-mail.
Looking much better readable.
Tried this also for the customer e-mail but this is not working.
Maybe I need to make changes a bit different in there?
It works in the admin e-mail.
Looking much better readable.
Tried this also for the customer e-mail but this is not working.
Maybe I need to make changes a bit different in there?
Please Log in or Create an account to join the conversation.
2 months 2 weeks ago #372529
by nicolas
Replied by nicolas on topic show variants name in orders
Hi,
Nothing different is needed. The customer email and the admin email are two separate templates, each with its own preload, so the change is not shared between them. You have to repeat the exact same two edits in the customer order email's own preload (the order confirmation sent to the buyer, not the admin copy you already edited).
So in that email:
1. Paste the same helper right after the opening PHP tag of its preload. Keep the if(!function_exists(...)) guard, it matters here: on order creation the customer email and the admin email are generated in the same request, and without the guard the second one would hit a "Cannot redeclare function" fatal and the mail would fail silently.
2. Find the same line and append the call:
If you did that and it still does not show, you most likely edited a different email than the one the buyer actually receives. The order_product_options data is identical in both, so once the two edits are in the right template it renders exactly like the admin one. Make sure it is the customer order confirmation email, and place a fresh test order, an old email already in the inbox will not update.
Nothing different is needed. The customer email and the admin email are two separate templates, each with its own preload, so the change is not shared between them. You have to repeat the exact same two edits in the customer order email's own preload (the order confirmation sent to the buyer, not the admin copy you already edited).
So in that email:
1. Paste the same helper right after the opening PHP tag of its preload. Keep the if(!function_exists(...)) guard, it matters here: on order creation the customer email and the admin email are generated in the same request, and without the guard the second one would hit a "Cannot redeclare function" fatal and the mail would fail silently.
2. Find the same line and append the call:
Code:
$t = '<p>' . $item->order_product_name . hikashopOrderVariantLines($item);
If you did that and it still does not show, you most likely edited a different email than the one the buyer actually receives. The order_product_options data is identical in both, so once the two edits are in the right template it renders exactly like the admin one. Make sure it is the customer order confirmation email, and place a fresh test order, an old email already in the inbox will not update.
Please Log in or Create an account to join the conversation.
- nico.van.leeuwen
-
Topic Author
- Offline
2 months 2 weeks ago #372536
by nico.van.leeuwen
Replied by nico.van.leeuwen on topic show variants name in orders
Hi,
I know about the different e-mails and made the changes twice to be certain but the result stays different for the admin/customer mails..
The customer e-mail is not showing the same result as the admin e-mail.
The devil must be in the details again
I know about the different e-mails and made the changes twice to be certain but the result stays different for the admin/customer mails..
The customer e-mail is not showing the same result as the admin e-mail.
The devil must be in the details again
Please Log in or Create an account to join the conversation.
2 months 2 weeks ago #372538
by nicolas
Replied by nicolas on topic show variants name in orders
Hi,
Glad it works in the admin email. The reason the same edit does nothing in the customer email is that the customer emails (order creation notification and order status notification) are built a bit differently from the admin one.
In the admin email the product name is a single plain line, which is exactly the line you edited. But in the customer emails the name is wrapped in a link to the product page when the product still exists, so there are two versions of that line:
Your products have a page, so the first line (the link one) is the one that actually runs. The line you edited is the fallback that only runs when the product has no link, which is why nothing showed.
Rather than editing inside that if/else, add the helper call on its own line right after the block closes, so it applies whichever branch runs:
And, as with the admin email, remember to also paste the helper function itself at the top of each customer email's preload (the if(!function_exists(...)) guard makes that safe).
Do this in the order creation notification and/or the order status notification, whichever ones your customers actually receive, and the characteristics block will show there too.
Glad it works in the admin email. The reason the same edit does nothing in the customer email is that the customer emails (order creation notification and order status notification) are built a bit differently from the admin one.
In the admin email the product name is a single plain line, which is exactly the line you edited. But in the customer emails the name is wrapped in a link to the product page when the product still exists, so there are two versions of that line:
Code:
if(!empty($item->product_id)) {
...
$t = '<p><a href="'.$product_url.'">' . $item->order_product_name . '</a>';
} else {
$t = '<p>' . $item->order_product_name;
}
Your products have a page, so the first line (the link one) is the one that actually runs. The line you edited is the fallback that only runs when the product has no link, which is why nothing showed.
Rather than editing inside that if/else, add the helper call on its own line right after the block closes, so it applies whichever branch runs:
Code:
} else {
$t = '<p>' . $item->order_product_name;
}
$t .= hikashopOrderVariantLines($item);
if($group){
And, as with the admin email, remember to also paste the helper function itself at the top of each customer email's preload (the if(!function_exists(...)) guard makes that safe).
Do this in the order creation notification and/or the order status notification, whichever ones your customers actually receive, and the characteristics block will show there too.
The following user(s) said Thank You: nico.van.leeuwen
Please Log in or Create an account to join the conversation.
- nico.van.leeuwen
-
Topic Author
- Offline
2 months 2 weeks ago #372541
by nico.van.leeuwen
Replied by nico.van.leeuwen on topic show variants name in orders
Hi,
This was the cause, yes.
Mails are now making a lot more sense when using all those variants
Many thanks again !
This was the cause, yes.
Mails are now making a lot more sense when using all those variants
Many thanks again !
The following user(s) said Thank You: nicolas
Please Log in or Create an account to join the conversation.
Time to create page: 0.386 seconds