2

我尝试使用我的自定义模块创建新客户帐户。我需要将性别与客户帐户创建一起存储。这是我尝试存储性别的集合。

  $customer = Mage::getModel('customer/customer')->setId(null);
        $customer->setData('firstname', $data['first_name']);
        $customer->setData('lastname', $data['last_name']);
        $customer->setData('email', $data['email']);
        $customer->setData('gender', $data['gender']);
        $customer->setData('is_active', 1);
        $customer->setData('confirmation', null);
        $customer->setConfirmation(null);
        $customer->getGroupId();
        $customer->save(); 

在此集合中,名字、姓氏和电子邮件正确保存在客户表中。但是性别信息没有保存在客户表中?

4

1 回答 1

4

除了两个小错误(双重设置confirmation, obsolete getGroupId)之外,这应该可以工作。

我的猜测是您在$data['gender'].

尝试使用固定的性别值来检查:

$customer = Mage::getModel('customer/customer')
    ->setFirstname('John')
    ->setLastname('Doe')
    ->setEmail('51zv52zg@example.com')
    ->setGender(
        Mage::getResourceModel('customer/customer')
            ->getAttribute('gender')
            ->getSource()
            ->getOptionId('Female')
    )
    ->setIsActive(1)
    ->setConfirmation(null)
    ->save();
于 2012-09-21T08:46:24.730 回答