Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 22
  1. #11
    Join Date
    Dec 2010
    Posts
    362
    Plugin Contributions
    0

    Default Re: How to remove all customers who have never ordered before?

    It was easy to scan the customers table and find the fakes -- so I simply deleted them and figured I was done.

    But as others have noted, there are other tables in the database that refer to the (now deleted) customer ids.

    My question is -- will this cause any problems down the road? I did this several weeks ago and we haven't experienced any issues, so I'm guessing we're OK. But if there's some kind of cleanup or database realignment that needs doing, I've love to know.

  2. #12
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: How to remove all customers who have never ordered before?

    YES, you should clean up the rest of the data. NEVER BLINDLY HACK OUT RECORDS IN THE DATABASE WITHOUT BEING SURE YOU KNOW WHAT YOU'RE DOING!!!!!
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #13
    Join Date
    Dec 2010
    Posts
    362
    Plugin Contributions
    0

    Default Re: How to remove all customers who have never ordered before?

    Message heard and lesson learned (the way I learn most of my lessons, the hard way).

    But, this raises two questions:

    1) I'm assuming I'd need to:
    -- Find the IDs of all the records I deleted;
    -- Find the tables where those IDs are still in existence;
    -- Delete the records with those IDs from the tables

    This would be incredibly time consuming, not to mention I increase the possibility of deleting records that shouldn't be. Is there a utility that can do these comparisons and clean up the database?

    2) Is there (and if there isn't, why?) a ZC extension that will facilitate the deletion of customers? Right now the only options seem to be to ban the customer or limit their shopping options. A utility that would allow customer records to be easily deleted enmasse would be incredibly useful.

  4. #14
    Join Date
    Jul 2006
    Posts
    308
    Plugin Contributions
    0

    Default Re: How to remove all customers who have never ordered before?

    I'm having this issue too with lots of spam customers I need to delete. Basically ones using the company name of AT&T, microsoft, and apple.

    It looks like it would just take a good SQL DELETE query with the right JOIN keywords to clean up these tables. Has anyone come up with one?

    address_book
    customers
    customers_info
    customers_basket
    customers_basket_attributes
    products_notifications

  5. #15
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: How to remove all customers who have never ordered before?

    Quote Originally Posted by fakeDecoy View Post
    I'm having this issue too with lots of spam customers I need to delete. Basically ones using the company name of AT&T, microsoft, and apple.

    It looks like it would just take a good SQL DELETE query with the right JOIN keywords to clean up these tables. Has anyone come up with one?

    address_book
    customers
    customers_info
    customers_basket
    customers_basket_attributes
    products_notifications
    I find that usually when people are asking something this specific they've already started deleting customer records from the customers table using some tool like phpMyAdmin (or even better something like Navicat or SqlYog or SequelPro). In such cases, running the following will very quickly (in a few seconds) clean up (delete) the associated records from the other related tables:
    Code:
    update reviews set customers_id = null where customers_id not in (select customers_id from customers);delete from address_book where customers_id not in (select customers_id from customers);
    delete from customers_info where customers_info_id not in (select customers_id from customers);
    delete from customers_basket where customers_id not in (select customers_id from customers);
    delete from customers_basket_attributes where customers_id not in (select customers_id from customers);
    delete from whos_online where customer_id not in (select customers_id from customers);
    delete from products_notifications where customers_id not in (select customers_id from customers);
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  6. #16
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,692
    Plugin Contributions
    9

    Default Re: How to remove all customers who have never ordered before?

    Quote Originally Posted by DrByte View Post
    I find that usually when people are asking something this specific they've already started deleting customer records from the customers table using some tool like phpMyAdmin (or even better something like Navicat or SqlYog or SequelPro). In such cases, running the following will very quickly (in a few seconds) clean up (delete) the associated records from the other related tables:
    Code:
    update reviews set customers_id = null where customers_id not in (select customers_id from customers);delete from address_book where customers_id not in (select customers_id from customers);
    delete from customers_info where customers_info_id not in (select customers_id from customers);
    delete from customers_basket where customers_id not in (select customers_id from customers);
    delete from customers_basket_attributes where customers_id not in (select customers_id from customers);
    delete from whos_online where customer_id not in (select customers_id from customers);
    delete from products_notifications where customers_id not in (select customers_id from customers);
    i think what is missing from here is the initial delete.... if you wanted to delete all customers who have not ordered, you could use something like:

    Code:
    delete from customers where customers_id not in (select customers_id from orders);
    and then follow with all of the remaining sql statements.

    if you wanted to delete ones with the company name, it gets a little trickier as the company name is stored in the address_book table and we would have to incorporate that into the initial delete.

    as with all SQL statements, i encourage you to remember an old Shakespearean saying:

    "to err is human... to screw things up, you need a computer.... and to screw things up royally, you need sql...."

    good luck!
    author of square Webpay.
    mxWorks has premium plugins. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  7. #17
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: How to remove all customers who have never ordered before?

    Quote Originally Posted by carlwhat View Post
    i think what is missing from here is the initial delete
    Yes. That was quite intentional, as giving an initial delete is destructive without any constraints, and could be terribly harmful if someone "just does it" without understanding the bigger picture.

    As you said, doing specific deletions based on specific criteria, is a separate exercise.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  8. #18
    Join Date
    Jul 2006
    Posts
    308
    Plugin Contributions
    0

    Default Re: How to remove all customers who have never ordered before?

    Cool, thanks! I think that will do the trick in helping me to clean spam out of my customer db.

  9. #19
    Join Date
    Jul 2006
    Posts
    308
    Plugin Contributions
    0

    Default Re: How to remove all customers who have never ordered before?

    FYI, my queries to delete customers with zero lifetime orders and with no activity for 6 months:

    Code:
    DELETE from zen_customers
    WHERE customers_id IN
    	(SELECT customers_info_id from zen_customers_info where TIMESTAMPDIFF(MONTH,customers_info_date_account_created, NOW()) > 6
    AND TIMESTAMPDIFF(MONTH,customers_info_date_of_last_logon, NOW()) > 6)	
    AND customers_id NOT IN
    	(SELECT customers_id FROM zen_orders);
    
    
    update zen_reviews set customers_id = null where customers_id not in (select customers_id from zen_customers);
    delete from zen_address_book where customers_id not in (select customers_id from zen_customers);
    delete from zen_customers_info where customers_info_id not in (select customers_id from zen_customers);
    delete from zen_customers_basket where customers_id not in (select customers_id from zen_customers);
    delete from zen_customers_basket_attributes where customers_id not in (select customers_id from zen_customers);
    delete from zen_whos_online where customer_id not in (select customers_id from zen_customers);
    delete from zen_products_notifications where customers_id not in (select customers_id from zen_customers);

  10. #20
    Join Date
    Jan 2018
    Posts
    146
    Plugin Contributions
    0

    Default Re: How to remove all customers who have never ordered before?

    Which php file on the ftp does this code go in to?

 

 
Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. v139h Email to customers who have ordered a specific item?
    By thehomeopath in forum General Questions
    Replies: 0
    Last Post: 11 Sep 2012, 03:24 PM
  2. 1062 Duplicate entry 'Customers who have never completed a purchase' for key 2
    By maperr55 in forum Upgrading from 1.3.x to 1.3.9
    Replies: 5
    Last Post: 9 Jul 2010, 05:14 AM
  3. Customers who have never completed an order?
    By MagicMan in forum General Questions
    Replies: 1
    Last Post: 24 Jul 2008, 06:44 PM
  4. 1062 Duplicate entry 'Customers who have never completed a purchase' for key 2
    By elliesupport in forum Upgrading from 1.3.x to 1.3.9
    Replies: 1
    Last Post: 2 Jul 2008, 09:04 PM
  5. 1062 Duplicate entry 'Customers who have never...
    By LostSheep in forum Upgrading from 1.3.x to 1.3.9
    Replies: 15
    Last Post: 17 Apr 2008, 06:53 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR