通过代码手动添加生日到客户帐户的详细信息?
问题描述:
我在查询字符串像一个生日:通过代码手动添加生日到客户帐户的详细信息?
?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);
任何解决方案?
答
生日字段实际上被称为dob
。尝试:
$customer->setDob('1991-01-01');
或添加以下日期代码:
list($y, $m, $d) = explode('-', $birthday);
$date=date('m/j/Y', strtotime("$y-$m-$d"));
$customer->setDob($date);
答
感谢马特。我修改了你的解决方案(因为我也遇到了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();
只要你有一个对象,你不知道尝试$ obj-> getData()或$ obj-> debug()这将提供更多的细节。 – oscprofessionals 2013-02-28 03:24:53
谢谢萨蒂什,我会尝试。 – LuFFy 2013-02-28 13:15:25