Wednesday, November 13, 2013

Splitting Order Items for Partial Shipping




If you are depending on external system for updating shipped quantity and you had to split order items instead of orders based on the quantity shipped for that order item.

We had a scenario where our external system is SAP and WC (Websphere Commerce) has to act based on the information SAP is sending to WC. There can be Partial shipping, Partial Cancellation of and order item.

IBM WC 7 is not supporting partial shipping by default. So we have to handle this scenario explicitly.

When SAP send message stating quantity of order item shipped. We have to split the order items through code. Here is the approach for splitting the order item.

 void createPartialOrderItem(OrderItemAccessBean originalOI,String quantityShipped,Long orderId) throws ECException, RemoteException, CreateException, FinderException, NamingException {
            CSROrderItemAddCmd addCmd = (CSROrderItemAddCmd) CommandFactory.createCommand(CSROrderItemAddCmd.NAME, getStoreId());
           
              Hashtable hashtable4 = new Hashtable();
              hashtable4.put("orderId", orderId.toString());
              hashtable4.put("customerId", "-1000"); // Note only few users have authority to create order item, Here -1000 is admin id
              Hashtable hashtable3 = new Hashtable();
              hashtable3.put("order", hashtable4);
              Hashtable hashtable2= new Hashtable();
              Hashtable hashtable5= new Hashtable();
              hashtable5.put("catentryId", originalOI.getCatalogEntryId());
              hashtable5.put("quantity",quantity );
              hashtable5.put("partNumber",originalOI.getPartNumber());
              hashtable5.put("tradingId",originalOI.getContractId() );
              hashtable5.put("shipModeId", originalOI.getShippingModeId());
              hashtable5.put("shipAddrId", originalOI.getAddressId());
              Vector vector3= new Vector();
              vector3.add(hashtable5);
              hashtable3.put("orderItem", vector3);
              hashtable2.put("XML",hashtable3);
             
              CommandContext contexttemp21 = (CommandContext)getCommandContext().clone();
              contexttemp21.setStoreId(storeIDInteger);
              contexttemp21.setStore(getCommandContext().getStore(storeIDInteger));
              addCmd.setCommandContext(contexttemp21);
              Hashtable hassmap= new Hashtable();
              hassmap.put("xml_string",hashtable2);
             
              Vector vector2= new Vector();
              vector2.add(hashtable2);
             
              requestProperties.put("EC_XMLObject", vector2);
              addCmd.setDefaultProperties(requestProperties);
              addCmd.setRequestProperties(requestProperties);
              addCmd.execute();
        }

No comments:

Post a Comment