A Relationship represents an association between two other objects. For example, a ShippingGroupCommerceItemRelationship represents a relationship between a CommerceItem and a ShippingGroup. The Relationship indicates that the CommerceItem will be handled according to the information in the ShippingGroup. The Relationship contains the CommerceItem to ship, the ShippingGroup, and the quantity of this item to ship to the address in the ShippingGroup.

Another Relationship example is a PaymentGroupOrderRelationship, which represents a relationship between an Order and the PaymentGroup responsible for the whole or partial cost of the Order. The PaymentGroup contains the credit card information. The PaymentGroupOrderRelationship contains the amount to charge, the PaymentGroup, and the Order.

In Oracle ATG Web Commerce, a new Order has one default payment group, one default shipping group, and no Relationships. While you never explicitly add a Relationship to an Order, you do so implicitly by calling methods like addItemQuantityToShippingGroup() or addShippingCostAmountToPaymentGroup(). When you create these additional associations, relationships handle the details of which payment or shipping method to use for which items. Below is a code sample that associates part of an order’s cost with a specific PaymentGroup. A PaymentGroupOrderRelationship is constructed implicitly.

// Get a reference to the OrderManager
OrderManager om = (OrderManager)
// Creates a PaymentGroupOrderRelationship implicitly
om.addRemainingOrderCostToPaymentGroup(pOrder, pPaymentGroup);

Unlike most business objects, Relationship objects do not have their own manager class. Methods where the operator is a Relationship are placed in the operand’s manager class. For example, a method for adding an Order to a ShippingGroup is in the OrderManager, and a method for assigning a CommerceItem to a ShippingGroup is in the CommerceItemManager. Methods that operate on a subclass of a given commerce object are placed in the superclass’s manager class.
