通过代码手动将出生日期添加到客户帐户详细信息?

时间:2013-02-27 19:55:49

标签: magento magento-1.7

我在查询字符串中有一个生日,如:

?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);

任何解决方案?

2 个答案:

答案 0 :(得分: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);

答案 1 :(得分: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();