OrderManager
class is the business layer object for managing and manipulating
Orders. This class holds all the business logic for manipulating an
Order. The various types of methods in this class are used for creating
objects, adding objects to an Order, adding objects to other objects,
removing objects from other objects. Below is an example of creating an
Order, adding CommerceItems to it, assigning those items to a
ShippingGroup and checking the Order out.
OrderManager om = getOrderManager();
CommerceItemManager cm = getCommerceItemManager();
PricingTools pt = getPricingTools();
String profileId = "10000";
String catalogRefId1 = "sku-1";
String catalogRefId2 = "sku-2";
String productId1 = "product-1";
String productId2 = "product-2";
long quantity1 = 1;
long quantity2 = 2;
// create the Order and CommerceItems. The Order has a ShippingGroup and PaymentGroup
// in it when constructed
Order order = om.createOrder(profileId);
CommerceItem item1 = om.createCommerceItem(catalogRefId1, productId1, quantity1);
CommerceItem item2 = om.createCommerceItem(catalogRefId2, productId2, quantity2);
// add the items to the Order, set the return value back to the object because if the
// item catalogRefId already existed in the Order, the quantity is incremented rather
// than adding the new object
item1 = cm.addItemToOrder(order, item1); // CommerceItemManager cm
item2 = cm.addItemToOrder(order, item2);
// get the ShippingGroup and add the items to it
ShippingGroup sg = (ShippingGroup) order.getShippingGroups().get(0);
om.addItemQuantityToShippingGroup(order, item1.getId(), sg.getId(), quantity1);
om.addRemainingItemQuantityToShippingGroup(order, item2.getId(),sg.getId());
// add the entire order amount to the PaymentGroup
PaymentGroup pg = (PaymentGroup) order.getPaymentGroups().get(0);
om.addRemainingOrderAmountToPaymentGroup(order, pg.getId());
// Compute the prices using pricing tools
pt.priceOrderTotal(order);
// checkout the Order and iterate through the result object displaying errors
PipelineResult pr = om.processOrder(order);
if (pr.hasErrors()) {
Object[] keys = pr.getErrorKeys();
for (int i = 0; i < keys.length; i++)
System.out.println(pr.getError(keys[i]));
}
SimpleOrderManager extends OrderManager. By default, a SimpleOrderManager object is configured in Nucleus at /atg/commerce/order/OrderManager. Logically, the SimpleOrderManager sits above the OrderManager and provides higher-level functionality. What takes several lines of code to do in the OrderManager takes only a single line of code in the SimpleOrderManager. You can use SimpleOrderManager in place of OrderManager to simplify your code, as the example below shows.
String skuId = getSkuId();
String productId = getProductId();
long quantity = getQuantity();
ShippingGroup shippingGroup = getShippingGroup();
getSimpleOrderManager().addItemToShippingGroup(order, skuId, productId, quantity,
shippingGroup);
This class is the business layer object for Order manipulation. Use of this class eliminates the need to know about Relationships and only requires basic knowledge of the commerce class hierarchy. Logically, this class is one level above the OrderManager class and attempts to do as much as possible for the user. The methods in the class allow CommerceItems to be added to or removed from an Order and ShippingGroup with a single call. It also allows movement of CommerceItems between ShippingGroups.
Below is an example of using the SimpleOrderManager.
OrderManager om = getOrderManager();
String profileId = "10000";
String catalogRefId1 = "sku-1";
String catalogRefId2 = "sku-2";
String productId1 = "product-1";
String productId2 = "product-2";
long quantity1 = 1;
long quantity2 = 2; // create the Order. The Order has a ShippingGroup and PaymentGroup in it when // constructed Order order = om.createOrder(profileId); // get the ShippingGroup and add the items to it ShippingGroup sg = (ShippingGroup) order.getShippingGroups().get(0);
item1 = om.addItemToShippingGroup(order, catalogRefId1, productId1, quantity1, sg.getId());
item2 = om.addItemToShippingGroup(order, catalogRefId2, productId2, quantity2, sg.getId()); // checkout the Order and iterate through the result object displaying errors
PipelineResult pr = om.processOrder(order);
if (pr.hasErrors()) {
Object[] keys = pr.getErrorKeys();
for (int i = 0; i < keys.length; i++)
System.out.println(pr.getError(keys[i]));
}
OrderManager om = getOrderManager();
CommerceItemManager cm = getCommerceItemManager();
PricingTools pt = getPricingTools();
String profileId = "10000";
String catalogRefId1 = "sku-1";
String catalogRefId2 = "sku-2";
String productId1 = "product-1";
String productId2 = "product-2";
long quantity1 = 1;
long quantity2 = 2;
// create the Order and CommerceItems. The Order has a ShippingGroup and PaymentGroup
// in it when constructed
Order order = om.createOrder(profileId);
CommerceItem item1 = om.createCommerceItem(catalogRefId1, productId1, quantity1);
CommerceItem item2 = om.createCommerceItem(catalogRefId2, productId2, quantity2);
// add the items to the Order, set the return value back to the object because if the
// item catalogRefId already existed in the Order, the quantity is incremented rather
// than adding the new object
item1 = cm.addItemToOrder(order, item1); // CommerceItemManager cm
item2 = cm.addItemToOrder(order, item2);
// get the ShippingGroup and add the items to it
ShippingGroup sg = (ShippingGroup) order.getShippingGroups().get(0);
om.addItemQuantityToShippingGroup(order, item1.getId(), sg.getId(), quantity1);
om.addRemainingItemQuantityToShippingGroup(order, item2.getId(),sg.getId());
// add the entire order amount to the PaymentGroup
PaymentGroup pg = (PaymentGroup) order.getPaymentGroups().get(0);
om.addRemainingOrderAmountToPaymentGroup(order, pg.getId());
// Compute the prices using pricing tools
pt.priceOrderTotal(order);
// checkout the Order and iterate through the result object displaying errors
PipelineResult pr = om.processOrder(order);
if (pr.hasErrors()) {
Object[] keys = pr.getErrorKeys();
for (int i = 0; i < keys.length; i++)
System.out.println(pr.getError(keys[i]));
}
SimpleOrderManager extends OrderManager. By default, a SimpleOrderManager object is configured in Nucleus at /atg/commerce/order/OrderManager. Logically, the SimpleOrderManager sits above the OrderManager and provides higher-level functionality. What takes several lines of code to do in the OrderManager takes only a single line of code in the SimpleOrderManager. You can use SimpleOrderManager in place of OrderManager to simplify your code, as the example below shows.
String skuId = getSkuId();
String productId = getProductId();
long quantity = getQuantity();
ShippingGroup shippingGroup = getShippingGroup();
getSimpleOrderManager().addItemToShippingGroup(order, skuId, productId, quantity,
shippingGroup);
This class is the business layer object for Order manipulation. Use of this class eliminates the need to know about Relationships and only requires basic knowledge of the commerce class hierarchy. Logically, this class is one level above the OrderManager class and attempts to do as much as possible for the user. The methods in the class allow CommerceItems to be added to or removed from an Order and ShippingGroup with a single call. It also allows movement of CommerceItems between ShippingGroups.
Below is an example of using the SimpleOrderManager.
OrderManager om = getOrderManager();
String profileId = "10000";
String catalogRefId1 = "sku-1";
String catalogRefId2 = "sku-2";
String productId1 = "product-1";
String productId2 = "product-2";
long quantity1 = 1;
long quantity2 = 2; // create the Order. The Order has a ShippingGroup and PaymentGroup in it when // constructed Order order = om.createOrder(profileId); // get the ShippingGroup and add the items to it ShippingGroup sg = (ShippingGroup) order.getShippingGroups().get(0);
item1 = om.addItemToShippingGroup(order, catalogRefId1, productId1, quantity1, sg.getId());
item2 = om.addItemToShippingGroup(order, catalogRefId2, productId2, quantity2, sg.getId()); // checkout the Order and iterate through the result object displaying errors
PipelineResult pr = om.processOrder(order);
if (pr.hasErrors()) {
Object[] keys = pr.getErrorKeys();
for (int i = 0; i < keys.length; i++)
System.out.println(pr.getError(keys[i]));
}
No comments:
Post a Comment