0

How can you query for customers that have changed their name or address since yesterday?

Problem is that the updated_at field is updated in all tables, whenever the customer changes their passwords too? Even though nothing has changed in the address ect.

Any ideas? Observer? Ect.

1 Answer 1

1

To query customers who have specifically changed their name or address in Magento 2 since yesterday, you can approach the problem by below steps:

  • Create an Observer: Use the events customer_save_after and customer_address_save_after. In your observer, check if the relevant fields (name, address) have changed.

  • Create a Custom Table: You might want to create a custom table with columns like entity_id, customer_id, changed_field, and changed_at.

  • Save Changes in custom table: In the observer, if the name or address has changed, save the customer ID and timestamp in your custom table.

  • Query for Changes: Use a SQL query to select customers from your custom table where changed_at is greater than yesterday's date.

then you can filter data from the custom table using below query

SELECT customer_id 
FROM your_custom_table 
WHERE changed_at >= DATE_SUB(NOW(), INTERVAL 1 DAY);
2
  • Thank you. But with that answer you are also telling me, that there is no "builtin" functionality to leave out when the user just update their password. I have to detect real changes myself?
    – AP87
    Commented Aug 22 at 8:55
  • Yes you need to add customisation yourself using above mentioned event Commented Aug 22 at 10:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.