Esempio n. 1
0
        // Warehouses & Locations
        //
        public void InsertInventoryReceiptSync(ShopifyInventoryLevel level, AcumaticaInventoryReceipt receipt)
        {
            var sync = new InventoryReceiptSync();

            sync.ShopifyInventoryLevel     = level;
            sync.AcumaticaInventoryReceipt = receipt;
            sync.DateCreated = DateTime.Now;
            sync.LastUpdated = DateTime.Now;
            Entities.InventoryReceiptSyncs.Add(sync);
            Entities.SaveChanges();
        }
        private void UpdateInventoryLevel(AcumaticaStockItem stockItem, ShopifyInventoryLevel level)
        {
            var location         = _syncInventoryRepository.RetrieveLocation(level.ShopifyLocationId);
            var warehouseIds     = location.MatchedWarehouseIds();
            var warehouseDetails = stockItem.Inventory(warehouseIds);

            var available = (int)warehouseDetails.Sum(x => x.AcumaticaAvailQty);
            var sku       = level.ShopifyVariant.ShopifySku;

            var levelDto = new InventoryLevel
            {
                inventory_item_id = level.ShopifyInventoryItemId,
                available         = available,
                location_id       = location.ShopifyLocationId,
            };

            var levelJson = levelDto.SerializeToJson();

            _inventoryApi.SetInventoryLevels(levelJson);


            using (var transaction = _syncInventoryRepository.BeginTransaction())
            {
                var log = $"Updated Shopify Variant {sku} " +
                          $"in Location {location.ShopifyLocationName} to Available Qty {available}";

                _executionLogService.Log(log);

                warehouseDetails.ForEach(x => x.IsInventorySynced = true);

                // Update Shopify Inventory Level records
                //
                level.ShopifyAvailableQuantity = available;
                level.LastUpdated = DateTime.UtcNow;

                _inventoryRepository.SaveChanges();
                transaction.Commit();
            }
        }
Esempio n. 3
0
        public void UpsertInventory(
            ShopifyVariant variant,
            InventoryItem shopifyItem,
            List <InventoryLevel> shopifyLevels)
        {
            var existingLevels =
                _inventoryRepository.RetrieveInventory(variant.ShopifyInventoryItemId);

            var locations = _inventoryRepository.RetreiveLocations();

            foreach (var shopifyLevel in shopifyLevels)
            {
                var existingLevel =
                    existingLevels.FirstOrDefault(x => x.ShopifyLocationId == shopifyLevel.location_id);

                var location = locations.First(x => x.ShopifyLocationId == shopifyLevel.location_id);

                if (existingLevel == null)
                {
                    var newLevel = new ShopifyInventoryLevel();
                    newLevel.ParentMonsterId          = variant.MonsterId;
                    newLevel.ShopifyInventoryItemId   = shopifyLevel.inventory_item_id;
                    newLevel.ShopifyLocationId        = shopifyLevel.location_id;
                    newLevel.ShopifyAvailableQuantity = shopifyLevel.available ?? 0;
                    newLevel.LocationMonsterId        = location.MonsterId;
                    newLevel.DateCreated = DateTime.UtcNow;
                    newLevel.LastUpdated = DateTime.UtcNow;

                    _inventoryRepository.InsertInventory(newLevel);
                }
                else
                {
                    existingLevel.ShopifyAvailableQuantity = shopifyLevel.available ?? 0;
                    existingLevel.LastUpdated = DateTime.UtcNow;

                    _inventoryRepository.SaveChanges();
                }
            }
        }
 public void InsertInventory(ShopifyInventoryLevel inventory)
 {
     Entities.ShopifyInventoryLevels.Add(inventory);
     Entities.SaveChanges();
 }