Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento 是否按代码手动将生日添加到客户帐户详细信息?_Magento_Magento 1.7 - Fatal编程技术网

Magento 是否按代码手动将生日添加到客户帐户详细信息?

Magento 是否按代码手动将生日添加到客户帐户详细信息?,magento,magento-1.7,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(

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

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

生日字段实际上称为
dob
。尝试:

$customer->setDob('1991-01-01');
或添加以下日期代码:

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

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

$customer->setDob($date);

谢谢你,马特。我修改了您的解决方案(因为我在1970年1月1日的日期也遇到了问题)。也许有人可以使用它:

        // $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();

谢谢你,马特。我修改了您的解决方案(因为我在1970年1月1日的日期也遇到了问题)。也许有人可以使用它:

        // $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(),这会提供更多细节。谢谢Satish,我会试试的。!!每当你有一个你不知道的对象时,试试$obj->getData()或$obj->debug(),这会提供更多细节。谢谢Satish,我会试试的。!!谢谢,但它添加了默认日期1970年1月1日为什么?不,我添加了以下代码列表($y,$m,$d)=爆炸('-',$birthday)$日期=日期('m/j/Y',标准时间($Y-$m-$d))$客户->设置日期($date);谢谢,但它添加了默认日期1970年1月1日为什么?不,我添加了以下代码列表($y,$m,$d)=爆炸('-',$birthday)$日期=日期('m/j/Y',标准时间($Y-$m-$d))$客户->设置日期($date);