Page 1 of 1

Added By - Concept Code

Posted: Fri Aug 09, 2024 11:07 am
by burt
SQL

This will set up 4 options with "system" as the default option, this means that "system" should be inserted when (eg) Paypal is used [which I think sends an item to the orders_status_history]. Note that all existing comments will be set to N/A as we do not know who/what added existing comments.

ALTER TABLE orders_status_history ADD added_by ENUM('system', 'admin', 'customer', 'N/A') NOT NULL DEFAULT 'system' AFTER comments;
UPDATE TABLE orders_status_history SET added_by = 'N/A';

CONCEPT CODE

These are (unfortunately) hardcoded changes, which obviously change core code, which is something we try not to do. Could probably be done by Hook, but I don't have time to look at it. Maybe these ideas or concept code could be taken by someone and made into a nice addon for PRO members?

1. admin/includes/actions/orders/update_order.php
Find:
$db->perform('orders_status_history', [

Add After:

Code: Select all

'added_by' => 'admin',
2. includes/system/segments/checkout/insert_history.php
Find:
$sql_data = [

Add After:

Code: Select all

'added_by' => 'customer',
3. admin/includes/actions/orders/views/edit.php
Find:
<th><?= TABLE_HEADING_DATE_ADDED ?></th>

Add After:

Code: Select all

<th>Added By</th>
Find:
echo '<td>' . $orders_history['date_added'] . '</td>';

Add After:

Code: Select all

echo '<td>' . $orders_history['added_by'] . '</td>';

Re: Added By - Concept Code

Posted: Fri Aug 09, 2024 1:10 pm
by Kofod95
Nice @burt!

Found time to do some - maybe someone can complete before me?

This goes in a new file: includes/hooks/admin/orders/commentTracker.php and replaces the edit of admin/includes/actions/orders/update_order.php

Code: Select all

<?php
/*
SQL:
ALTER TABLE orders_status_history ADD added_by ENUM('system', 'admin', 'customer', 'N/A') NOT NULL DEFAULT 'system' AFTER comments;
UPDATE orders_status_history SET added_by = 'N/A';
*/

  class hook_admin_orders_commentTracker {
	function listen_updateOrderAction(){
	  global $db, $order_updated;
	  if($order_updated){
	    $orders_status_history_id = mysqli_insert_id($db);
	    $db->perform('orders_status_history', ['added_by' => 'admin'], 'update', " orders_status_history_id = " . (int)$orders_status_history_id);
	  }
	}
  }
This hook will make admin-comments save with "admin" as a value.
The SQL is included in the comment of the file, as that is what I usually do, untill I figure out how I want to install it.

Making customer comments say "customer" shouldn't be too difficult, but I'm out of time.
Getting the row to show in the status_history_table in the order-edit screen, however. That will surely occupy my brain for the weekend - unless someone shares a solution before the weekend is over ;)

//Daniel