コード例 #1
0
        public void CalculateShipping(string address, double addressLatitude, double addressLongitude, Guid shippingMethodId)
        {
            if (_items == null || _items.Count == 0)
            {
                throw new Exception("No item to calculate");
            }

            if (string.IsNullOrEmpty(address) || shippingMethodId == Guid.Empty)
            {
                throw new Exception("address and shipping method required");
            }

            if (_isPreCalculated == false)
            {
                PreCalculate();
            }

            var  id               = Guid.Parse(Id);
            long shippingFee      = ShippingMethodServices.ShippingCost(id, shippingMethodId, address, addressLatitude, addressLongitude);
            var  orderPromotionId = Guid.Empty;
            var  orderPromo       = OrderPromotionServices.CalculateForShipping(id);

            if (orderPromo != null)
            {
                if (orderPromo.FreeShip)
                {
                    shippingFee = 0;
                }
                orderPromotionId = orderPromo.Id;
            }

            ApplyChange(new ShoppingCartPromotionCalulatedForOrderShipping(id, orderPromotionId));

            ApplyChange(new ShoppingCartCalculatedShipping(id, shippingMethodId, shippingFee));
        }
コード例 #2
0
        private static void PreCalculateShoppingCart(Guid shoppingCartId, Guid productId, int productQuantity)
        {
            var hubContext = GlobalHost.ConnectionManager.GetHubContext <SystemNotificationHub>();
            var msg        = string.Empty;

            var pp         = ProductPromotionServices.CalculateDiscount(productId, productQuantity);
            var ooDiscount = OrderPromotionServices.CalculateForDiscount(shoppingCartId);
            var ooShipping = OrderPromotionServices.CalculateForShipping(shoppingCartId);

            using (var db = new CoreEcommerceDbContext())
            {
                if (pp != null)
                {
                    msg += db.ContentLanguages.GetValue(pp.Id, "Description");
                }
                if (ooDiscount != null)
                {
                    msg += "<br>" + db.ContentLanguages.GetValue(ooDiscount.Id, "Description");
                }
                if (ooShipping != null)
                {
                    msg += "<br>" + db.ContentLanguages.GetValue(ooShipping.Id, "Description");
                }
            }

            if (!string.IsNullOrEmpty(msg))
            {
                hubContext.Clients.All.shoppingCartMessage(new NotificationMessage()
                {
                    DataType = "ShoppingCart",
                    DataJson = JsonConvert.SerializeObject(new
                    {
                        Id         = shoppingCartId,
                        ProductId  = productId,
                        ActionType = "PreCalculateShoppingCart",
                        Message    = msg
                    })
                });
            }

            hubContext.Clients.All.shoppingCartMessage(new NotificationMessage()
            {
                DataType = "ShoppingCart",
                DataJson = JsonConvert.SerializeObject(new
                {
                    Id         = shoppingCartId,
                    ActionType = "RefreshShoppingCart",
                    Message    = msg
                })
            });
        }