Post by coldrex » Sat Jan 04, 2025 9:47 am

Hello,

I need to add a model name to email subject line (now I have only store name and order ID).

I opened the file: /catalog/controller/mail/order.php and added [text_model] to a subject line.

Looks like this:

Code: Select all

$data['title'] = sprintf($language->get('text_subject'), $order_info['store_name'], $order_info['order_id'], $order_info['text_model']);
Cleared modificators and all caches.

Nothing changed. What I am doing wrong?

User avatar
New member

Posts

Joined
Thu Jun 07, 2012 10:05 pm

Post by OSWorX » Sat Jan 04, 2025 6:46 pm

coldrex wrote:
Sat Jan 04, 2025 9:47 am
Hello,

I need to add a model name to email subject line (now I have only store name and order ID).

I opened the file: /catalog/controller/mail/order.php and added [text_model] to a subject line.

Looks like this:

Code: Select all

$data['title'] = sprintf($language->get('text_subject'), $order_info['store_name'], $order_info['order_id'], $order_info['text_model']);
Cleared modificators and all caches.

Nothing changed. What I am doing wrong?
You have to use the variable $order_products (and then $order_product for each) to get the product model values.
Look at the line where it says:

Code: Select all

foreach ($order_products as $order_product) { ... }
and add there a new variable (e.g. $models).
Then add each model value to this new variable:

Code: Select all

$models .= $order_product['model] . ', ';
Finally trim it:

Code: Select all

trim(',', $models);
You could add them also as array

Code: Select all

$models[] = $model;
and then finally

Code: Select all

$models = implode(',', $models);
(as I would do it).

And finally add this new variable to your line

Code: Select all

$data['title'] = sprintf($language->get('text_subject'), $order_info['store_name'], $order_info['order_id'], $models);
Note: you have to adopt then also the language variable 'text_subject' otherwise an error will be produced!
Better to use that:

Code: Select all

$data['title'] = sprintf($language->get('text_subject'), $order_info['store_name'], $order_info['order_id']) . ' ' . $models;

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Administrator

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by khnaz35 » Sat Jan 04, 2025 7:16 pm

So if he has in cart more then 1 items it will look messy with subject line , because every product will have model/skus

Got an urgent question that’s keeping you up at night? There might just be a magical inbox ready to help: khnaz35@gmail.com
Enjoy nature ;) :) :-*


User avatar
Active Member

Posts

Joined
Mon Aug 27, 2018 11:30 pm
Location - Malaysia

Post by nonnedelectari » Sat Jan 04, 2025 8:22 pm

khnaz35 wrote:
Sat Jan 04, 2025 7:16 pm
So if he has in cart more then 1 items it will look messy with subject line , because every product will have model/skus
And every client truncates the subject line after a number of characters.

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by OSWorX » Sat Jan 04, 2025 8:49 pm

@khnaz35 & @nonnedelectari: both of you are true.
But that was not the question O0

To avoid longer subject lines he should check the length before adding.
Or adding the model(s) to the message text where enough space is ..

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Administrator

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by coldrex » Sat Jan 04, 2025 10:48 pm

OSWorX wrote:
Sat Jan 04, 2025 6:46 pm
coldrex wrote:
Sat Jan 04, 2025 9:47 am
Hello,

I need to add a model name to email subject line (now I have only store name and order ID).

I opened the file: /catalog/controller/mail/order.php and added [text_model] to a subject line.

Looks like this:

Code: Select all

$data['title'] = sprintf($language->get('text_subject'), $order_info['store_name'], $order_info['order_id'], $order_info['text_model']);
Cleared modificators and all caches.

Nothing changed. What I am doing wrong?
You have to use the variable $order_products (and then $order_product for each) to get the product model values.
Look at the line where it says:

Code: Select all

foreach ($order_products as $order_product) { ... }
and add there a new variable (e.g. $models).
Then add each model value to this new variable:

Code: Select all

$models .= $order_product['model] . ', ';
Finally trim it:

Code: Select all

trim(',', $models);
You could add them also as array

Code: Select all

$models[] = $model;
and then finally

Code: Select all

$models = implode(',', $models);
(as I would do it).

And finally add this new variable to your line

Code: Select all

$data['title'] = sprintf($language->get('text_subject'), $order_info['store_name'], $order_info['order_id'], $models);
Note: you have to adopt then also the language variable 'text_subject' otherwise an error will be produced!
Better to use that:

Code: Select all

$data['title'] = sprintf($language->get('text_subject'), $order_info['store_name'], $order_info['order_id']) . ' ' . $models;

Thanks.
So I found this string in multiple lines:

Code: Select all

foreach ($order_products as $order_product) { ... }
First was on line 50.
After the block of code, on line 58 I added suggested code:

Code: Select all

$models .= $order_product['model] . ', ';
		trim(',', $models);
		$models[] = $model;
		$models = implode(',', $models);
And then changed the line:

Code: Select all

$data['title'] = sprintf($language->get('text_subject'), $order_info['store_name'], $order_info['order_id']) . ' ' . $models;
Tried to make a checkout in the cart and got an error.

What is wrong here? ..

User avatar
New member

Posts

Joined
Thu Jun 07, 2012 10:05 pm

Post by OSWorX » Sat Jan 04, 2025 11:03 pm

coldrex wrote:
Sat Jan 04, 2025 10:48 pm
What is wrong here? ..
Sorry, but nearly everything ..

1. open ../catalog/controller/mail/order.php with a qualified editor (e.g. Visual Studio Code).
2. then look for public function add(
3. search for foreach ($order_products as $order_product) {
4. before you add: $models = [];
5. inside the foreach (see #3) before $data['products'][] = array( add this: $models[] = $order_product['model'];
6. look for $mail->setSubject(html_entity_decode(sprintf($language->get('text_subject'), $order_info['store_name'], $order_info['order_id']), ENT_QUOTES, 'UTF-8')); and change to: $mail->setSubject(html_entity_decode(sprintf($language->get('text_subject'), $order_info['store_name'], $order_info['order_id']), ENT_QUOTES, 'UTF-8')) . implode(', ', $models);

That's it.

But beware - as already written prior, if you have a long subject line (usually more than 76 characters) it will be truncated!
Maybe better to add the models to the message.

p.s.: next time it would save all of us time, if you hire a professional.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Administrator

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria
Who is online

Users browsing this forum: Semrush [Bot] and 14 guests