Creatinge new ERP message¶
Standard messages have to meet stricter conventions like the UBL message standard. Project-specific messages can be added in a more simple way with less effort.
Use case: ERP message ItemTransfer¶
This example shows how to set up and use a new ERP message. The example uses a message which requests product data from the ERP system that is often required in online shops.
The example is using the Web.Connector to fetch data about a given SKU in real time. The name of the product and the inventory is displayed on a webpage.
You can find more existing ERP messages in ERP messages component.
Fetch products from ERP¶
The Web.Connector provides the web service operation
This method fetches data for a given SKU and returns some data about this product.
The SKU value may also be a filter such as
1.. (this is a NAV notation that lists all products where the SKU starts with
The ERP expects the following XML as a request:
1 2 3 4
The ERP responds with the following XML. The
ITEM tag can be repeated for each product returned by the ERP.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
You need to send the request as expected by the ERP, but map the response if required.
Create the request and response XML¶
UBL 2.0 is used as base for the XML structure and customized when necessary.
You create the request and response XML to generate message objects from as expected by the shop.
Make sure that the toot tags are not using the same name.
It is a good practice to name the tag of the response adding a suffix such as
These two xml files have to be stored in the subdirectory
Resources/specifications/xml/ of your project:
request.itemtransfer.xmlcontains the specification for the request.
response.itemtransfer.xmlcontains the specification for the response.
1 2 3 4 5
This is the expected response of the ERP answer. Since the tag
ITEM is provided for each product,
ses_unbounded="ITEM" informs the shop that it should handle this element as an array.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
There are several XML attributes (
ses_type), that can be used.
See XML format (necessary additional attributes) for more information.
Create XSL mapping¶
To send and retrieve the XML in the proper format, create a mapping. For more information see ERP mapping component.
Two mappings have to be defined (note that the file ending is now
request.itemtransfer.xslmaps the request as modeled before into the format the ERP expects.
response.itemtransfer.xslmaps the response from the ERP as modeled before into the format the shop expects.
1 2 3 4 5 6
1 2 3 4 5 6 7 8
Generate request/response message classes¶
Now that you have the XML as expected from the shop and the mapping to/from the ERP system, you are ready to generate the PHP objects. For more information, see ERP Message-Class-Generator.
If you recreate the PHP objects, you have to delete the old objects first.
The "-force" parameter performs this task automatically.
This includes all classes from the order: Entities/Messages/Document and the
ItemtransferMessage.php from Entities/Messages
as well as the .yml files from the config order:
Add configuration to parameters.yml¶
When all PHP objects are generated, you have to configure the messages so that they are accessible by the shop.
1 2 3 4 5 6 7 8 9 10
Define the web service method which is used in the ERP system or Web.Connector.
In this example the operation
SV_ITEM_TRANSFER is used.
Using request and response¶
When everything is set up, you can use the request and response objects in the shop.
Implement a controller which gets the SKU using the URL (e.g.
establishes the connection to the ERP and loads a template.
Keep in mind that setting/getting content to/from elements always requires accessing the value attribute, for example:
$itemtransferRequest ->ITEM_MAXCOUNT->value = '1';
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
1 2 3 4 5 6 7 8 9 10 11 12