Last active
December 27, 2015 10:18
-
-
Save tegansnyder/7309743 to your computer and use it in GitHub Desktop.
Importing a list of customer groups into Magento from a CSV file.
This file contains hidden or 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 | |
equire_once('app/Mage.php'); | |
umask(0); | |
Mage::app(); | |
$customer = Mage::getModel('customer/customer'); | |
$csv = array(); | |
// prepare a file called groups.csv with group_name, tax_class_id | |
if( ($handle = fopen('groups.csv', "r")) !== FALSE) { | |
$rowCounter = 0; | |
while (($rowData = fgetcsv($handle, 0, ",")) !== FALSE) { | |
if( 0 === $rowCounter) { | |
$headerRecord = $rowData; | |
} else { | |
foreach( $rowData as $key => $value) { | |
$csv[ $rowCounter - 1][ $headerRecord[ $key] ] = $value; | |
} | |
} | |
$rowCounter++; | |
} | |
fclose($handle); | |
} | |
foreach ($csv as $customer) { | |
$group_data = array(); | |
$group_data['customer_group_code'] = $customer['group_name']; | |
$group_data['tax_class_id'] = $customer['tax_class_id']; // what is the tax_class you want them in | |
Mage::getSingleton('customer/group')->setData($group_data)->save(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment