Skip to content

Can't work customer Image attribute programmatically #19983

Closed
@cygnetampatel

Description

@cygnetampatel

Preconditions (*)

  1. Magento CE version 2.2.7
  2. Create custom attribute programmatically, which is to be added to the 'customer eav attribute e.g.:
$customerSetup->addAttribute(\Magento\Customer\Model\Customer::ENTITY, "customerprofile",  array(
                "type"      => "varchar",
                "backend"   => "",
                "label"     => "Customerprofile",
                "input"     => "file",
                "source"    => "",
                "visible"   => true,
                "required"  => false,
                "default"   => "",
                "frontend"  => "",
                "unique"    => false,
                "note"      => ""
            ));
$customerdoc     = $customerSetup->getAttribute(\Magento\Customer\Model\Customer::ENTITY, "customerdoc");
$customerdoc     = $customerSetup->getEavConfig()->getAttribute(\Magento\Customer\Model\Customer::ENTITY, 'customerdoc');
            $used_in_forms[] = "adminhtml_customer";
            $used_in_forms[] = "checkout_register";
            $used_in_forms[] = "customer_account_create";
            $used_in_forms[] = "customer_account_edit";
            $used_in_forms[] = "adminhtml_checkout";
            $customerdoc->setData("used_in_forms", $used_in_forms)
                ->setData("is_used_for_customer_segment", true)
                ->setData("is_system", 0)
                ->setData("is_user_defined", 1)
                ->setData("is_visible", 1)
                ->setData("sort_order", 100);
            $customerdoc->save();

Steps to reproduce (*)

  1. Go to the registration form. you will show Customer profile attribute as a file. when user upload an image error message show "Customer profile is not a valid file".

Expected result (*)

  1. file is valid so data want to save.

Actual result (*)

  1. is not a valid file message on the frontend and backend.

Issue In this file (*)

  1. An issue in the if a condition "Magento\Eav\Model\Attribute\Data\File"

    protected function _validateByRules($value)
    {
    if (!empty($value['tmp_name']) && !is_uploaded_file($value['tmp_name'])) {
    return [__('"%1" is not a valid file.', $label)];
    }
    return [];
    }
    Acctually Image first of upload in temp folder then after move into accordinglly.

according to the condition if a file exists in temp folder it's throw error.

Resolve the issue(*)

protected function _validateByRules($value)
{
if (empty($value['tmp_name']) && is_uploaded_file($value['tmp_name'])) {
return [__('"%1" is not a valid file.', $label)];
}
return [];
}

Metadata

Metadata

Labels

Component: CustomerFixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions