2013-02-27 62 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();