Created
July 26, 2017 13:42
-
-
Save neilbradley/b3946e1f0dd4e67b2810c4c54d9793c8 to your computer and use it in GitHub Desktop.
Programmatically set default billing/shipping address of customers if they are not set in magento
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once ("app/Mage.php"); | |
umask(0); | |
Mage::app("default"); | |
$collection = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('*'); | |
foreach ($collection as $customer) { | |
$customerObj = Mage::getModel('customer/customer')->load( $customer->getId() ); | |
if ( ! $customerObj->getDefaultBillingAddress() ) { | |
foreach ($customerObj->getAddresses() as $address) { | |
$address->setIsDefaultBilling('1'); | |
//$address->save(); | |
continue; // we only want to set first address of the customer as default billing address | |
} | |
} | |
if ( ! $customerObj->getDefaultShippingAddress() ) { | |
foreach ($customerObj->getAddresses() as $address) { | |
$address->setIsDefaultShipping('1'); | |
//$address->save(); | |
continue; // we only want to set first address of the customer as default shipping address | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment