예제 #1
0
        public async Task <ProductDto> Handle(UpdateProductCommand request, CancellationToken cancellationToken)
        {
            //product
            var product = await _productService.GetProductById(request.Model.Id);

            var prevStockQuantity = product.StockQuantity;

            product = request.Model.ToEntity(product);
            product.UpdatedOnUtc = DateTime.UtcNow;
            request.Model.SeName = await product.ValidateSeName(request.Model.SeName, product.Name, true, _seoSettings, _urlRecordService, _languageService);

            product.SeName = request.Model.SeName;
            //search engine name
            await _urlRecordService.SaveSlug(product, request.Model.SeName, "");

            //update product
            await _productService.UpdateProduct(product);

            if (product.ManageInventoryMethod == ManageInventoryMethod.ManageStock &&
                product.BackorderMode == BackorderMode.NoBackorders &&
                product.AllowBackInStockSubscriptions &&
                product.GetTotalStockQuantity() > 0 &&
                prevStockQuantity <= 0 && !product.UseMultipleWarehouses &&
                product.Published)
            {
                await _backInStockSubscriptionService.SendNotificationsToSubscribers(product, "");
            }

            //activity log
            await _customerActivityService.InsertActivity("EditProduct", product.Id, _localizationService.GetResource("ActivityLog.EditProduct"), product.Name);

            return(product.ToModel());
        }
예제 #2
0
 protected async Task BackInStockNotifications(Product product, int prevStockQuantity, List <ProductWarehouseInventory> prevMultiWarehouseStock)
 {
     if (product.ManageInventoryMethod == ManageInventoryMethod.ManageStock &&
         product.BackorderMode == BackorderMode.NoBackorders &&
         product.AllowBackInStockSubscriptions &&
         product.GetTotalStockQuantity() > 0 &&
         prevStockQuantity <= 0 && !product.UseMultipleWarehouses &&
         product.Published)
     {
         await _backInStockSubscriptionService.SendNotificationsToSubscribers(product, "");
     }
     if (product.ManageInventoryMethod == ManageInventoryMethod.ManageStock &&
         product.BackorderMode == BackorderMode.NoBackorders &&
         product.AllowBackInStockSubscriptions &&
         product.UseMultipleWarehouses &&
         product.Published)
     {
         foreach (var prevstock in prevMultiWarehouseStock)
         {
             if (prevstock.StockQuantity - prevstock.ReservedQuantity <= 0)
             {
                 var actualStock = product.ProductWarehouseInventory.FirstOrDefault(x => x.WarehouseId == prevstock.WarehouseId);
                 if (actualStock != null)
                 {
                     if (actualStock.StockQuantity - actualStock.ReservedQuantity > 0)
                     {
                         await _backInStockSubscriptionService.SendNotificationsToSubscribers(product, prevstock.WarehouseId);
                     }
                 }
             }
         }
         if (product.ProductWarehouseInventory.Sum(x => x.StockQuantity - x.ReservedQuantity) > 0)
         {
             if (prevMultiWarehouseStock.Sum(x => x.StockQuantity - x.ReservedQuantity) <= 0)
             {
                 await _backInStockSubscriptionService.SendNotificationsToSubscribers(product, "");
             }
         }
     }
 }