Customer creation for Magento

A guide on how to create Companies on Magento 2 using Alumio

Strategy

  1. Read input file from a location or some endpoint that provides the required company information to be created on Magento. For this example, we will use XML input from SFTP storage as the input source (Incoming configuration).
    Sample input data
    <?xml version="1.0" encoding="UTF-8"?>
    <Companies>
    <Company>
    <id>87</id>
    <Status>1</Status>
    <Company_Name>3D BoXXw bv</Company_Name>
    <Company_email>MaaXXXX@XXXXtiv.com</Company_email>
    <Street>HeiXXXge AdXanXXXXaat 2</Street>
    <City>ESBEXXK</City>
    <Country_id>NL</Country_id>
    <Postcode>50X5 EM</Postcode>
    <Telephone>013-5169163</Telephone>
    <Customer_group_id>BoXX/tiXXer</Customer_group_id>
    <Sales_representative_id>BoXX eXX timXXr (Ehv)</Sales_representative_id>
    <super_user_id>50</super_user_id>
    </Company>
    <Company>
    <id>101</id>
    <Status>1</Status>
    <Company_Name>3D22BoXXw bv</Company_Name>
    <Company_email>MaaXXXX2XXXX@tiv2.com</Company_email>
    <Street>HeiXXXg2e AdXanXXXXaat 2</Street>
    <City>ESBEXXK</City>
    <Country_id>NL</Country_id>
    <Postcode>50X5 EM</Postcode>
    <Telephone>013-5169163</Telephone>
    <Customer_group_id>BoXX/tiXXer</Customer_group_id>
    <Sales_representative_id>BoXX eXX timXXr (Ehv)</Sales_representative_id>
    <super_user_id>51</super_user_id>
    </Company>
    </Companies>
  2. Create a route that links the Incoming configuration to the Outgoing configuration on Alumio.
  3. Create and invoke transformations that transform the data into a request body that satisfies the requirements of the Magento APIs for company creation. A sample request body is as shown below,
    {
    "company": {
    "City": "ESBEXXK",
    "Status": 1,
    "street": [
    "HeiXXXg2e AdXanXXXXaat 2"
    ],
    "Postcode": "50X5 EM",
    "Telephone": "013-5169163",
    "Country_id": "NL",
    "reseller_id": "101",
    "Company_Name": "3D22BoXXw bv",
    "Company_email": "MaaXXXX2XXXX@tiv2.com",
    "super_user_id": 51,
    "Customer_group_id": 1,
    "Sales_representative_id": 0
    }
    }
    super_user_id - Company admin customer id.
  4. Create an outgoing configuration that pushes the payload to the Magento company creation API. The relevant API call is as shown below,
      POST: /rest/all/V1/company/

    Docs: https://magento.redoc.ly/2.4.0-admin#operation/companyCompanyRepositoryV1SavePost

 

Incoming connection

The incoming configuration of the Company creation configuration is as follows,

From the input data we see that more than one company is nested within the companies tag, we will utilize the "Get branches from patterns" to split the companies into individual tasks in the pipeline.

If the input is as follows,

<companies>

<company>
.
.
.
</company>
<company>
.
.
.
</company>
</companies>


The branch pattern is company.* the companies or root tag will be removed by the XML reader.
So we will simply split the array of company into individual task.

Branching the company into tasks.

Route configuration

The company restructures code is responsible for transforming the incoming data into the required payload structure.

{
"$schema": "https://di.schema.mediact.com/register.configuration.json",
"type": "list-transformer",
"identifier": "leeuwerik-company-creation-restructure-v2",
"name": "Leeuwerik Company creation restructure v2",
"description": null,
"object": {
"prototype": "data",
"parameters": {
"transformers": [
{
"prototype": "value-mapper",
"parameters": {
"mappers": [
{
"prototype": "cast-int",
"parameters": []
}],
"accessor": {
"prototype": "pattern",
"parameters": {
"keys": [
"Customer_group_id",
"id",
"super_user_id",
"Status",
"Sales_representative_id"
]}}}},
{
"prototype": "pattern-move",
"parameters": {
"pattern": "Street",
"replacement": "street.0"
}},
{
"prototype": "value-mapper",
"parameters": {
"mappers": [
{
"prototype": "dictionary-map",
"parameters": {
"map": [[
0,
1]],
"comparator": "equals"
}}],
"accessor": {
"prototype": "key",
"parameters": {
"keys": [
"Customer_group_id"
]}}}},
{
"prototype": "pattern-move",
"parameters": {
"pattern": "id",
"replacement": "reseller_id"
}},
{
"prototype": "value-mapper",
"parameters": {
"mappers": [
{
"prototype": "cast-string",
"parameters": []
}],
"accessor": {
"prototype": "pattern",
"parameters": {
"pattern": "reseller_id"
}}}},
{
"prototype": "pattern-move",
"parameters": {
"pattern": "*",
"replacement": "company.$1"
}}]}}}

Outgoing connection

The outgoing configuration to create the Company on Magento is as shown below,