Add due date of Advanced date picker module to admin email title

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

-- HikaShop version -- : 2.6.3
-- Joomla version -- : 3.6.5
-- PHP version -- : 5.6.3
-- Browser(s) name and version -- : Chrome 56.0.2924.87

Hello,

I need to put the due date of each order into the subject lines of our admin notification email subject lines.

I can do this sort of, but I have two problems:

1. even though I add the variable for my custom field 'yourdesiredduedate' (it's an Advanced date picker module), for some reason the date format comes out different in the subject line than it does in the email itself.

For example, in the email body it will read "03/31/2017", but in the subject line it reads '20170331000000'.

Is there somewhere I can change that format?


2. For some reason my subject line leaves out one variable. Even though I have the placeholder '%s' in my 'NEW_ORDER_SUBJECT' language override.

So the entire subject line will read:

New Customer order No. WW-00855 created on site.com - 20170331000000

My NEW_ORDER_SUBJECT code is:

New %s order No. %s created on site.com%s%s%s

and the code I have in Order.php is:

$order->customer->user_email = explode(',',$emails);
	$order->customer->name= ' ';
	$this->loadOrderNotification($order,'order_admin_notification');
	$address_company = $order->cart->billing_address->address_company;
	$shipto_method = $order->cart->billing_address->shipto_method;
	$yourdesiredduedate = $order->cart->yourdesiredduedate;
$order->mail->subject = JText::sprintf('NEW_ORDER_SUBJECT',$address_company,$order->order_number,' - ',$shipto_method,$yourdesiredduedate,HIKASHOP_LIVE);

You can see I have 5 placeholders in my override, and 4 variables in my order subject line in the code. I suppose HIKASHOP_LIVE is a variable, but that one doesn't print in the subject line (which is fine, we don't want it to).

Please let me know of any help you can offer. Thanks!

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

  • Posts: 82865
  • Thank you received: 13372
  • MODERATOR
7 years 8 months ago #265688

Hi,

1. That's the data of the custom field. It's stored like that in the database. If you want to convert it, you need to call the show function of class.field
Here is an example with a custom item field:
www.hikashop.com/forum/product-category-...e-picker.html#202906

2. You indeed have 5 placeholders in your override, but I count 6 variables in your code:
$address_company
$order->order_number
' - '
$shipto_method
$yourdesiredduedate
HIKASHOP_LIVE

So it's normal that the last one, HIKASHOP_LIVE is missing.

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

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

Hi Nicolas,

Thanks for your response.

Ok, I'll have to investigate the formatting of the custom field further.

For now, I still have trouble even displaying the value of the field in the subject line. The number of variables showing is still coming out wrong, despite me adding the new placeholder to my override.

So now I have this same code in the 'Order.php' file:

$order->customer->user_email = explode(',',$emails);
	$order->customer->name= ' ';
	$this->loadOrderNotification($order,'order_admin_notification');
	$address_company = $order->cart->billing_address->address_company;
	$shipto_method = $order->cart->billing_address->shipto_method;
	$yourdesiredduedate = $order->cart->yourdesiredduedate;
$order->mail->subject = JText::sprintf('NEW_ORDER_SUBJECT',$address_company,$order->order_number,' - ',$shipto_method,$yourdesiredduedate,HIKASHOP_LIVE);

and my override now looks like this:
New %s order No. %s created on Playerkits.com%s%s%s%s

so we can see that there are now 6 placeholders. However my subject line of my email comes out looking like this:
New Customer order No. WW-00855 created on Playerkits.com - 20170331000000http://www.site.com/

So for some reason it's only showing 5 of the available variables:
$address_company
$order->order_number
' - '
$shipto_method
$yourdesiredduedate
HIKASHOP_LIVE

It's completely skipping my "shipto_method" for some reason. Do you have any idea what's going wrong here?

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

  • Posts: 82865
  • Thank you received: 13372
  • MODERATOR
7 years 7 months ago #265987

Hi,

It's impossible that it's skipping it. Which means that your problem is that the variable $shipto_method is empty.
So probably there is no value in the billing address for the custom address field with the column name "shipto_method".

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

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

Yes, you are absolutely correct. My shipto_method field was indeed empty. So everything that should be showing is indeed showing in the subject of my email now.

However, this brings me back to the format of my date. I modified the code from the linked thread you provided, but it doesn't do anything at all.

I place this code into the preload section of my Admin email:

