Ejemplo n.º 1
0
    /// <summary>
    /// Setups the control.
    /// </summary>
    public void SetupControl()
    {
        string type = ValidationHelper.GetString(GetValue("TotalToDisplay"), "TotalPriceOfProducts");

        // Display the correct value according to the TotalToDisplay property of the web part
        switch (type)
        {
        case "TotalPriceOfOrder":
        {
            var value = ShoppingCart.GrandTotal;
            DisplayValue(GetFormattedPriceToDisplay(value));
            break;
        }

        case "TotalPriceOfProducts":
        {
            var value = ShoppingCart.TotalItemsPrice;
            DisplayValue(GetFormattedPriceToDisplay(value));
            break;
        }

        case "TotalShipping":
        {
            var value = (ShoppingCart.ShippingOption != null) ? ShoppingCart.TotalShipping : 0;
            DisplayValue(GetFormattedPriceToDisplay(value));
            break;
        }

        case "TotalWeight":
        {
            var value        = ShoppingCart.TotalItemsWeight;
            var stringFormat = GetStringFormat();
            DisplayValue(stringFormat == "" ? ShippingOptionInfoProvider.GetFormattedWeight(value, CurrentSiteName) : String.Format(stringFormat, value));
            break;
        }

        case "TotalOrderTax":
        {
            var value = ShoppingCart.TotalTax;
            DisplayValue(GetFormattedPriceToDisplay(value));
            break;
        }

        case "TotalOrderDiscount":
        {
            var value = ShoppingCart.OrderDiscount;
            DisplayValue(GetFormattedPriceToDisplay(value));
            break;
        }

        case "OtherPaymentsTotal":
        {
            var value = ShoppingCart.OtherPayments;
            DisplayValue(GetFormattedPriceToDisplay(value));
            break;
        }
        }
    }
    /// <summary>
    /// Setups the control.
    /// </summary>
    public void SetupControl()
    {
        double value        = 0;
        string stringFormat = ValidationHelper.GetString(GetValue("StringFormat"), "");

        // Try to use the stringFormat format, to check, if it's a valid one
        try
        {
            String.Format(stringFormat, value);
        }
        catch (Exception ex)
        {
            CMS.EventLog.EventLogProvider.LogException("Checkout process", "ERROR", ex, CurrentSite.SiteID, "The StringFormat property of the web part isn't in a correct format: '" + stringFormat + "'");
            // Recovery
            stringFormat = "";
        }

        string type = ValidationHelper.GetString(GetValue("TotalToDisplay"), "TotalPriceOfProducts");

        // Display the correct value according to the TotalToDisplay property of the web part
        switch (type)
        {
        case "TotalPriceOfOrder":
            value = ShoppingCart.TotalPrice;
            DisplayValue(GetFormattedPriceToDisplay(value, stringFormat));
            break;

        case "TotalPriceOfProducts":
            value = ShoppingCart.TotalItemsPrice;
            DisplayValue(GetFormattedPriceToDisplay(value, stringFormat));
            break;

        case "TotalPriceOfProductsWithoutTax":
            value = ShoppingCart.TotalItemsPrice - ShoppingCart.TotalItemsTax;
            DisplayValue(GetFormattedPriceToDisplay(value, stringFormat));
            break;

        case "TotalShippingWithoutTax":
            if (ShoppingCart.ShippingOption != null)
            {
                value = ShoppingCart.ApplyExchangeRate(ShippingOptionInfoProvider.CalculateShipping(ShoppingCart));
            }

            DisplayValue(GetFormattedPriceToDisplay(value, stringFormat));
            break;

        case "TotalShipping":
            if (ShoppingCart.ShippingOption != null)
            {
                value = ShoppingCart.TotalShipping;
            }

            DisplayValue(GetFormattedPriceToDisplay(value, stringFormat));
            break;

        case "TotalWeight":
            value = ShoppingCart.TotalItemsWeight;
            DisplayValue(stringFormat == "" ? ShippingOptionInfoProvider.GetFormattedWeight(value, CurrentSiteName) : String.Format(stringFormat, value));
            break;

        case "TotalProductTax":
            value = ShoppingCart.TotalTax;
            DisplayValue(GetFormattedPriceToDisplay(value, stringFormat));
            break;

        case "TotalOrderTax":
            value = ShoppingCart.TotalTax;

            if (ShoppingCart.ShippingOption != null)
            {
                value += ShoppingCart.ApplyExchangeRate(ShippingOptionInfoProvider.CalculateShippingTax(ShoppingCart));
            }

            DisplayValue(GetFormattedPriceToDisplay(value, stringFormat));
            break;

        case "TotalShippingTax":
            if (!DataHelper.DataSourceIsEmpty(ShoppingCart.ShippingTaxesTable))
            {
                value = ValidationHelper.GetDoubleSystem(ShoppingCart.ShippingTaxesTable.Rows[0]["TaxSummary"], 0);
            }

            DisplayValue(GetFormattedPriceToDisplay(value, stringFormat));
            break;

        case "TotalDiscount":
            value = ShoppingCart.OrderDiscount + ShoppingCart.ItemsDiscount + ShoppingCart.ShippingDiscount;
            DisplayValue(GetFormattedPriceToDisplay(value, stringFormat));
            break;

        case "TotalOrderDiscount":
            value = ShoppingCart.OrderDiscount;
            DisplayValue(GetFormattedPriceToDisplay(value, stringFormat));
            break;

        case "OrderDiscountSummary":
            DisplayOrderDiscountSummary();
            break;
        }
    }