0

我正在尝试从批量加载创建 ATG 订单,价格信息对象未保存在数据库中。但是从应用程序中注销并再次登录它会创建对象并在表中显示正确的数据。在这里,我们创建一个商业项目,然后尝试使用所有详细信息更新订单。

下面是代码片段。

    vlogDebug("BulkOrderManager.createOrder() method - Start");
    NCROrderImpl ncrOrder = null;
    try {
        ncrOrder = (NCROrderImpl) getOrderManager().createOrder(profileId, CommerceConstants.NCRORDER);

        if (ncrOrder != null) {
            vlogDebug("Default order is created for user[" + getOrderBean().getUserId() + "] with order id : "
                    + ncrOrder.getId());
            Timestamp timestamp = new Timestamp(System.currentTimeMillis());
            Date date = new Date();
            date.setTime(timestamp.getTime());
            String formattedDate = new SimpleDateFormat(CommerceConstants.DATE_FORMAT_DD_MMM_YYYY_HH_MM_SS)
                    .format(date);
            String description = getOrderBean().getOrderName() + " " +"(" + formattedDate + ")";
            ncrOrder.setDescription(description);
            ncrOrder.setExplicitlySaved(true);
            ncrOrder.setSavedOrder(true);
            ncrOrder.setOrganizationId(getOrderBean().getMasterCutsomerNumber());
            ncrOrder.setLockedOrder(getOrderBean().isLockedOrder());
            if(StringUtils.isNotBlank(getOrderBean().getBillToAddressNumber()) && getOrderBean().isLockedOrder()){
                ncrOrder.setLockedOrderBillTo(Boolean.TRUE);
            }
            
            //save order into repository
            //getOrderManager().addOrder(ncrOrder);
            
            List<ProductDetails> productDetailBeans = getOrderBean().getProducts();
            String forUseAddressNumber = getOrderBean().getForUseAddressNumber();
        
            for (ProductDetails productDetailBean : productDetailBeans) {
                createCommerceItem(ncrOrder, productDetailBean, forUseAddressNumber);
                // addItemToShippingGroup(commerceItem, ncrOrder);
            }
            
            /** Removing the default shipping group from the order */
            ncrOrder.removeAllShippingGroups();
            createAndAssignShippingGroupToOrder(ncrOrder);
            
            
            /** Removing the default PaymentGroup from order*/
            ncrOrder.removeAllPaymentGroups();
            PaymentGroup payGroup = getOrderManager().getPaymentGroupManager().createPaymentGroup(CommerceConstants.INVOICE_REQUEST);
            getOrderManager().getPaymentGroupManager().addPaymentGroupToOrder(ncrOrder, payGroup);
            String billToAddr = getOrderBean().getBillToAddressNumber();
            if(StringUtils.isNotBlank(billToAddr)){
                vlogDebug("START : Adding Bill to Address : {0}", billToAddr);
                addAddressToPaymentGroup(billToAddr, ncrOrder);
                vlogDebug("DONE :  Adding Bill to Address : {0}", billToAddr);
            }
            List<NCRCommerceItem> ciList = (List<NCRCommerceItem>) ncrOrder.getCommerceItems();
            for (NCRCommerceItem ncrCommerceItem : ciList) {
                addItemToShippingGroup(ncrCommerceItem, ncrOrder);
            }
            
            String forUseSiteUseId = getBulkOrderTools().getSiteUseIdFromAddrNumber(getOrderBean().getForUseAddressNumber(), CommerceConstants.SITE_USE_CODE_DELIVER_TO,getOrderBean().getErrorMSG());
            String shipToSiteUseId = getBulkOrderTools().getSiteUseIdFromAddrNumber(getOrderBean().getShipToAddressNumber(), CommerceConstants.SITE_USE_CODE_SHIP_TO,getOrderBean().getErrorMSG());
            
            vlogDebug("ForUseAddressNumber is : {0}  and forUseSiteId is : {1}",getOrderBean().getForUseAddressNumber(),forUseSiteUseId);
            vlogDebug("ShipToAddressNumber is : {0}  and shipToSiteId is : {1}",getOrderBean().getShipToAddressNumber(),shipToSiteUseId);
            
            if(StringUtils.isNotBlank(forUseSiteUseId) && StringUtils.isNotBlank(shipToSiteUseId)){
                addAddressToShippingGroup(forUseSiteUseId,shipToSiteUseId,getOrderBean().getShippingInstructions(),ncrOrder);
            }else{
                getOrderBean().getErrorMSG().add("forUseSiteId or shipToSiteId is blank" + ":" +Thread.currentThread().getStackTrace()[1].
                          getLineNumber()+" in BulkOrderManager");
                vlogError("forUseSiteId or shipToSiteId is blank");
            }
            
            if(StringUtils.isNotBlank(getOrderBean().getPoNumber())){
                ncrOrder.setNonEditablePONumber(getOrderBean().getPoNumber());
                MutableRepositoryItem followUpItem = (MutableRepositoryItem) ncrOrder.getFollowupQuestion();
                boolean toCreateBean = false;
                if(null==followUpItem){
                    toCreateBean = true; 
                    followUpItem= getOrderRepository().createItem(CommerceConstants.FOLLOW_UP_QUESTION);
                }
                followUpItem.setPropertyValue("purchaseOrderNumber", getOrderBean().getPoNumber());
                if(toCreateBean){
                    getOrderRepository().addItem(followUpItem);
                }else{
                    getOrderRepository().updateItem(followUpItem);
                }               
                ncrOrder.setFollowupQuestion(followUpItem);
                //getOrderManager().updateOrder(ncrOrder);
            }
            
        } else {
            getOrderBean().getErrorMSG().add("Unable to create the order for user : " + getOrderBean().getUserId()+ ":" +Thread.currentThread().getStackTrace()[1].
                      getLineNumber()+" in BulkOrderManager");
            vlogError("Unable to create the order for user[{0}]", getOrderBean().getUserId());
        }
    } catch (CommerceException exc) {
        getOrderBean().getErrorMSG().add("CommerceException  : " + exc.getMessage()+ ":" +Thread.currentThread().getStackTrace()[1].
                  getLineNumber()+" in BulkOrderManager");
        vlogError("CommerceException : {0}" + exc);
    } catch (Exception e) {
        vlogError("CommerceException : {1}" + e);
    }
    vlogDebug("BulkOrderManager.createOrder() method - Stop");
    return ncrOrder;


    vlogDebug("Going to save the order[{0}] for user[{1}]", ncrOrder.getId(), getOrderBean().getUserId());
    try {
        //((NCROrderManager) getOrderManager()).repriceOrderTotal(ncrOrder);
        getOrderManager().updateOrder(ncrOrder);
        //getOrderManager().addOrder(ncrOrder);
        vlogDebug("Order[" + ncrOrder.getId() + "] is saved for user[" + getOrderBean().getUserId() + "]");

    } catch (Exception e) {
        getOrderBean().getErrorMSG().add("CommerceException Occured for order[" + ncrOrder.getId() + "]" + e + ":" +Thread.currentThread().getStackTrace()[1].
                  getLineNumber()+" in BulkOrderManager");
        vlogError("CommerceException : {0}", e);
    }
4

0 回答 0