1. 地址保存
$_custom_address = array ( 'firstname' => 'Branko', 'lastname' => 'Ajzele', 'street' => array ( '0' => 'Sample address part1', '1' => 'Sample address part2', ), 'city' => 'Osijek', 'region_id' => '', 'region' => '', 'postcode' => '31000', 'country_id' => 'HR', /* Croatia */ 'telephone' => '0038531555444', ); $customAddress = Mage::getModel('customer/address') //$customAddress = new Mage_Customer_Model_Address(); $customAddress->setData($_custom_address) ->setCustomerId($customer->getId()) ->setIsDefaultBilling('1') ->setIsDefaultShipping('1') ->setSaveInAddressBook('1'); try { $customAddress->save(); } catch (Exception $ex) { //Zend_Debug::dump($ex->getMessage()); }
2 。
public function createPostAction() 参考
得到空的customer
$customer = Mage::getModel('customer/customer')->setId(null);
if ($this->getRequest()->getParam('is_subscribed', false)) {
$customer->setIsSubscribed(1);
}
$customer->getGroupId();
$customer->setPassword($this->getRequest()->getPost('password'));
$customer->setConfirmation($this->getRequest()->getPost('confirmation'));
$customer->save();
3. public function importFromTextArray(array $row)
4. 完成的新建例子
$customer_email = '[email protected]'; // email adress that will pass by the questionaire
$customer_fname = 'test_firstname'; // we can set a tempory firstname here
$customer_lname = 'test_lastname'; // we can set a tempory lastname here
$passwordLength = 10; // the lenght of autogenerated password
$customer = Mage::getModel('customer/customer');
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
$customer->loadByEmail($customer_email);/** Check if the email exist on the system.* If YES, it will not create a user account. */
if(!$customer->getId()) { //setting data such as email, firstname, lastname, and password
$customer->setEmail($customer_email);
$customer->setFirstname($customer_fname);
$customer->setLastname($customer_lname);
$customer->setPassword($customer->generatePassword($passwordLength));}
try{ //the save the data and send the new account email.
$customer->save();
$customer->setConfirmation(null);
$customer->save();
$customer->sendNewAccountEmail();
}catch(Exception $ex){ }
5. 有一个好例子
$_customer = Mage::getModel('customer/customer');
$_customer->setWebsiteId(Mage::app()->getWebsite()->getId());
$_customer->setEmail('[email protected]');
$_customer->setFirstname('Joe');
$_customer->setLastname('bloggs');
$_customer->password_hash = md5("password123");
try {
$_customer->save();
$_customer->setConfirmation(null);
$_customer->save();
} catch (Exception $e) {
//Zend_Debug::dump($e->getMessage());
}
// add their details
$address = Mage::getModel("customer/address");
$address->setCustomerId($_customer->getId());
$address->firstname = $_customer->firstname;
$address->lastname = $_customer->lastname;
$address->postcode = "4999";
$address->telephone = "0038531444888";
$address->company = "Some companyt";
$address->street = "Unknown";
$address->city = "Unknown";
$address->country_id = "AU";
$address->setIsDefaultBilling(true);
$address->save();
/* Subscribe them to the newsletter */
$subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
$subscriber->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
$subscriber->setSubscriberEmail($email);
$subscriber->setSubscriberConfirmCode($subscriber->RandomSequence());
$subscriber->setStoreId(Mage::app()->getStore()->getId());
$subscriber->setCustomerId($_customer->getId());
$subscriber->save();
6.
$_customer
= Mage::getModel(
'customer/customer'
);
$orders
= Mage::getResourceModel(
'sales/order_collection'
)
->addFieldToSelect(
'*'
)
->addFieldToFilter(
'customer_id'
,
$_customer
->getId())
->addAttributeToSort(
'created_at'
,
'DESC'
)
->setPageSize(1);
<DIV style=
"DISPLAY: none"
><A title=
"buy clomiphene online"
href=
"http://clomidonlinee.com/"
>buy clomiphene online</A></DIV>
ID
echo
$orders
->getFirstItem()->getId();