Post by riqee » Wed Nov 08, 2017 2:53 am

Hey all,

I am fairly new to open cart and have some experience in WooCommerce and pretty general knowledge of PHP, HTML, etc. I am looking into creating a simple script that would, ideally, look at a customers order history and add a comment to their order if they have not ordered in the last 6 months. It sounds simple enough but I'm not totally sure what the best course of action would be to achieve this.

Thanks in advance and sorry if this is a stupid question!

Newbie

Posts

Joined
Wed Nov 08, 2017 2:39 am

Post by webcorvo » Sat Nov 11, 2017 10:19 pm

Hi,
Yes is possible.
You can do that in Customer Orders Report
Last edited by webcorvo on Sun Nov 12, 2017 1:52 am, edited 2 times in total.

Opencart Developer - For custom work and support contact @ webcorvo@gmail.com


User avatar
Active Member

Posts

Joined
Mon Mar 20, 2017 11:42 pm
Location - Lisbon, Portugal

Post by straightlight » Sun Nov 12, 2017 12:05 am

The question would also be to know what if the customer does not fill out a comment after the past 6 months for his last order. A customer could simply purchase a product and never visit the order history more than once within the first 6 months period.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by webcorvo » Sun Nov 12, 2017 1:13 am

Yes everything is possible.
webcorvo@gmail.com

Opencart Developer - For custom work and support contact @ webcorvo@gmail.com


User avatar
Active Member

Posts

Joined
Mon Mar 20, 2017 11:42 pm
Location - Lisbon, Portugal

Post by straightlight » Sun Nov 12, 2017 1:42 am

I see. Well, to automatically add a comment to the customer's order and able to see it from the admin order history,

in your catalog/model/checkout/order.php file,

find:

Code: Select all

// If old order status is the processing or complete status but new status is not then commence restock, and remove coupon, voucher and reward history
add above:

Code: Select all

$order_period = $this->db->query("SELECT `order_id` FROM `" . DB_PREFIX . "order` WHERE `date_modified` > DATE_SUB(now(), INTERVAL 6 MONTH) AND `order_period_comment` = '0' AND `order_id` = '" . (int)$order_id . "'");
			
			if ($order_period->num_rows) {
				$this->db->query("INSERT INTO " . DB_PREFIX . "order_history SET order_id = '" . (int)$order_id . "', order_status_id = '" . (int)$order_status_id . "', notify = '" . (int)$notify . "', `comment` = 'More than 6 months', date_added = NOW()");
				
				$this->db->query("UPDATE `" . DB_PREFIX . "order` SET `order_period_comment` = '1' WHERE `order_id` = '" . (int)$order_id . "'");
			}
The More than 6 months message can be changed to your preference.

Then, in your PHPMyAdmin, on your order table, go to the SQL tab and execute the following query:

Code: Select all

ALTER TABLE `oc_order` ADD `order_period_comment` INT(1) NOT NULL DEFAULT '0';
Note: Replace oc_ with your current database table prefix from the query before launching the query. This should resolve the request.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by webcorvo » Sun Nov 12, 2017 1:59 am

straightlight wrote:
Sun Nov 12, 2017 1:42 am
I see. Well, to automatically add a comment to the customer's order and able to see it from the admin order history,

in your catalog/model/checkout/order.php file,

find:

Code: Select all

// If old order status is the processing or complete status but new status is not then commence restock, and remove coupon, voucher and reward history
add above:

Code: Select all

$order_period = $this->db->query("SELECT `order_id` FROM `" . DB_PREFIX . "order` WHERE `date_modified` > DATE_SUB(now(), INTERVAL 6 MONTH) AND `order_period_comment` = '0' AND `order_id` = '" . (int)$order_id . "'");
			
			if ($order_period->num_rows) {
				$this->db->query("INSERT INTO " . DB_PREFIX . "order_history SET order_id = '" . (int)$order_id . "', order_status_id = '" . (int)$order_status_id . "', notify = '" . (int)$notify . "', `comment` = 'More than 6 months', date_added = NOW()");
				
				$this->db->query("UPDATE `" . DB_PREFIX . "order` SET `order_period_comment` = '1' WHERE `order_id` = '" . (int)$order_id . "'");
			}
The More than 6 months message can be changed to your preference.

Then, in your PHPMyAdmin, on your order table, go to the SQL tab and execute the following query:

Code: Select all

ALTER TABLE `oc_order` ADD `order_period_comment` INT(1) NOT NULL DEFAULT '0';
Note: Replace oc_ with your current database table prefix from the query before launching the query. This should resolve the request.
Last edited by webcorvo on Sun Nov 12, 2017 2:13 am, edited 1 time in total.

Opencart Developer - For custom work and support contact @ webcorvo@gmail.com


User avatar
Active Member

Posts

Joined
Mon Mar 20, 2017 11:42 pm
Location - Lisbon, Portugal

Post by straightlight » Sun Nov 12, 2017 2:07 am

The topic subject also indicates to add a comment automatically based on the order history which means, the best way to do it automatically without a cron task, would be when the merchant is about to check an order and the addOrderHistory method could also handle all periodic orders that do not involve the current order ID once the time period has been exceeded. Of course, the order ID can also be removed from the query if all orders that haven't been checked within the past 6 months have not been put in the order history. This would use more resource but would still work by adding a loop by replacing the above statement like the following so that the merchant and / or the customer does not need to write anything:

Code: Select all

$order_period = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order` WHERE `date_modified` > DATE_SUB(now(), INTERVAL 6 MONTH) AND `order_period_comment` = '0'");
			
			if ($order_period->num_rows) {
			foreach ($order_period->rows as $order_per) {
				$this->db->query("INSERT INTO " . DB_PREFIX . "order_history SET order_id = '" . (int)$order_per['order_id'] . "', order_status_id = '" . (int)$order_per['order_status_id'] . "', notify = '0', `comment` = 'More than 6 months', date_added = NOW()");
				
				$this->db->query("UPDATE `" . DB_PREFIX . "order` SET `order_period_comment` = '1' WHERE `order_id` = '" . (int)$order_per['order_id'] . "'");
				}
			}

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by straightlight » Sun Nov 12, 2017 2:16 am

In addition, the admin reports can already indicate the date intervals within the same year which 6 months results should already appear by using the report filters.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by webcorvo » Sun Nov 12, 2017 2:25 am

straightlight wrote:
Sun Nov 12, 2017 2:16 am
In addition, the admin reports can already indicate the date intervals within the same year which 6 months results should already appear by using the report filters.
In Customer Orders Report ;)

Opencart Developer - For custom work and support contact @ webcorvo@gmail.com


User avatar
Active Member

Posts

Joined
Mon Mar 20, 2017 11:42 pm
Location - Lisbon, Portugal
Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot] and 430 guests