public function test($setup)
    /** @var CustomerSetup $customerSetup */
    $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);

    // Add new customer attribute

            'label'                 => 'test',
            'input'                 => 'text',
            'required'              => false,
            'sort_order'            => 1000,
            'position'              => 1000,
            'visible'               => true,
            'system'                => false,
            'is_used_in_grid'       => true,
            'is_visible_in_grid'    => false,
            'is_filterable_in_grid' => false,
            'is_searchable_in_grid' => false,
            'default'               => '0'

    // add attribute to form
    /** @var  $attribute */
    $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'lifetime_sales');
    $attribute->setData('used_in_forms', ['adminhtml_customer', 'customer_account_create', 'customer_account_edit']);


public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
    $installer = $setup;


    if (version_compare($context->getVersion(), '0.0.1', '<')) {
                'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                'nullable' => false,
                'length' => '255',
                'comment' => 'test'



This is my code and I can see test in customer section in admin which is what I wanted. But at the moment I am not sure how to populate the current amount customers have ordered. I want to update the test field when customer spend and update the value.

Please can anyone guide me or give any tips to progress this.

This is an example what I want to do. If customer A purchase a product for 10 pound that should be added to test field If the customer A purchase again and say the product is 119.86 pound the total should be 129.86 in test field

Your Answer

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

Browse other questions tagged or ask your own question.