Beispiel #1
0
        private void PushFulfillmentToShopify(string shipmentNbr)
        {
            // Get a fresh copy
            //
            var salesOrderShipment = _syncOrderRepository.RetrieveSoShipment(shipmentNbr);

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

            var fulfillmentParent = ShopifyOrderRecord(salesOrderShipment);

            // Write Execution Log entry
            //
            var content = LogBuilder.CreateShopifyFulfillment(salesOrderShipment);

            _logService.Log(content);

            // First, create the Sync Record
            //
            var orderRecord       = salesOrderShipment.AcumaticaSalesOrder.ShopifyOrder;
            var fulfillmentRecord = new ShopifyFulfillment();

            fulfillmentRecord.ShopifyOrderMonsterId = orderRecord.MonsterId;
            fulfillmentRecord.ShopifyOrderId        = orderRecord.ShopifyOrderId;
            fulfillmentRecord.DateCreated           = DateTime.UtcNow;
            fulfillmentRecord.LastUpdated           = DateTime.UtcNow;

            // ... and assign Shipment thereto
            //
            salesOrderShipment.ShopifyFulfillment = fulfillmentRecord;
            salesOrderShipment.LastUpdated        = DateTime.UtcNow;
            _shopifyOrderRepository.InsertFulfillment(fulfillmentRecord);

            // Write the Fulfillment to the Shopify API
            //
            var resultJson = _fulfillmentApi.Insert(orderRecord.ShopifyOrderId, fulfillmentParent.SerializeToJson());

            var resultParent = resultJson.DeserializeFromJson <FulfillmentParent>();

            // Ingest and save the result
            //
            fulfillmentRecord.Ingest(resultParent.fulfillment);
            fulfillmentRecord.LastUpdated = DateTime.UtcNow;
            _shopifyOrderRepository.SaveChanges();
        }
Beispiel #2
0
        private void UpsertOrderFulfillment(ShopifyOrder orderRecord, Fulfillment fulfillment)
        {
            var fulfillmentRecord
                = orderRecord
                  .ShopifyFulfillments
                  .FirstOrDefault(x => x.ShopifyFulfillmentId == fulfillment.id);

            if (fulfillmentRecord != null)
            {
                // Existing Fulfillment Record
                //
                fulfillmentRecord.ShopifyStatus = fulfillment.status;
                fulfillmentRecord.LastUpdated   = DateTime.UtcNow;

                _orderRepository.SaveChanges();
                return;
            }

            var matchedRecord
                = orderRecord
                  .ShopifyFulfillments
                  .FirstOrDefault(x => x.ShopifyTrackingNumber == fulfillment.tracking_number);

            if (matchedRecord != null)
            {
                // Matched via Tracking Number in Shopify
                //
                _executionLogService.Log(
                    LogBuilder.FillingUnknownShopifyFulfillmentRefByTracking(matchedRecord));

                matchedRecord.ShopifyFulfillmentId = fulfillment.id;
                matchedRecord.LastUpdated          = DateTime.UtcNow;
                _orderRepository.SaveChanges();
            }
            else
            {
                // Creating new Fulfillment Record
                //
                var newRecord = new ShopifyFulfillment();
                newRecord.ShopifyOrderMonsterId = orderRecord.MonsterId;
                newRecord.ShopifyFulfillmentId  = fulfillment.id;
                newRecord.ShopifyOrderId        = orderRecord.ShopifyOrderId;
                newRecord.ShopifyStatus         = fulfillment.status;
                newRecord.DateCreated           = DateTime.UtcNow;
                newRecord.LastUpdated           = DateTime.UtcNow;

                _orderRepository.InsertFulfillment(newRecord);
            }
        }