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]);

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 Oct 13 '17 at 12:18
  • Could you add your code? – Mathieu Oct 13 '17 at 12:19
  • I added code ... – Mjuzik Oct 13 '17 at 12:23
  • This is product attribute, I need customer attribute – Mjuzik Oct 13 '17 at 12:34
  • Ok, where I can set id by second store for second attribute? – Mjuzik Oct 13 '17 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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