Book Image

Magento 2 Development Cookbook

Book Image

Magento 2 Development Cookbook

Overview of this book

With the challenges of growing an online business, Magento 2 is an open source e-commerce platform with innumerable functionalities that gives you the freedom to make on-the-fly decisions. It allows you to customize multiple levels of security permissions and enhance the look and feel of your website, and thus gives you a personalized experience in promoting your business.
Table of Contents (18 chapters)
Magento 2 Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Adding customer attributes


In some cases, it could be that we need extra attributes for a customer like we did for products. Because a customer is an EAV object, it is possible to add attributes to it, but there is no interface for that in the Community Edition of Magento. When we want to do that, we need to install the attributes by code, and that's the thing that we will do in this recipe. We will add a new field loyaltynumber to the customer.

Getting ready

To add a customer attribute, we need to create an installation or upgrade script. In this recipe, we will create a new module that will install the attribute with the installation script so we don't need to install starter files in Magento.

How to do it...

In the following steps, we will create a small module that adds a customer attribute:

  1. Create a module Packt_CustomerAttribute by creating a file app/code/Packt/CustomerAttribute/etc/module.xml with the following content:

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org...