Jump to content

Date issue with 5.2.13?


Recommended Posts

I've installed 5.2.13 on our plushcatalog store, but I found when checking some emails that the order date in the email for a test order shows as 1408134298 - not written as a calendar date. I expected it to be 08/15/2014. I used {$DATA.order_date} in the email template.

 

I haven't checked the customer emails in a long time, so this may not have anything to do with this upgrade. Your help is appreciated.

Link to comment
Share on other sites

There is code that will convert the "unix timestamp" to a readable value. (order.class.php, near line 543, getOrderDetails()). The function formatTime() (in functions.inc.php, near line 333) checks the configuration settings for a time format. That format is set in admin, Store Settings, Advanced tab, for Time Format may be something like %Y-%m-%d %H:%M

 

We need to make sure there aren't any plugins/snippets with hooks which may be interfering with getOrderDetails().

Link to comment
Share on other sites

I do have %m/%d/%Y %l:%M%p on the Advanced screen.

 

Here's what I have on order.class.php

// Format data
		$order_summary['order_date'] = formatTime($order_summary['order_date'],false,true);
		$order_summary['ship_date']  = ((int)(str_replace('-', '', $order_summary['ship_date'])) > 0) ? formatDispatchDate($order_summary['ship_date']) : "";
		$order_summary['gateway']    = str_replace('_',' ',$order_summary['gateway']);

And functions.inc.php

 * Format time
 *
 * @param string $timestamp
 * @param bool $format
 * @param bool $dynamic
 *
 * @return string/false
 */
function formatTime($timestamp, $format = false, $static = false) {
	if (empty($timestamp)) {
		return false;
	}

	## Convert a timestamp to something legible
	if (!$format) {
		$format = $GLOBALS['config']->get('config', 'time_format');
	}
	$sign	= substr($GLOBALS['config']->get('config', 'time_offset'), 0, 1);
	$value	= substr($GLOBALS['config']->get('config', 'time_offset'), 1);
	if ($sign == '+') {
		$seconds = $timestamp+$value;
	} else if ($sign == '-') {
		$seconds = $timestamp-$value;
	} else {
		$seconds = $timestamp;
	}
	$fuzzy = true;
	if(!$date_today	= strftime('%D', time())) {
		$fuzzy = false;
	}
	$date = strftime('%D', $seconds);
	$time = strftime('%H:%M', $seconds);
	if ($fuzzy && !$static && $date_today == $date) { ## Today
		return $GLOBALS['language']->common['today'].", ".$time;
	} elseif ($fuzzy && !$static && strftime("%D", strtotime('yesterday')) == $date) { ## Yesterday
		return $GLOBALS['language']->common['yesterday'].", ".$time;
	} else {
		return strftime($format, $seconds);
	}
}
Link to comment
Share on other sites

I don't know how to check for Hooks that might be in play. The Hooks listed in Admin are Custom Contact Us, Fusion, Homepage Sales Items, Mailchimp, PayPal Pro, Sale Items with Images, and Sequential Order Numbers. None of those "sound" like they would have any date effects to me. There's only one Code Snippet, and it's to block registrations for typical spammer choices.

 

I just tried an old test order on estates (still on 5.2.12) and the date is a unix timestamp in the email for that one, too. So this problem is not a 5.2.13 issue after all. The only reason I even thought to test customer emails was because there were some changes to Cancelled in this upgrade.

Link to comment
Share on other sites

"I don't know how to check for Hooks that might be in play."

 

You will need to look at the database directly to easily determine if there is a hook or snippet that may be interfering with getOrderDetails(). In the table, Cubecart_hooks, we need to see if any hook has as a 'trigger' the value "class.order.get_order_details" (or any trigger that starts with "class.order").

 

Also look in CubeCart_code_snippet if any snippet has as a 'hook_trigger' a value that starts with "class.order".

Link to comment
Share on other sites

"I used {$DATA.order_date} in the email template."

 

For the email template Cart: Order Confirmed, has, in part:

