Question

I am looking for a way to hook into one of the Magento events that define Order creation Date. I would like to add a counter next to it that shows how many days/weeks/months ago the order was placed.

The reason is some items have extended warranties while others do not so if I could simply calculate the date then customer service could quickly establish whether the item is still covered by the warranty.

I am not sure how I should go about doing this. If anyone would like to lend a hand I would be very grateful for the help...

Thanks in advance!

Was it helpful?

Solution

You can do this via PHP Datetime addition (based on the date of purchase) and set the information on the order at the time of purchase (calculate the date the warranty expires, and store to the order).

Datetime addition, store to quote:

$date = new DateTime($order->getCreatedAt());
$date->add(new DateInterval('P90D'));
$quote->setWarrantyExpirationDate($date->format('Y-m-d'));
$quote->save();

If you'd rather calculate it on the fly - it's a very simple change:

$date = new DateTime($order->getCreatedAt());
$date->add(new DateInterval('P90D'));
echo $date->format('Y-m-d');

Further reading:

http://www.php.net/manual/en/datetime.add.php

http://www.php.net/manual/en/class.dateinterval.php

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top