Пример #1
0
        /// <summary>
        /// Recalculates the total, subtotals, and shipping costs.
        /// </summary>
        public void ReCalculate()
        {
            // No need to calculate if nothing was changed
            if (!_isDirty)
            {
                return;
            }

            _subTotal = 0.0;
            _shipping = 0.0;

            foreach (ShoppingCartItem item in _items)
            {
                _subTotal += item.UnitPrice * item.Quantity;
                _shipping += _shippingStrategy.EstimateShipping(item.UnitPrice, item.Quantity);
            }

            // Add subtotal and shipping to get total
            _total = _subTotal + _shipping;

            _isDirty = false;
        }