Example #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));
        }