Hoping a seasoned Magento guy can help out here.
So for any new orders all of a sudden the table: sales_flat_order_payment
and column: method
is not being updated for ONLY the last 2 orders. It was working perfectly fine and then over the weekend something has gone a miss. We are using v1.9.2.2 with no changes having been done over. It was working perfectly fine with a custom file which we use to call the following:
("SELECT `method` FROM `sales_flat_order` LEFT JOIN `sales_flat_order_payment` ON `sales_flat_order`.`entity_id` = `sales_flat_order_payment`.`entity_id` WHERE `sales_flat_order`.`increment_id` = '" . $row['increment_id'] . "'");
Was working fine. Values were pulled in to our custom script with no isses. I can also manually go to phpmyadmin view: sales_flat_order_payment
and column: method
which does have the payment method used inserted. HOWEVER on doing a query:
SELECT `method` , increment_id, remote_ip, updated_at, customer_email FROM `sales_flat_order` LEFT JOIN `sales_flat_order_payment` ON `sales_flat_order`.`entity_id` = `sales_flat_order_payment`.`entity_id` WHERE sales_flat_order.updated_at > '2016-02-23' ORDER BY updated_at DESC
returns the last 2 orders on that sales_flat_order_payment and column: method as being NULL
Best Answer
Your problem is right here in the query:
order.entity_id
is not the same asorder_payment.entity_id
. They may have matched up in the past, but there is no guarantee that will always be the case. They are separate identifiers. You should link the tables onorder_payment.parent_id
instead, like so:Your query is returning
NULL
for some columns because it is not finding any record insales_flat_order_payment
to join at all.