Extracting Transaction ID from the Order, for store report, via MySQL Query (custom report).
As an alternative, I had asked eWay if they would assist in amending their module to write their transaction data to it's own table, however as the dev team were winding down for Christmas / New Year, an 'emergency measure' in the meantime was emailed to me, the following code suggestions have been presented.
Ideally I would like to see the module write to it's own tables, is this something that someone in the community could do - or is this gateway an eWay only module??
I have been communicating with eWay regarding my options, however over Christmas/New Year it may be quicker coming and asking for some further advice here.
I am adding to my store monthly sales query which I run using a custom MySQL query in MySQL Workbench and I am trying to extract the Transaction ID from each order that has been purchased using eWay, which I then match up my eWay reports transaction history in excel.
I was given these 2 pieces of code to add to my query, both work, however they only return orders with the Transaction ID, and none of those where the 'Comments' are blank or contain 'PayPal' (which I also added as an 'OR'). If someone could please assist.
----------
eWay code
Code:
select REPLACE(comments, 'eway TransactionID: ', '') from orders_status_history WHERE comments LIKE 'eway TransactionID%'
- Only returns eWay transactions
or
Code:
select orders_id, REPLACE(comments, 'eway TransactionID: ', '') AS transaction_id from orders_status_history WHERE comments LIKE 'eway TransactionID%'
----------
My code
This returns the Transaction ID, but I can't get it to return both eWay & PayPal OR eWay, blank & PayPal and if I tell it to return ALL comments, my query returns over 10,000 lines, 2/3 of which are duplicates as the customer and admins have added comments to orders.
Code:
Select
-- Get Order data --
T5.orders_id As OrdID,
DATE_FORMAT(T5.date_purchased, '%Y-%m-%d') As OrdDate,
T3.products_name As ProdName,
-- Rest of query --
REPLACE(O2.comments, '%eway Transaction%', '') as OrdCom
-- Extra query --
From /*PREFIX*/products T1
--other joins--
Left Join /*PREFIX*/orders_status_history O2 On (O2.orders_id = T2.orders_id)
----------
I was wondering about using a CASE query, however I am unsure on how to write it.
How do I extract the whole string of what is in the comments (as below), except in the case of PayPal, example under "CASE"
Code:
CASE
When(O2.comments = '%eway Transaction%') then 'eway TransactionID: xxxxxxxxx' -- eWay
When(O2.comments = '%Transaction ID%') then 'Transaction ID: 02D32743CD990491Y' -- PayPal**
When(O2.comments = ' ') then ' ' -- Blank comments
When(O2.comments = 'everything else') then ' ' -- Blank comments
End As OrdCom,
** However, PayPal comments return as below, so would want to truncate them to only between "Transaction ID and P" (Payment), any ideas??:
'Transaction ID: xxxxxxxxxxxxxxxxx
Payment Type: PayPal Express Checkout (instant)
Timestamp: 2013-09-26T18:48:09Z
Payment Status: Completed
Amount: 29.99 AUD '
In Excel I would use: =LEFT(A1,FIND("Payment",A1&"Payment")-1)
-----
Is this a lost cause, I'm sure I should be able to just extract the the TransID comments without all the other data, in a larger query, without having to run 2 separate reports and join then post run.
Thanks in advance.