Thursday, January 16, 2014

Creating a Configurable Commerce Item : ATG



      Configurable commerce items are items with other items as optional components, and are described in the Using and Extending the Standard Catalog chapter of this manual.

Follow these steps to create a new ConfigurableCommerceItem and associate it with an Order:


Call CommerceItemManager.createCommerceItem() to create the base commerce item.

Call CommerceItemManager.addSubItemToConfigurableItem() or addAsSeparateSubItemToConfigurableItem() to add options to the base item.

The example below illustrates how to programmatically create a ConfigurableCommerceItem with subSKU items and then add it to an Order.

Example:


// Creating Configurable CommerceItem
ConfigurableCommerceItem configurableItem = (ConfigurableCommerceItem)
getCommerceItemManager().createCommerceItem("configurableCommerceItem",
 "sku10001", null, "prod10001", null, 1, null, null, new ItemPriceInfo());

SubSkuCommerceItem subskuItem = (SubSkuCommerceItem)
getCommerceItemManager().createCommerceItem("subSkuCommerceItem",
"sku20001", null, "prod20001", null, 1, null, null, new ItemPriceInfo());
getCommerceItemManager().addSubItemToConfigurableItem(configurableItem,
subskuItem);

subskuItem = (SubSkuCommerceItem)
getCommerceItemManager().createCommerceItem("subSkuCommerceItem",
"sku20002", null, "prod20002", null, 1, null, null, new ItemPriceInfo());
getCommerceItemManager().addSubItemToConfigurableItem(configurableItem,
subskuItem);

//Adding Configurable CommerceItem to Order
getCommerceItemManager().addItemToOrder(order, configurableItem);




Creating a Standard Commerce Item : ATG

Follow these steps to create a new CommerceItem and associate it with an Order:

1. Call CommerceItemManager.createCommerceItem().

2. Make any changes to the CommerceItem, such as setting the quantity.

3. Call CommerceItemManager.addItemToOrder(pOrder, pCommerceItem) to add the CommerceItem to       the Order.

Refer to the below example:


// Get a reference to the OrderManager
OrderManager orderManager = (OrderManager)
  request.resolveName("/atg/commerce/order/OrderManager");

// Create the CommerceItem
CommerceItem commerceItem =
  commerceItemManager.createCommerceItem(pCatalogRefId);
commerceItem.setQuantity(3);

// Add the CommerceItem to the Order
commereceItemManager.addItemToOrder(pOrder, commerceItem);


Note: createCommerceItem() will work even if you pass it a nonexistent catalog reference ID. This allows you to use ATG Commerce as an ordering system with multiple catalogs, some of which may not have repositories. If you want to prevent this behavior, you must institute a check.

Auxiliary data is a construct that exists in a CommerceItem object. This structure allows arbitrary data to be stored with a CommerceItem.

This data could be the options for a CommerceItem such as size and color. It could also refer to the product reference in the catalog. An important concept is that any data that is inserted into the auxiliary data can be serialized at any time in a system that contains remote components.

When defining AuxiliaryData objects, the classes must be defined as serializable. As initially defined, the class includes ProductID, ProductRef, PropertyValue, and CatalogRef properties.



Popular Posts