Magento2 DOB客户属性保存

时间:2018-11-16 07:01:30

标签: magento2

在创建客户的同时,我需要为客户存储dob属性。面临类似的问题,

SQLSTATE [42S22]:找不到列:1054'字段列表'中的未知列'customer_entity.value_id',查询为:SELECT customer_entityvalue_id FROM customer_entity在哪里(attribute_id = '11'AND entity_id ='199')

同时,如果我在客户实体中添加了自定义日期属性,则会保存该属性。 任何人对此都有任何想法。 提前致谢。 我正在存储如下所示的自定义属性,

    $data = []; //Array of attributes with key as attribute code 
    $customer = $this->customerModel->load($customerId);
    $customerData = $customer->getDataModel();
    $customerResource = $this->customerAttrFactory->create();
    foreach ($data as $attrCode => $attrValue):
        $customerData->setCustomAttribute($attrCode, $attrValue);
        $customer->updateData($customerData);
        $customerResource->saveAttribute($customer, $attrCode);
    endforeach;

1 个答案:

答案 0 :(得分:0)

无需将dob另存为属性。 客户实体表具有dob字段,因此我们可以通过下面提供的客户模型进行设置。

    $websiteId = $this->storeManager->getWebsite()->getWebsiteId();
    $customer = $this->customerFactory->create();
    $customer->setWebsiteId($websiteId);
    $data['dob'] = $formData['dob'];
    $customer->setData($data);
    $customer->save();