how do customer details import in magento on programatically?

Posted: November 18, 2011 in Magento

public function massRunprofileAction() {
$connection = Mage::getSingleton(’core/resource’)->getConnection(’core_write’);
$vantgeimportIds = $this->getRequest()->getParam(’vantgeimport’);
if (!is_array($vantgeimportIds)) {
Mage::getSingleton(’adminhtml/session’)->addError($this->__(’Please select item(s)’));
} else {
try {
foreach ($vantgeimportIds as $vantgeimportId) {
//Here Added Customer Data
$vantgeimport = Mage::getSingleton(’vantgeimport/vantgeimport’)
->load($vantgeimportId)->getData();
// XML Read Content
$xmlfile = Mage::getBaseDir(’media’) . DS . ‘vantagecustomer’ . DS . $vantgeimport[’filename’];
$doc = new DOMDocument();
$doc->load($xmlfile);
$arrFeeds = array();
foreach ($doc->getElementsByTagName(’Customer’) as $node) {
$itemRSS = array(
‘Company’ => $node->getElementsByTagName(’Company’)->item(0)->nodeValue,
‘Name’ => $node->getElementsByTagName(’Name’)->item(0)->nodeValue,
‘EMailAddress’ => $node->getElementsByTagName(’EMailAddress’)->item(0)->nodeValue,
‘Country’ => $node->getElementsByTagName(’Country’)->item(0)->nodeValue,
‘PhoneNum’ => $node->getElementsByTagName(’PhoneNum’)->item(0)->nodeValue,
‘FaxNum’ => $node->getElementsByTagName(’FaxNum’)->item(0)->nodeValue,
‘City’ => $node->getElementsByTagName(’City’)->item(0)->nodeValue,
‘State’ => $node->getElementsByTagName(’State’)->item(0)->nodeValue,
‘Zip’ => $node->getElementsByTagName(’Zip’)->item(0)->nodeValue,
‘CreditHold’ => $node->getElementsByTagName(’CreditHold’)->item(0)->nodeValue,
‘Address1’ => $node->getElementsByTagName(’Address1’)->item(0)->nodeValue,
‘GroupCode’ => $node->getElementsByTagName(’GroupCode’)->item(0)->nodeValue
);
array_push($arrFeeds, $itemRSS);
}
$array_leg = count($arrFeeds);
for ($i = 0; $i < $array_leg; $i++) {
$customer_model = Mage::getModel(’customer/customer’);
$customer_model->setData(’firstname’, $arrFeeds[$i][’Name’]);
if ($arrFeeds[$i][’EMailAddress’] == ‘’) {
$email = rand() . ‘xxx@gmail.com’;
} else {$email = $arrFeeds[$i][’EMailAddress’];}
if ($arrFeeds[$i][’CreditHold’] == true) {
$vantagehold = ‘Hold’;}$customer_model->setData(’email’, $email);$customer_model->setData(’lastname’, ‘’);
$customer_model->setData(’vantagehold’, $vantagehold);
$getgroupid = “select customer_group_id from customer_group where customer_group_code=’” . $arrFeeds[$i][’GroupCode’] . “‘“;
$get_groupid = $connection->query($getgroupid);
while ($rowgr = $get_groupid->fetch()) {
$groupid_value = $ids[] = $rowgr[’customer_group_id’];}
if ($groupid_value == ‘’) {$customer_model->setData(’group_id’, 1);
} else {$customer_model->setData(’group_id’, $groupid_value);}
$customer_model->setData(’website_id’, 1);
$customer_model->setData(’created_in’, ‘Admin’);
$customer_model->setData(’default_billing’, ‘’);
$customer_model->setData(’password_hash’, ‘’);
$customer_model->save();
$customerdata_load = Mage::getModel(’customer/customer’);
$customerdata_load->setWebsiteId(1)->loadByEmail($email)->getData();
$customer_id = $customerdata_load[’entity_id’];

$billingAddress1 = Mage::getModel(’customer/address’);
$billingAddress1->setFirstname($arrFeeds[$i][’Name’]);
$billingAddress1->setRegion($arrFeeds[$i][’State’]);
$billingAddress1->setCity($arrFeeds[$i][’City’]);
$billingAddress1->setCompany($arrFeeds[$i][’Company’]);
$country = substr($arrFeeds[$i][’Country’], 0, 2);
$billingAddress1->setCountryId($country);
$billingAddress1->setFax($arrFeeds[$i][’FaxNum’]);
$billingAddress1->setPostcode($arrFeeds[$i][’Zip’]);
$billingAddress1->setTelephone($arrFeeds[$i][’PhoneNum’]);
$billingAddress1->setStreet($arrFeeds[$i][’Address1’]);
$billingAddress1->setEntityTypeId(2);
$billingAddress1->setAttributeSetId(0);
$billingAddress1->setParentId($customer_id);
$billingAddress1->save();}}$this->_getSession()->addSuccess(
$this->__(’Total of %d record(s) were successfully updated’, count($vantgeimportIds)));
} catch (Exception $e) {$this->_getSession()->addError($e->getMessage());}
}$this->_redirect(’*/*/index’);}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s