0

I am trying to edit customer form data in which i have added one contact number as attribute in form. On removing the text from contact number and then saving it i am not able to save null or empty string in database after form is submitted.

Code: $customerDto->setCustomAttribute('contact_number',NULL); $this->customerRepository->save($customerDto);

Is there any other way to save custom attribute value of customer to null or empty string on form submit

2 Answers 2

0

This might be a limitation based on the is_required attribute property. When this is set to false(0), the attribute is not seen as required and could be set to null.

0

your attribute should look like

$customerSetup->addAttribute(Customer::ENTITY, 'partner_id_microsoft', [
                'type' => 'varchar',
                'label' => 'MPN ID',
                'input' => 'text',
                'required' => false,
                'visible' => true,
                'user_defined' => true,
                'sort_order' => 1001,
                'position' => 1001,
                'system' => 0,
            ]);
            $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'partner_id_microsoft')
            ->addData([
                'attribute_set_id' => $attributeSetId,
                'attribute_group_id' => $attributeGroupId,
                'used_in_forms' => ['adminhtml_customer','customer_account_edit','customer_account_create'],
            ]);

            $attribute->save();

while saving data to customer you have to use:

//get post value for partner_id_cisco
            $customer->setCustomAttribute('partner_id_cisco',$partner_id_cisco);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.