Skip to content

aesha93/ExtendCustomer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Practical_ExtendCustomer Module

This Magento 2 module extends the Customer entity to support an additional attribute origin_channel and exposes it via GraphQL.


Features

  • Adds a new customer attribute: origin_channel
  • Supports values like: null, website, boutique
  • Extends createCustomerV2 GraphQL mutation to accept origin_channel
  • Includes plugins and data patch for setup

Module Location

Place the module inside your Magento installation:

app/code/Practical/ExtendCustomer

Installation Steps

  1. Copy Module
cp -r Practical/ExtendCustomer <magento_root>/app/code/Practical/ExtendCustomer
  1. Enable and Install
bin/magento module:enable Practical_ExtendCustomer
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento cache:flush
  1. Verify Attribute

Check the database:

SELECT * FROM eav_attribute WHERE attribute_code = 'origin_channel';

🌐 REST API Usage

You can also create a customer with the origin_channel attribute using the Magento 2 REST API.

➤ Endpoint

POST /rest/V1/customers

Full URL Example:

https://app.magento248.test/rest/V1/customers

➤ Request Body

{
  "customer": {
    "email": "c.doe@example.com",
    "firstname": "John",
    "lastname": "Doe",
    "extension_attributes": {
      "origin_channel": "boutique"
    }
  },
  "password": "Password123"
}

✅ Sample Response

{
  "id": 13,
  "group_id": 1,
  "created_at": "2025-06-25 08:23:43",
  "updated_at": "2025-06-25 08:23:43",
  "created_in": "Default Store View",
  "email": "c.doe@example.com",
  "firstname": "John",
  "lastname": "Doe",
  "store_id": 1,
  "website_id": 1,
  "addresses": [],
  "disable_auto_group_change": 0,
  "extension_attributes": {
    "is_subscribed": false
  },
  "custom_attributes": [
    {
      "attribute_code": "origin_channel",
      "value": "boutique"
    }
  ]
}

GraphQL Usage

➤ Mutation

mutation {
  createCustomerV2(
    input: {
      firstname: "John"
      lastname: "Doe"
      email: "johre8o4.doe@example.com"
      password: "Password123"
      origin_channel: boutique
    }
  ) {
    customer {
      id
      firstname
      lastname
      email
      custom_attributes{
        code
      }
    }
  }
}

Allowed origin_channel Values

  • null
  • website
  • boutique

Defined in: Model/Source/OriginChannel.php


Key Files

File Description
registration.php Registers module with Magento
etc/module.xml Declares module version
etc/di.xml Plugin configuration
etc/extension_attributes.xml Declares extension attributes
etc/schema.graphqls Adds GraphQL schema extension
Plugin/CustomerAccountManagementPlugin.php Intercepts customer creation
Setup/Patch/Data/AddOriginChannelCustomerAttribute.php Adds origin_channel to customer entity
Model/Resolver/Customer/OriginChannel.php GraphQL resolver

Uninstall (Optional)

bin/magento module:disable Practical_ExtendCustomer
rm -rf app/code/Practical/ExtendCustomer
bin/magento setup:upgrade

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages