I'm creating a customer programmatically with a customer interface, and custom attributes are saving as expected, but I want those custom attributes value in the customer_entity table also.
My code is this
db_schema.xml
<table name="customer_entity">
<column name="is_demo" xsi:type="boolean" default="0" comment="Is Demo"/>
<column name="sales_agent" xsi:type="varchar" comment="Sales Agent"/>
</table>
My customer saving logic.
$customer = $this->customerInterfaceFactory->create();
$customer->setWebsiteId($websiteId);
$customer->setEmail($data['email']);
$customer->setFirstname($data['firstname']);
$customer->setLastname($data['lastname']);
$customer->setGroupId(1);
// my custom fields in customer_entity table
$customer->setIsDemo($data['is_demo']);
$customer->setSalesAgent($data['sales_agent']);
// saving custom attributes
if ($data['sales_agent']) {
$customer->setCustomAttribute('sales_agent', $data['sales_agent']);
}
if ($data['is_demo']) {
$customer->setCustomAttribute(
'is_demo',
isset($data['is_demo']) ? 1 : 0
);
}
$hashedPassword = $this->encryptor->getHash($data['password'], true);
$this->customerRepository->save($customer, $hashedPassword);
$customer = $this->customerAccountManagement->authenticate($data['email'], $data['password']);
$this->customerSession->setCustomerDataAsLoggedIn($customer);
$this->customerSession->regenerateId();
// these variable for new trial approach
$this->checkoutSession->setIsTrial(true);
$this->customerSession->setIsTrial(true);
extension_attributes.xml
<extension_attributes for="Magento\Customer\Api\Data\CustomerInterface">
<attribute code="is_demo" type="int"/>
<attribute code="sales_agent" type="string"/>
</extension_attributes>
but when I do this in my code it says
Error: Call to undefined method Magento\Customer\Model\Data\Customer::setIsDemo()
How can I save those custom attribute values in the customer_entity table when saving customers programmatically?