You can create custom attributes for an existing system object. For example, you can create an object type of
ProcessingDays to hold an integer that represents the number of days required to process the order.
If your data is especially complex, create a custom business object to handle the transaction. Creation of custom business objects can significantly impact overall performance, is typically unnecessary. Avoid creating a custom business object if there’s another possible solution.
You can define custom business objects that require no explicit database schema changes. B2C Commerce uses the concept of metadata, where you first declare the data element, and then access it.
Use Business Manager to create a custom business object definition. A custom object definition is available for use in all storefronts defined for the organization.
Select Administration > Site Development > Custom Object Types.
To add a definition, click Add.
Define your custom object and a key attribute.
The attribute stores a unique key for every custom object of this type.
For example, create a
ProcessingDaysobject that lets you inform customers how long it takes for their order to ship. Add a
Click the Attribute Definitions tab.
The system automatically creates three attributes for you: UUID, creationDate, and lastModified. These attributes store system data and can't be removed.
To add more attributes, click New.
For example, add the attributes
To save your changes, click Apply.
To return to the previous page, click Back.
To define attribute groups, click the Attribute Grouping tab.
Attribute groups are shown in Business Manager and let you create or edit objects created through scripts.
To add an attribute group, click New.
For example, create an attribute group called
To add attributes to the group, click Edit.
For example, add the attributes
You can use Business Manager to create and manage an instance of a custom object. Instances of a custom object can be site-specific or organization-wide.
Store a custom object instance globally to make it available to the entire organization and all sites. You can also store instances locally per site. The custom object type definition is always available to the entire organization (to all sites).
Select site > Merchant Tools > Custom Objects > Custom Object Editor.
Create an instance of a custom object.
Assign values to the attributes.
For example, assign
OrderProcessinga value of 5,
Shippinga value of 6, and
TotalShippingTimea value of 11.
dw.object package, which contains these classes:
Refer to the API documentation for further details.
Sometimes you want to extend or modify data for an existing B2C Commerce object, such as a product, within a script using a wrapper object that includes a reference to a B2C Commerce object. If you want this information to persist in a pipeline after an interaction continue node, store it in a custom attribute for the object or a separate custom object. The context of the object is changed after an interaction continue node or interaction node and any custom script object you create, even one stored in the Pipeline Dictionary, doesn't let you access any objects referenced as part of that custom script wrapper object.
The following script shows two functions. The first function,
execute(), causes an error if the custom wrapper object (
containerObject()) is stored in the Pipeline dictionary before an interaction continue node and then the product reference is accessed after the interaction continue node. The error is similar to the following.
The second function,
executeX(), doesn't cause an error.
To use this structure, you would first import the package:
Then you would access the contents of the package, including all classes and methods as follows:
In this case, getCustomObject is the method used by the CustomObjectMgr class to return a new custom object where the type ("ExampleType") is a string and the keyValue (123) is a number.
The following script returns a new custom object instance of the specified type, using the given key value.
The type declaration is used for code completion within the Studio environment, and ignored in the code.