Categories
#DEV

Deleting Magento Customer Address Programmatically

When upgrading Magento for one of our customers, we’ve realized somehow all the shipping information were half complete. It either had a region filled out without address or zip code. When you enter that customer’s profile and try to save it, it wouldn’t save because these are required fields. This was causing these old customers to purchase stuff from the store because they assumed their address was saved.

The best thing to do when you encounter such an issue with Magento is to clear saved addresses altogether. Our team has written a neat little script that would delete all the saved addresses given that you know their email addresses. This is easy to find out if you were to just export all customer profiles through Magento panel. Some might argue that you can do this Data Profiles Import/Export function. Unfortunately, Magento has a function to replace only if the value contains something. If you leave it blank, it wouldn’t touch that field. So you would still have the customers whose addresses are half filled with missing information.

I hope this helps someone in need 🙂

<?php
  include('app/Mage.php');
  Mage::app();  
  
  $customer_emails = array(
    "[email protected]",
    "[email protected]"
);
  
  foreach($customer_emails as $customer_email){
    
    echo $customer_email . "</br>";
    $customer = Mage::getModel("customer/customer");
    $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
    $customer->loadByEmail($customer_email); //load customer by email id
    $customer_id = $customer->getId();
    
      echo $customer_id. "</br>";
      foreach ($customer->getAddresses() as $address)
      {
         $customerAddress[] = $address->toArray();
         
         $address->delete();
      }
      
    echo '<pre/>';print_r($customerAddress );
  }
  
  
?>

 

Categories
#DEV Tutorials Useful & Productive

Magento Slow Backend but A Fast Frontend

Past two days has been a nightmare. We recently migrated all of our websites to Amazon Web Services (AWS), and the speed has been good. We love it. The infrastructure is excellent and so is the service we’re getting. I wouldn’t have a lot to say about their support, though. Unless you are a reasonably big enterprise which is spending a lot of dollars, you can’t afford their support packages. What I suggest from my personal experience is to subscribe to their developer support. If you get into issues relating to operating websites on their servers, they usually point you in the right direction. You will get a response generally within 24 hours which is ok.

The reason why I am writing this post is not to address that. It’s actually due to our experience with Magento. Over the past two days, I have learned so much about Magento E-Commerce Platform. One of our client who runs one of the biggest online pharmacies in New Zealand – YourChemist.co.nz hosts with us. The database is big, and so are the files. Migrating to AWS took a while, but we got there eventually. Since this website was so busy all through the day, the only time we could migrate had to be at midnight when it has the least amount of site traffic.

After migrating, we started noticing a significant problem. The speed of Magento’s backend or as some would address it as admin panel was terrible. So I did my little research on tackling this issue.