$fieldsClass = hikashop_get('class.field');
$element=null;
$fields = $fieldsClass->getFields('',$element,'order');
echo $fieldsClass->show($fields['yourdesiredduedate'], $this->row->yourdesiredduedate);

I placed it at the end after the "ob_start" section, before the 'JPluginHelper' line.

Where should I be placing this code? And should I change the code at all? Thanks!

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

  • Posts: 82865
  • Thank you received: 13372
  • MODERATOR
7 years 7 months ago #266098

Hi,

That code is correct.
However, you need to understand that the show function require its first parameter to be a field data.
If

$fields['yourdesiredduedate']
is empty, which I assume it is, then the show function won't work properly as it doesn't have the data of the custom field and thus it doesn't know how you configured the custom field.
And thus, you need to also understand how the getFields function works. It returns an array of the fields data available for the element given in its second parameter. Since you give it an empty parameter, it will give you back all the fields that apply to any order regardless of what you have in the order. So if your custom field is limited to only some products or some categories, then the data of that custom field won't be in the array returned by the getFields function.
Now you didn't provide a screenshot of the settings of your custom field, so I don't know if that's the case but I bet it is something along those lines.
An easy alternative would be to run your own MySQL query to load the field data yourself from the hikashop_field table.

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

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

Hi Nicolas,

alright, so maybe I have inadvertently restricted the field from being loaded correctly? That same field shows correctly within the body of the email, so I assume it must be loaded correctly at some point.

I have included the screenshot of that field, so hopefully you can spot what I'm doing wrong here.

Attachments:

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

  • Posts: 82865
  • Thank you received: 13372
  • MODERATOR
7 years 7 months ago #266197

Hi,

That's what I thought :)
As I can see on your screenshot, the field is limited to the category "product category".
Remove that restriction and your code should work.
Otherwise, you can also change :
$fields = $fieldsClass->getFields('',$element,'order');
to:
$fields = $fieldsClass->getFields('',$order,'order'); / Or $order->cart ?
so that the fields loaded take into account the data of the order and include the fields with restrictions on the categories of the products of the order.

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

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

Hi Nicolas,

for some reason it's still not working as I had hoped.

I'm still getting that default date formatting.

I've attached a screenshot of my custom field, where I have removed the restriction from the category.

And here is the code I tried. Both this:

$fieldsClass = hikashop_get('class.field');
$element=null;
$fields = $fieldsClass->getFields('',$order->cart,'order');
echo $fieldsClass->show($fields['yourdesiredduedate'], $this->row->yourdesiredduedate);

and this:
$fieldsClass = hikashop_get('class.field');
$element=null;
$fields = $fieldsClass->getFields('',$order,'order');
echo $fieldsClass->show($fields['yourdesiredduedate'], $this->row->yourdesiredduedate);

but my subject lines still come out like this:
New Customer order No. WW-00865 created on Playerkits.com - 20170428000000

I'm hoping here that I just mis-applied the code...?

Attachments:

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

  • Posts: 82865
  • Thank you received: 13372
  • MODERATOR
7 years 7 months ago #266754

Hi,

Well, I don't know the context of your code.
Why do you have the custom field value in $this->row if you have $order ? Do you actually have the $order variable ?
And why do you echo the return of the show function ? Wasn't the goal to add it in the subject of the email ?

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

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

Hi Nicolas,

I don't know the answer to any of your questions except for the last one - and the answer to that one is yes, I need a readable date in the subject of the email.

As for the rest, I don't know PHP well, so I don't know why most of that code is there, which is why I need help with this. I copied a lot of it from the thread you linked to earlier, and tried to adjust it the best i could.

At this point, the only thing that needs to be done is to format the date correctly. I do get the date itself in the subject, but it's in an unfriendly format that is not easily scanned. If you (or someone) could just tell me how to change that date format I'd be all set.

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

  • Posts: 82865
  • Thank you received: 13372
  • MODERATOR
7 years 7 months ago #266845

Hi,

Please provide the whole code that you have in the function where you have your code. Because without context, I can't provide precise code, I can only provide examples where you need to adapt the variables to the context where you are.

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

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

Hi Nicolas,

Ok, I think where you're asking for the "function", that's not something I quite understand. But, here's the bottom part of the code from the Preload section of my Admin Notification Override.

The only part of this I have changed is where I added the 4 line block of code staring with "$fieldsClass" after the first chunk of code.

