Пример #1
0
        /// <summary>
        /// Updates the specified product stock.
        /// </summary>
        /// <param name="code">The code.</param>
        /// <param name="newAmount">The new amount.</param>
        /// <param name="args">The arguments.</param>
        public void Update(string code, long newAmount, ServiceClientArgs args)
        {
            ProductStockInfo stockInfo = new ProductStockInfo {
                ProductCode = code
            };

            SiteContext site = Utils.GetExistingSiteContext(args);

            using (new SiteContextSwitcher(site))
            {
                IProductStockManager stockManager = Context.Entity.Resolve <IProductStockManager>();

                stockManager.Update(stockInfo, newAmount);
            }
        }
Пример #2
0
        /// <summary>
        /// Processes the specified order.
        /// </summary>
        /// <typeparam name="T">The order type.</typeparam>
        /// <param name="order">The order instance.</param>
        protected override void Process <T>(T order)
        {
            if (order.OrderLines.IsNullOrEmpty())
            {
                return;
            }

            foreach (OrderLine indexOrderLine in order.OrderLines)
            {
                if (!(indexOrderLine.Product is Product))
                {
                    continue;
                }

                IProductStockManager stockManager = Context.Entity.Resolve <IProductStockManager>();
                ProductStockInfo     stockInfo    = new ProductStockInfo {
                    ProductCode = indexOrderLine.Product.Code
                };
                OrderLine line = indexOrderLine;

                stockManager.Update(stockInfo, s => s - line.Quantity);
            }
        }