Business Objects

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.

There are two parts to adding custom business objects to the B2C Commerce environment: definition and creation. You must use Business Manager to define a custom object. You can use the Business Manager, B2C Commerce JavaScript, or import pipelets to create the data for the custom object.

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.

  1. Select Administration > Site Development > Custom Object Types.

  2. To add a definition, click Add.

  3. 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 ProcessingDays object that lets you inform customers how long it takes for their order to ship. Add a ShipmentNo key attribute.

  4. 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.

  5. To add more attributes, click New.

    For example, add the attributes OrderProcessing, Shipping, and TotalShippingTime.

  6. To save your changes, click Apply.

  7. To return to the previous page, click Back.

  8. 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.

  9. To add an attribute group, click New.

    For example, create an attribute group called ShipmentTime.

  10. To add attributes to the group, click Edit.

    For example, add the attributes OrderProcessing, Shipping, and TotalShippingTime.

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).

  1. Select site > Merchant Tools > Custom Objects > Custom Object Editor.

  2. Create an instance of a custom object.

  3. Assign values to the attributes.

    For example, assign OrderProcessing a value of 5, Shipping a value of 6, and TotalShippingTime a value of 11.

You can add custom business objects through B2C Commerce JavaScript. This method of adding custom business objects offers the most flexibility and control.

Use the dw.object package, which contains these classes:

  • CustomObject
  • CustomObjectMgr

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.