Should this code be placed somewhere else?

ob_start();

	$sep = '';
	if(hikashop_level(2)) {
		$fields = $fieldsClass->getFields('frontcomp',$data,'order','');
		foreach($fields as $fieldName => $oneExtraField) {
			if(empty($data->cart->$fieldName))
				continue;
			echo '<span class="top_pkinfo_headers">' .$sep . $fieldsClass->trans($oneExtraField->field_realname).' : <span>'.$fieldsClass->show($oneExtraField, $data->cart->$fieldName,'admin_email').'</span></span>';
			$sep = ' ';
		}
	}

// This is the part added by wildweststudios

$fieldsClass = hikashop_get('class.field');
$element=null;
$fields = $fieldsClass->getFields('',$order->cart,'order');
echo $fieldsClass->show($fields['yourdesiredduedate'], $this->row->yourdesiredduedate);

// End part added by wildweststudios


	JPluginHelper::importPlugin('hikashop');
	$dispatcher = JDispatcher::getInstance();
	$dispatcher->trigger('onAfterOrderProductsListingDisplay', array(&$data->cart, 'email_notification_html'));

$content = ob_get_clean();
$vars['ORDER_SUMMARY'] = $content;

$vars['BILLING_ADDRESS'] = '';
$vars['SHIPPING_ADDRESS'] = '';

$params = null;
$js = '';
$fieldsClass = hikashop_get('class.field');
$template = trim(hikashop_getLayout($view,'address_template',$params,$js));
if(!empty($data->cart->billing_address) && !empty($data->cart->fields)){
	$billing = ''.$template;
	foreach($data->cart->fields as $field){
		$fieldname = $field->field_namekey;
		if(!empty($data->cart->billing_address->$fieldname)) $billing=str_replace('{'.$fieldname.'}',$fieldsClass->show($field,$data->cart->billing_address->$fieldname),$billing);
	}
	$vars['BILLING_ADDRESS'] = str_replace(array("\r\n","\r","\n"),'<br/>',preg_replace('#{(?:(?!}).)*}#i','',$billing));
}
if(!empty($data->cart->override_shipping_address)) {
	$vars['SHIPPING_ADDRESS'] =  $data->cart->override_shipping_address;
} elseif(!empty($data->order_shipping_id) && !empty($data->cart->shipping_address)) {
	$shipping = ''.$template;
	foreach($data->cart->fields as $field) {
		$fieldname = $field->field_namekey;
		if(!empty($data->cart->shipping_address->$fieldname)) $shipping=str_replace('{'.$fieldname.'}',$fieldsClass->show($field,$data->cart->shipping_address->$fieldname),$shipping);
	}
	$vars['SHIPPING_ADDRESS'] = str_replace(array("\r\n","\r","\n"),'<br/>',preg_replace('#{(?:(?!}).)*}#i','',$shipping));
} else {
	$vars['SHIPPING_ADDRESS'] = $vars['BILLING_ADDRESS'];
}

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
7 years 7 months ago #266959

Hello,

I'm afraid that in the email context, the variables "$order->cart" and "$this->row" does not exist.
So, your code cannot work properly because you're not giving the right data to the functions.

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
7 years 7 months ago #267106

Hi Jerome, thanks for the response.

Ok, I see then that the current code will not work.

So the question still remains, what code actually will work? Thanks!

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
7 years 7 months ago #267113

Hello,

In the email context, you have the variable "$data".
And as you can see in the code just before what you have pasted, you will find the loading of the order custom field and the display of these fields ; just like what you want to do.

$fields = $fieldsClass->getFields('frontcomp',$data,'order','');
$fieldsClass->show($oneExtraField, $data->cart->$fieldName,'admin_email')

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
7 years 7 months ago #267217

Hi Jerome,

alright great, I put in this code in place of my other code:

$fields = $fieldsClass->getFields('frontcomp',$data,'order','');
$fieldsClass->show($oneExtraField, $data->cart->$yourdesiredduedate,'admin_email');

While it doesn't send the admin email, it shows a mostly blank screen with only this text:
Your Desired Due Date : 04/28/2017

So the date is actually formatted correctly, but I can't tell if it's correct in the subject of the email, since it never sends.

How should I modify this to get it working?

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
7 years 7 months ago #267219

$data->cart->yourdesiredduedate


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.

Time to create page: 0.094 seconds
Powered by Kunena Forum