Example #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();
        }
Example #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);
            }
        }
        /// <summary>
        /// Generates a valid <see cref="ShopifyFulfillment"/> for testing the Fulfillment API.
        /// </summary>
        public static ShopifyFulfillment GenerateFulfillment(bool multipleTrackingNumbers = false, IEnumerable <ShopifyLineItem> items = null)
        {
            ShopifyFulfillment fulfillment;

            if (multipleTrackingNumbers)
            {
                fulfillment = new ShopifyFulfillment()
                {
                    TrackingCompany = "Jack Black's Pack, Stack and Track",
                    TrackingUrls    = new string[]
                    {
                        "https://example.com/da10038ee679f9afc93a785cafdd8d52",
                        "https://example.com/6349a40313ae3c7544331ff9fb44f28c",
                        "https://example.com/ca0b2d7bcccec4b58a94a24fa04101d3"
                    },
                    TrackingNumbers = new string[]
                    {
                        "da10038ee679f9afc93a785cafdd8d52",
                        "6349a40313ae3c7544331ff9fb44f28c",
                        "ca0b2d7bcccec4b58a94a24fa04101d3"
                    }
                };
            }
            else
            {
                fulfillment = new ShopifyFulfillment()
                {
                    TrackingCompany = "Jack Black's Pack, Stack and Track",
                    TrackingUrl     = "https://example.com/123456789",
                    TrackingNumber  = "123456789",
                };
            }

            if (items != null)
            {
                fulfillment.LineItems = items;
            }

            return(fulfillment);
        }
        /// <summary>
        /// Generates a valid <see cref="ShopifyFulfillment"/> for testing the Fulfillment API.
        /// </summary>
        public static ShopifyFulfillment GenerateFulfillment(bool multipleTrackingNumbers = false, IEnumerable<ShopifyLineItem> items = null)
        {
            ShopifyFulfillment fulfillment;

            if (multipleTrackingNumbers)
            {
                fulfillment = new ShopifyFulfillment()
                {
                    TrackingCompany = "Jack Black's Pack, Stack and Track",
                    TrackingUrls = new string[] 
                    {
                        "https://example.com/da10038ee679f9afc93a785cafdd8d52",
                        "https://example.com/6349a40313ae3c7544331ff9fb44f28c",
                        "https://example.com/ca0b2d7bcccec4b58a94a24fa04101d3"
                    },
                    TrackingNumbers = new string[] 
                    {
                        "da10038ee679f9afc93a785cafdd8d52",
                        "6349a40313ae3c7544331ff9fb44f28c",
                        "ca0b2d7bcccec4b58a94a24fa04101d3"
                    }
                };
            }
            else
            {
                fulfillment = new ShopifyFulfillment()
                {
                    TrackingCompany = "Jack Black's Pack, Stack and Track",
                    TrackingUrl = "https://example.com/123456789",
                    TrackingNumber = "123456789",
                };
            }

            if (items != null)
            {
                fulfillment.LineItems = items;
            }

            return fulfillment;
        }
Example #5
0
 public static string LogDescriptor(this ShopifyFulfillment shopifyFulfillment)
 {
     return($"Shopify Fulfillment {shopifyFulfillment.ShopifyFulfillmentId}");
 }
Example #6
0
 public static string FillingUnknownShopifyFulfillmentRefByTracking(ShopifyFulfillment fulfillment)
 {
     return($"Filling unknown Shopify Fulfillment reference for {fulfillment.LogDescriptor()} " +
            $"(by tracking number {fulfillment.ShopifyTrackingNumber})");
 }
Example #7
0
 public static string FillingUnknownShopifyFulfillmentRef(
     AcumaticaSoShipment shipmentRef, ShopifyFulfillment fulfillment)
 {
     return($"Filling unknown Shopify Fulfillment reference from {shipmentRef.LogDescriptor()} with {fulfillment.LogDescriptor()}");
 }
Example #8
0
 public void InsertFulfillment(ShopifyFulfillment fulfillment)
 {
     Entities.ShopifyFulfillments.Add(fulfillment);
     Entities.SaveChanges();
 }
Example #9
0
 /// <summary>
 /// Updates the specified fulfillment.
 /// </summary>
 /// <param name="fulfillment">The fulfillment.</param>
 /// <param name="orderID">The order identifier.</param>
 /// <returns></returns>
 public ShopifyFulfillment Update(ShopifyFulfillment fulfillment, long orderID)
 {
     return(base.Update(fulfillment, fulfillment.Id, $"/admin/orders/{orderID}/fulfillments/{fulfillment.Id}.json"));
 }
Example #10
0
 /// <summary>
 /// Creates the specified fulfillment.
 /// </summary>
 /// <param name="fulfillment">The fulfillment.</param>
 /// <param name="orderID">The order identifier.</param>
 /// <returns></returns>
 public ShopifyFulfillment Create(ShopifyFulfillment fulfillment, long orderID)
 {
     return(base.Create(fulfillment, $"/admin/orders/{orderID}/fulfillments.json"));
 }
 public static void Ingest(this ShopifyFulfillment record, Fulfillment fulfillment)
 {
     record.ShopifyFulfillmentId  = fulfillment.id;
     record.ShopifyTrackingNumber = fulfillment.tracking_number;
     record.ShopifyStatus         = fulfillment.status;
 }