예제 #1
0
        private void CorrectFulfillmentWithUnknownRef(string shipmentNbr)
        {
            var salesOrderShipment = _syncOrderRepository.RetrieveSoShipment(shipmentNbr);

            if (!salesOrderShipment.HasSyncWithUnknownNbr())
            {
                return;
            }

            var fulfillmentRecord = salesOrderShipment.ShopifyFulfillment;

            var shopifyOrder =
                _shopifyJsonService.RetrieveOrder(
                    salesOrderShipment.AcumaticaSalesOrder.ShopifyOrder.ShopifyOrderId);

            var matches =
                shopifyOrder
                .fulfillments
                .Where(x => x.tracking_number == salesOrderShipment.AcumaticaTrackingNbr)
                .ToList();

            if (!matches.Any())
            {
                var content = LogBuilder.ShopifyFulfillmentWithUnknownRefNoMatches(salesOrderShipment);
                _logService.Log(content);
                _syncOrderRepository.SetErrorCountToMaximum(shopifyOrder.id);
                return;
            }

            if (matches.Count() > 1)
            {
                var content = LogBuilder.ShopifyFulfillmentWithUnknownRefTooManyMatches(salesOrderShipment);
                _logService.Log(content);
                _syncOrderRepository.SetErrorCountToMaximum(shopifyOrder.id);
                return;
            }

            fulfillmentRecord.Ingest(matches.First());
            fulfillmentRecord.DateCreated = DateTime.UtcNow;
            fulfillmentRecord.LastUpdated = DateTime.UtcNow;

            _logService.Log(LogBuilder.FillingUnknownShopifyFulfillmentRef(salesOrderShipment, fulfillmentRecord));
            _shopifyOrderRepository.SaveChanges();
        }