Add custom field to email title

  • Posts: 75
  • Thank you received: 7
9 years 1 month ago #216815

-- HikaShop version -- : 2.5.0
-- Joomla version -- : 3.44
-- PHP version -- : 5.4.41
-- Browser(s) name and version -- : Chrome 45.0.2454.101 (64-bit)

Hi, I would to add the "Company" custom field (address_company) to the title of the admin notification email when an order is placed.

Previously, I was trying to add a Community Builder field but that is too complex at this point.

For the address_company field, I attempted to add the variable to the "order.php" file like so:

$order->mail->subject = JText::sprintf('NEW_ORDER_SUBJECT',$address_company,$order->order_number,HIKASHOP_LIVE);

but this actually does nothing. I tried adding more variable calls "%s" to my NEW_ORDER_SUBJECT language override, but I think my basic syntax/understanding of how to do this may be off.

I've been searching on this for a while now, but it seems most people want to add these variable within the body of the email, not the subject. Thanks for any help.

Please Log in or Create an account to join the conversation.

  • Posts: 82867
  • Thank you received: 13374
  • MODERATOR
9 years 1 month ago #216835

Hi,

That's the correct way of doing it for the subject.
If that doesn't work, the problem is how you initialize that $address_company variable.
How do you load it ? Are you sure that it is filled with something ?
Normally, it should be available in $order->cart->billing_address->address_company

Please Log in or Create an account to join the conversation.

  • Posts: 75
  • Thank you received: 7
9 years 1 month ago #216858

Hi Nicolas,

I did load it in the line above, although with the wrong path. I have now included the correct path so that it reads like so:

$order->mail->subject = trim($order->mail->subject);
      if(empty($order->mail->subject)) {
            $address_company = $order->cart->billing_address->address_company;
            $order->mail->subject = JText::sprintf('NEW_ORDER_SUBJECT',$address_company,$order->order_number,HIKASHOP_LIVE);

but it still will not appear. The field is definitely filled in inside the User account, as well. I've tried adding extra variable placeholders to the language string with no results, except when you add too many it sends an email with "(No subject)".

Hopefully you can see what's going wrong here...

Please Log in or Create an account to join the conversation.

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
9 years 1 month ago #216992

Hi,

And what appear in your email subject ?
The access for the custom field data is right ; but you have to be sure that the "$order->cart" is right there.
That variable is loaded in the email "preload" ; that's mostly why you should create an email override and not modify the HikaShop core files directly ; except if you want to have issues with future updates and loose your modifications.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 75
  • Thank you received: 7
9 years 1 month ago #217167

Hi Jerome,

thanks for the response. since I have the following in my order file:

$order->mail->subject = JText::sprintf('NEW_ORDER_SUBJECT',$address_company,$order->order_number,HIKASHOP_LIVE);

My email subject line reads like so:

New order No. ZZ-00931 created on Mywebsite.com

I looked in the preload for my "Order administrator notification" and I don't see the "New Order Subject" line in there at all for me to modify for an override. Am I supposed to add it myself?

Can someone just walk me through what exactly I should do to get this to happen? I'm kind of playing whack-a-mole here and obviously I'm missing something substantial in my understanding. thank you.

Please Log in or Create an account to join the conversation.

  • Posts: 82867
  • Thank you received: 13374
  • MODERATOR
9 years 1 month ago #217994

hi,

Ok, in the administrator/components/com_hikashop/classes/order.php file, instead of:

							$order->mail->subject = trim($order->mail->subject);
							if(empty($order->mail->subject)) {
								$order->mail->subject = JText::sprintf('NEW_ORDER_SUBJECT',$order->order_number,HIKASHOP_LIVE);
							}
try to put just:
$address_company = $order->cart->billing_address->address_company;
            $order->mail->subject = JText::sprintf('NEW_ORDER_SUBJECT',$address_company,$order->order_number,HIKASHOP_LIVE);
That should hopefully do it.

Please Log in or Create an account to join the conversation.

  • Posts: 75
  • Thank you received: 7
9 years 1 month ago #218100

Hi Nicolas,

thanks for responding. I did try this and unfortunately it also didn't work.

So just to be clear on what I did - this is what I have now in Order.php

$order->mail->subject = trim($order->mail->subject);
	if(empty($order->mail->subject)) {
		$address_company = $order->cart->billing_address->address_company; 
		$order->mail->subject = JText::sprintf('NEW_ORDER_SUBJECT',$address_company,$order->order_number,HIKASHOP_LIVE);
	}

Is it possible the problem is somewhere else? I've attached screenshots of what I have in my "address_company" custom field, then that field filled in the User Address Information screen, and then my "NEW_ORDER_SUBJECT" language override. Hopefully this sheds some light on the issue. Thanks!






Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 82867
  • Thank you received: 13374
  • MODERATOR
9 years 1 month ago #218144

Hi,

That's not what I said to do in my last message. I said the replace the whole block with the 2 lines. Try like that.

Please Log in or Create an account to join the conversation.

  • Posts: 75
  • Thank you received: 7
9 years 4 weeks ago #218647

I did it that way and it worked. Thank you.

Please Log in or Create an account to join the conversation.

  • Posts: 195
  • Thank you received: 5
  • Hikashop Business
8 years 7 months ago #234640

Is there any way to make this change via an override - or other means so that each time HS is upgraded we don't have to manually re-apply this change?

Please Log in or Create an account to join the conversation.

  • Posts: 82867
  • Thank you received: 13374
  • MODERATOR
8 years 7 months ago #234687

Hi,

Normally, it should be possible to override the $mail->subject in the email override without having to edit directly order.php
And in that case, it shouldn't be a problem for updates.

Please Log in or Create an account to join the conversation.

  • Posts: 195
  • Thank you received: 5
  • Hikashop Business
8 years 7 months ago #235051

Sorry, I'm not finding exactly where to do that override.

I've tried using the Hkashop view and the only "email" view that I'm finding are on the "back end":

  • form
  • form_param
  • listing

But none of them have any code anything similar to this.

Am I just looking in the wrong place?

Please Log in or Create an account to join the conversation.

  • Posts: 82867
  • Thank you received: 13374
  • MODERATOR
8 years 7 months ago #235113

Hi,

You need to do that in the code of the email itself when you edit it via the menu System>Emails of your backend.
There, you won't find any code about $mail, you need to add it like that for example:
<?php $mail->subject = "my new subject"; ?>

Please Log in or Create an account to join the conversation.

  • Posts: 75
  • Thank you received: 7
8 years 7 months ago #236426

Hi Nicolas,

to pick up from what cpaschen is saying, I'd also like to try to move this into the email override instead of the order.php file.

so to do this, I would open up my 'Order administrator notification' email to add code, and would I add this to the "Preload" section?

$address_company = $order->cart->billing_address->address_company;
            $order->mail->subject = JText::sprintf('NEW_ORDER_SUBJECT',$address_company,$order->order_number,' - ',HIKASHOP_LIVE);

I looked through the code in that section, but couldn't tell if there's one place that's better than another to add the code. Is there a specific line that it should be placed?

Please Log in or Create an account to join the conversation.

  • Posts: 82867
  • Thank you received: 13374
  • MODERATOR
8 years 7 months ago #236498

Hi,

That code like that won't work.
You need to change $order to $data everywhere in that code.
And you can add it in the preload of the email, anywhere you want after $data->cart is loaded.
At the end of the preload for example.

Please Log in or Create an account to join the conversation.

  • Posts: 75
  • Thank you received: 7
8 years 7 months ago #236560

Thanks Nicolas,

I tried doing this. First, I reverted my "order.php" file to the default code that installs with HikaShop Business 2.6.2.

Then, in the Preload section of my "Order administrator notification" I placed this code at the very bottom:

$address_company = $data->cart->billing_address->address_company;
$shipto_method = $data->cart->billing_address->shipto_method;
$data->mail->subject = JText::sprintf('NEW_ORDER_SUBJECT',$address_company,$data->order_number,' - ',$shipto_method,HIKASHOP_LIVE);

But when I placed an order, I get the email but the subject line is completely blank. Can you tell me where I went wrong?

Please Log in or Create an account to join the conversation.

Time to create page: 0.106 seconds
Powered by Kunena Forum