コード例 #1
0
        public void RetrieveChannelAdvisorIds(KCStore store)
        {
            KCDataExchangeMaint      graph      = PXGraph.CreateInstance <KCDataExchangeMaint>();
            KCSiteMaster             connection = graph.Connection.Select().RowCast <KCSiteMaster>().First(x => x.SiteMasterCD.Equals(store.SiteMasterCD));
            KCARestClient            client     = new KCARestClient(connection);
            KCInventoryItemAPIHelper helper     = new KCInventoryItemAPIHelper(client);

            foreach (KCAPIIdSkuJuxtaposion juxtaposion in helper.GetAllIdSkuJuxtaposions())
            {
                InventoryItem item = graph.ItemByCd.SelectSingle(juxtaposion.Sku);
                if (item == null)
                {
                    continue;
                }
                KNSIKCInventoryItem cItem = graph.KCInventoryItem.SelectSingle(item.InventoryID);
                if (cItem != null && cItem.UsrKCActiveOnCa.GetValueOrDefault())
                {
                    cItem.UsrKCCAID       = juxtaposion.ID;
                    cItem.UsrKCCAParentID = juxtaposion.ParentProductID.ToString();
                    graph.KCInventoryItem.Update(cItem);
                }
            }

            graph.Actions.PressSave();

            if (logger != null)
            {
                logger.ClearLoggingIds();
                logger.Information(KCMessages.ProductIdsRetrievalSuccess);
            }
        }
コード例 #2
0
        private static void Process(IList <KCStore> stores)
        {
            LoggerProperties.RequestId = GetRequestId();
            logger = new KCLoggerProvider(LoggerProperties);

            int index = 0;

            foreach (KCStore store in stores)
            {
                try
                {
                    ProcessStore(store);
                    PXProcessing <KCStore> .SetInfo(index, $"Data Exchange for {store.SiteMasterCD} has been processed successfully");
                }
                catch (Exception exception)
                {
                    string log = KCMessages.ProcessException(store.SiteMasterCD, exception.Message, exception.StackTrace);
                    logger.ClearLoggingIds();
                    logger.Error(log);
                    PXProcessing <KCStore> .SetError(index, new Exception(log));
                }
                index++;
            }
        }
コード例 #3
0
        public void ExportShipments(KCStore store)
        {
            if (store.DateTo < store.DateFrom)
            {
                throw new PXException(KCMessages.DateToBiggerThanDateFrom);
            }
            if (store.DateTo.GetValueOrDefault() != default)
            {
                store.DateTo = store.DateTo.GetValueOrDefault().AddDays(1);
            }
            bool anyExported             = false;
            KCDataExchangeMaint    graph = PXGraph.CreateInstance <KCDataExchangeMaint>();
            SOOrderShipmentProcess orderShipmentGraph = PXGraph.CreateInstance <SOOrderShipmentProcess>();

            KCSiteMaster        connection     = graph.Connection.Select().RowCast <KCSiteMaster>().Where(x => x.SiteMasterCD.Equals(store.SiteMasterCD)).First();
            KCARestClient       client         = new KCARestClient(connection);
            KCOrderAPIHelper    helperOrder    = new KCOrderAPIHelper(client);
            KCShipmentAPIHelper helperShipment = new KCShipmentAPIHelper(client);

            List <SOOrder> orders = graph.Orders.Select().RowCast <SOOrder>().Where(x =>
                                                                                    x.GetExtension <KCSOOrderExt>().UsrKCSiteName?.EndsWith("/Non-FBA") == true).ToList();

            foreach (SOOrder order in orders)
            {
                IEnumerable <SOOrderShipment> orderShipments = KCGeneralDataHelper.GetOrderShipmentsByOrderNbr(graph, order.OrderNbr);
                if (orderShipments == null)
                {
                    continue;
                }

                foreach (SOOrderShipment orderShipment in orderShipments)
                {
                    if (!CheckData(orderShipment, store.DateFrom, store.DateTo))
                    {
                        continue;
                    }
                    PXResultset <SOLine> lines    = graph.OrderLines.Select(orderShipment.ShipmentNbr);
                    SOShipment           shipment = KCGeneralDataHelper.GetShipmentByShipmentNbr(orderShipmentGraph, orderShipment.ShipmentNbr);
                    if (!CheckShippingCarrier(helperShipment, shipment))
                    {
                        logger.Information(KCMessages.ShipViaDoesnotExist(shipment.ShipmentNbr));
                        continue;
                    }
                    KCSOShipmentExt shipmentKCExt  = shipment?.GetExtension <KCSOShipmentExt>();
                    SOPackageDetail package        = KCGeneralDataHelper.GetPackageByShipmentNbr(orderShipmentGraph, orderShipment.ShipmentNbr);
                    KCSOOrderExt    orderExt       = order.GetExtension <KCSOOrderExt>();
                    KCMapShipment   shipmentMapper = new KCMapShipment();

                    int?customerOrderNbr = Convert.ToInt32(order.CustomerOrderNbr);

                    if (shipment != null && orderShipment.Confirmed.GetValueOrDefault() &&
                        KCGeneralDataHelper.GetExistingCAOrderById(helperOrder, customerOrderNbr) != null && shipmentKCExt?.UsrKCExported != true)

                    {
                        string          log;
                        KCErrorResponse response = new KCErrorResponse();
                        logger.SetParentAndEntityIds(order.OrderNbr, shipment.ShipmentNbr);

                        try
                        {
                            response = helperShipment.MarkTheOrderAsShipped(shipmentMapper.GetAPIShipment(shipment, package, lines), customerOrderNbr);
                        }
                        catch (Exception ex)
                        {
                            log = KCMessages.CorruptedShipment(shipment.ShipmentNbr);
                            logger.Information(log);
                            continue;
                        }


                        if (response != null)
                        {
                            log = KCMessages.ShipmentExportFailure(shipment.ShipmentNbr, response.Error.Message);
                        }
                        else
                        {
                            shipmentKCExt.UsrKCExported = true;
                            orderShipmentGraph.Shipments.Update(shipment);
                            orderShipmentGraph.Save.Press();
                            anyExported = true;
                            log         = KCMessages.ShipmentExported(shipment.ShipmentNbr);
                        }

                        logger.Information(log);
                    }
                }
            }

            logger.ClearLoggingIds();
            logger.Information(anyExported ? KCMessages.ShipmentExportSuccess : KCMessages.NoShipmentsToExport);
        }