I have customer attribute and I would like to this attribute is required in first store, not required in second store.

I have one solution, I would like create second customer attribute in a similar code and in first store use first attribute, in second store use second attribute. But I don't know how to set scope for customer attribute. Any hints?

$installer = $setup; $installer->startSetup();

    $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);

1 Answer 1


An example to add an attribute and how to precise the scope, you can update an attribute with the same method:

    public function install( ModuleDataSetupInterface $setup, ModuleContextInterface $context )

            $eavSetup = $this->_eavSetupFactory->create(['setup' => $setup]);

            // add customer_attribute to customer
            $eavSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, 'customer_attribute');
            \Magento\Customer\Model\Customer::ENTITY, 'customer_attribute', [
                'type' => 'varchar',
                'label' => 'Customer Attribute',
                'input' => 'text',
                'required' => false,
                'system' => 0,
                'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
                'sort_order' => '200'

  • how to implement in code by upgradeAttribute() ? I set that only is_required without scope website
    – Mjuzik
    Commented Oct 13, 2017 at 12:18
  • Could you add your code?
    – Mathieu
    Commented Oct 13, 2017 at 12:19
  • I added code ...
    – Mjuzik
    Commented Oct 13, 2017 at 12:23
  • This is product attribute, I need customer attribute
    – Mjuzik
    Commented Oct 13, 2017 at 12:34
  • Ok, where I can set id by second store for second attribute?
    – Mjuzik
    Commented Oct 13, 2017 at 12:42

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.