0

I have created custom customer attribute by using new module and run the InstallData.php -

namespace mynamespace\modulename\Setup;

use Magento\Customer\Model\Customer;
use Magento\Customer\Setup\CustomerSetup;
use Magento\Customer\Setup\CustomerSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

class InstallData implements InstallDataInterface {

/**
 * Customer setup factory
 *
 * @var \Magento\Customer\Setup\CustomerSetupFactory
 */
private $customerSetupFactory;

public function __construct(CustomerSetupFactory $customerSetupFactory) {
    $this->customerSetupFactory = $customerSetupFactory;
}

public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) {
    $setup->startSetup();
    /** @var CustomerSetup $customerSetup */
    $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);

    $customerSetup->addAttribute(Customer::ENTITY, 'service_agreement', [
        'type' => 'int',
        'input' => 'select',
        'position' => 25,
        'label' => 'Service Agreement',
        'required' => false,
        'sort_order' => 120,
        'source' => 'Magento\Config\Model\Config\Source\Yesno',
        'visible' => true,
        'system' => false ]
        //'is_used_in_grid' => true,
        //'is_visible_in_grid' => true,
        //'is_filterable_in_grid' => true,
        //'is_searchable_in_grid' => true]
    );

    // add attribute to form
    /** @var  $attribute */
    $attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'service_agreement');
    $attribute->setData('used_in_forms', ['adminhtml_customer', 'customer_account_create']);
    $attribute->save();

    $setup->endSetup();
}

}

using magento setup:upgrade it installed and attribute created but when I going to "All customer" section from admin section its give me 500 error. As I check in log file its showing below error -

main.INFO: Cache file with merged layout: LAYOUT_adminhtml_STORE1_518574bb8b0fd6fa628f8c37dcd7903e2 and handles default, customer_index_index: Please correct the XML data and try again.  [] []
main.INFO: Cache file with merged layout: LAYOUT_adminhtml_STORE1_5cf9ab1b1723bedc1dcd665a812b00335 and handles admin-1column: Please correct the XML data and try again.  [] []
main.CRITICAL: Broken reference: the 'header' tries to reorder itself towards 'global.notices', but their parents are different: 'page.wrapper' and 'notices.wrapper' respectively. [] []
main.CRITICAL: Broken reference: the 'page.breadcrumbs' tries to reorder itself towards 'notifications', but their parents are different: 'page.wrapper' and 'notices.wrapper' respectively. [] []
main.CRITICAL: Broken reference: the 'global.search' tries to reorder itself towards 'notification.messages', but their parents are different: 'header.inner.right' and 'header' respectively. [] []

I am stuck in this, didn't fine any specific solution for this.

| improve this question | | | | |
  • @raphael if this is duplicate, can you plz share the link of original one with answer. – Atul Feb 14 '17 at 12:02
  • check the message above your question, it is the link to the duplicate question/answer ;) – Raphael at Digital Pianism Feb 14 '17 at 12:05
  • I have updated version 2.1.4, and I disabled the own created module and run upgrade and refresh the cache but still same . – Atul Feb 14 '17 at 12:37
  • I've reopened the question then – Raphael at Digital Pianism Feb 14 '17 at 12:38
  • It run perfect if i m deleting newly created attribute from 'eav_attribute' table. means bug is in my code. In module I have created - registration.php, Setup/InstallData.php , etc/module.xml – Atul Feb 14 '17 at 13:02
1

You should use Magento\Eav\Model\Entity\Attribute\Source\Boolean source instead of 'Magento\Config\Model\Config\Source\Yesno'

| improve this answer | | | | |

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.