Alexander, question regarding importing users who join or renew offline using the import feature in aMember V4. We allow members to join or renew using cheques offline as well as online payments. I'm looking to make it easier to administer our system by importing offline members. However, I notice your system checks the usernames to see if the member already exists. The problem with this is that members joining offline don't have usernames and those renewing might have changed their usernames, as we allow them to do this. We use membership numbers, which are unique to each member. Is there a way to get the system to check this field instead? This number never changes, and new members joining offline are assigned a number as soon as they join. Many thanks, Peter
Peter, I believe it could be easier to write a PHP script for your particular case. From aMember side there will be a few lines of code, but it will work with your file format and import will be instant. Let me know if you need details and if you have programming skills.
it will be something like that (needs testing and tweaking) put it into amember/application/default/plugins/misc/custom-import.php enable custom-import plugin at aMember Cp -> Setup -> Plugins try to access http://yoursite.com/amember/admin-custom-import PHP: class Am_Plugin_CustomImport extends Am_Plugin {} class AdminCustomImportController extends Am_Controller{ protected $lines_imported = 0; public function checkAdminPermissions(Admin $admin) { return $admin->hasPermission(Am_Auth_Admin::PERM_IMPORT); } function indexAction() { // here we load file from predefined location - amember/data/custom-import.csv $f = fopen(DATA_DIR . '/custom-import.csv', 'r'); if (!$f) throw new Am_Exception_InputError("No custom-import.csv uploaded"); $csv_fields = array( 0 => null, // first line is record number, ignore it 1 => 'customid', // second field is your internal userid, 2 => 'amount', // payment amount 3 => 'refid', // payment reference id 4 => 'email', // custom email ); $lines = 0; // count lines while ($line = fgets($f)) { $lines++; $line = preg_split('/\;/', $line); // fields must be ; separated if (count($line) < 2) continue; // skip empty lines $record = array(); foreach ($csv_fields as $k => $v) if ($v) $record[$v] = $line[$k]; // we now pass $record as array('customid'=>'...', 'amount' => '...', 'refid' => '...', 'email' => '...'); $this->processRecord($record); } // now display success $this->view->title = "Custom Import"; $this->view->content("$lines lines processed, {$this->lines_imported} lines imported."); $this->view->display('admin/layout.phtml'); } function processRecord(array $record) { if (!$record['customid']) { print "Empty customid, skip line<br />"; return; } // try find a user record by customid (it must be a SQL field added via aMember CP -> Add Fields) $user = $this->getDi()->userTable->findFirstBy(array('customid' => $record['customid'])); // if user is not found, search by email address if (!$user) $user = $this->getDi()->userTable->findFirstByEmail($record['email']); // if user is not find, create new one if (!$user) { $user = $this->getDi()->userTable->createRecord(); $user->email = $record['email']; $user->generateLogin(); $user->generatePassword(); $user->insert(); } // load product #11 to insert into invoice $product = $this->getDi()->productTable->load(11); // or load product based on $record // now create a new pending invoice $invoice = $this->getDi()->invoiceTable->createRecord(); $invoice->setUser($user); $invoice->paysys_id = 'offline'; // or something else based on $record $invoice->add($product); $invoice->calculate(); $invoice->insert(); // now we add payment record for invoice $payplugin = $this->getDi()->plugins_payment->loadGet($invoice->paysys_id); $tr = new Am_Paysystem_Transaction_Manual($payplugin); $tr->setAmount($record['amount']); $tr->setReceiptId($record['refid']); $invoice->addPayment($tr); $this->lines_imported++; }}
Alex, that looks great, thank you! Now, I assume I can add more fields into the array, such as address details & custom fields already added to the database? This is perfect for me to work on a final code...many thanks for your help!