2013-02-27 61 views
2

我在查詢字符串像一個生日:通過代碼手動添加生日到客戶帳戶的詳細信息?

?birthdate=1991-01-01 

和我的代碼如下:

$customer->setWebsiteId(Mage::app()->getWebsite()->getId()); 
$customer->loadByEmail($email); 
if (!$customer->getId()) { 
    $customer->setEmail($email); 
    $customer->setFirstname($name); 
    $customer->setLastname($lastname); 
    $customer->setPassword($password); 
    $customer->setGender(
    Mage::getResourceModel('customer/customer') 
     ->getAttribute('gender') 
     ->getSource() 
     ->getOptionId($gender) 
    ); 
} 

同樣的方式,我想這樣的:

$customer->setBirthday($date); 

任何解決方案?

+0

只要你有一個對象,你不知道嘗試$ obj-> getData()或$ obj-> debug()這將提供更多的細節。 – oscprofessionals 2013-02-28 03:24:53

+0

謝謝薩蒂什,我會嘗試。 – LuFFy 2013-02-28 13:15:25

回答

4

生日字段實際上被稱爲dob。嘗試:

$customer->setDob('1991-01-01'); 

或添加以下日期代碼:

list($y, $m, $d) = explode('-', $birthday); 

$date=date('m/j/Y', strtotime("$y-$m-$d")); 

$customer->setDob($date); 
+0

謝謝,但它增加了默認日期1/1/1970 爲什麼? – LuFFy 2013-02-28 13:16:04

+0

你有沒有使用我的相同格式?如果是這樣,嘗試MM-DD-YYYY – 2013-02-28 13:45:00

+0

不,我添加了以下代碼 list($ y,$ m,$ d)= explode(' - ',$ birthday); $ date = date('m/j/Y',strtotime(「$ y- $ m- $ d」)); $ customer-> setDob($ date); – LuFFy 2013-02-28 14:18:31

0

感謝馬特。我修改了你的解決方案(因爲我也遇到了01-01-1970日期的麻煩)。也許有人可以使用它:

 // $birthday format m/d/y -> convert to m-d-Y 
     $datetime = DateTime::createFromFormat('m/d/y', $birthday); 
     $customer->setDob($datetime->format('m-d-Y')); 
     $customer->save();