Added By - Concept Code

Open to all! Ask other shopowners for help.
Post Reply
User avatar
burt
Core Team
Posts: 4551
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Added By - Concept Code

Post 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>';
I am not here to build for you.
I am here to build with you. Let's help each other.

Tags:


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
Kofod95
Senior Contributor
Posts: 748
Joined: Sat Feb 06, 2021 7:38 pm
Phoenix Version: 1.0.8.20
Has thanked: 99 times
Been thanked: 179 times

Re: Added By - Concept Code

Post 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
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply