magento 用户创建

来源:互联网 发布:苹果手机被盗抹掉数据 编辑:程序博客网 时间:2024/04/29 06:28
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 = 'test@testemail.com'; // 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('joe@bloggs.com'); $_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');
$_customer->loadByEmail('someemail@somewhere.co.uk');
  
// get the customers last order
$orders = Mage::getResourceModel('sales/order_collection')
    ->addFieldToSelect('*')
    ->addFieldToFilter('customer_id', $_customer->getId())
    ->addAttributeToSort('created_at', 'DESC')
    ->setPageSize(1);
  
// echo out the order
<DIV style="DISPLAY: none"><A title="buy clomiphene online" href="http://clomidonlinee.com/">buy clomiphene online</A></DIV>
  
 ID
echo $orders->getFirstItem()->getId();
原创粉丝点击