Your order {$DATA.cart_order_id} has been received which was placed on {$DATA.order_date}.

 

This is working fine for me (CC5212).

 

The way you said you used {$DATA.order_date} in an email template, leads me to believe {$DATA.order_date} wasn't there before. Which template are you specifically having the timestamp show instead of the date?

Link to comment
Share on other sites

I used the Order Failed email and reworked it to be an Unpaid Order email, so I could get one last chance of getting a customer to complete an order they had left pending. I also have that language in an E-check Payment email that was created by a developer. Both show {$DATA.order_date} in the Macros, and both show the timestamp in emails.

Link to comment
Share on other sites

"I used the Order Failed email"

 

There is no email template named Order Failed.

 

There is an order status of ORDER_FAILED that uses the Cart: Fraud Review template.

 

There is an order status of ORDER_CANCELLED that uses the Cart: Order Cancelled template.

 

CubeCart will get the raw order details from the database.

 

However, CubeCart also gets the order's details via getOrderDetails(), tweaks a few of the items, and assigns them to a class-wide variable ($_email_details), which it does before deciding how to process the change in the order status. Cubecart must then assign that variable to the various "sections" (for lack of a better word, such as $DATA and $BILLING) and does this in assignOrderDetails().

 

However, In CC5212 (and presumably in CC5213), in the Cart class, assignOrderDetails() is only called within the blocks of code for when an order goes to Pending, Processing, or Complete, but not when the order goes to Declined, Failed, or Cancelled (also, sending the Digital Download email). Instead, these statuses use the raw order details data.

 

There are several places in the Cart class that need edits so that all status emails gets the most appropriate set of data.

 

"I also have that language in an E-check Payment email."

 

We may need to visit that code to make sure it is using the Cart class functions correctly.

Link to comment
Share on other sites

It was Fraud Review - sorry.

 

There are several places in the Cart class that need edits so that all status emails gets the most appropriate set of data.

 

I had noticed that some of the lines have  $this->assignOrderDetails(null,true);    and others don't have (null,true)

Link to comment
Share on other sites

In the file /classes/order.class.php, near lines 305-317:

Was:
case self::ORDER_DECLINED:
    // Nothing to do, but leave the option here for hooks & such
break;

case self::ORDER_FAILED:
    // Email the customer to explain their order failed fraud review
    $content = $mailer->loadContent('cart.payment_fraud', $order_summary['lang'], $this->_order_summary);
break;

case self::ORDER_CANCELLED:
    // Cancelled
    $content = $mailer->loadContent('cart.order_cancelled', $order_summary['lang'], $this->_order_summary);
break;
 
Now:
case self::ORDER_DECLINED:
    // Nothing to do, but leave the option here for hooks & such
break;

case self::ORDER_FAILED:
    // Email the customer to explain their order failed fraud review
    if( ($content = $mailer->loadContent('cart.payment_fraud', $order_summary['lang'])) !== false ) $this->assignOrderDetails();
break;

case self::ORDER_CANCELLED:
    // Cancelled
    if( ($content = $mailer->loadContent('cart.order_cancelled', $order_summary['lang'])) !== false ) $this->assignOrderDetails();
break;

Also, near line 647:

Was:
if ($this->_email_enabled && ($contents = $mailer->loadContent('cart.digital_download', $this->_order_summary['lang'], $this->_order_summary))) {                
 
Now:
if ($this->_email_enabled && ($contents = $mailer->loadContent('cart.digital_download', $this->_order_summary['lang']))) {
  $this->assignOrderDetails();

Let's see how this works.

Link to comment
Share on other sites

I tried it again with your code, but the Order Summary page still crashes. I've commented out yours and left mine.

				case self::ORDER_FAILED:
					// Email the customer to explain their order failed fraud review
					$content = $mailer->loadContent('cart.payment_fraud', $order_summary['lang'], $this->_order_summary);
//( ($content = $mailer->loadContent('cart.payment_fraud', $order_summary['lang'])) !== false ) $this->assignOrderDetails();
				break;
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...