public static string GetFormatedPrice(object SKUPrice, object SKUDepartmentId, ShoppingCartInfo cart, object SKUId, bool FormatPrice)
    {
        double price = ValidationHelper.GetDouble(SKUPrice, 0);
        int departmentId = ValidationHelper.GetInteger(SKUDepartmentId, 0);
        int skuId = ValidationHelper.GetInteger(SKUId, 0);

        // When on the live site
        if (cart == null)
        {
            cart = ECommerceContext.CurrentShoppingCart;
        }

        if (departmentId > 0)
        {
            // Try site discount level
            DiscountLevelInfo discountLevel = cart.SiteDiscountLevel;
            bool valid = (discountLevel != null) && discountLevel.IsInDepartment(departmentId) && discountLevel.IsValid;

            if (!valid)
            {
                // Try global discount level
                discountLevel = cart.DiscountLevel;
                valid = (discountLevel != null) && discountLevel.IsInDepartment(departmentId) && discountLevel.IsValid;
            }

            // Apply discount to product price
            if (valid)
            {
                // Remember price before discount
                double oldPrice = price;

                // Get new price after discount
                price = price * (1 - discountLevel.DiscountLevelValue / 100);

                if ((oldPrice > 0) && (price < 0))
                {
                    price = 0;
                }
            }
        }

        int stateId = cart.StateID;
        int countryId = cart.CountryID;
        bool isTaxIDSupplied = ((cart.Customer != null) && (cart.Customer.CustomerTaxRegistrationID != ""));

        if ((skuId > 0) && ((stateId > 0) || (countryId > 0)))
        {
            // Apply taxes
            price += GetSKUTotalTax(price, skuId, stateId, countryId, isTaxIDSupplied);
        }

        // Apply exchange rate
        price = cart.ApplyExchangeRate(price);

        if (FormatPrice)
        {
            // Get formatted price
            return cart.GetFormattedPrice(price, true);
        }
        else
        {
            // Get not-formated price
            return price.ToString();
        }
    }
Пример #2
0
    public static string GetFormatedPrice(object SKUPrice, object SKUDepartmentId, ShoppingCartInfo cart, object SKUId, bool FormatPrice)
    {
        double price        = ValidationHelper.GetDouble(SKUPrice, 0);
        int    departmentId = ValidationHelper.GetInteger(SKUDepartmentId, 0);
        int    skuId        = ValidationHelper.GetInteger(SKUId, 0);

        // When on the live site
        if (cart == null)
        {
            cart = ECommerceContext.CurrentShoppingCart;
        }

        if (departmentId > 0)
        {
            // Try site discount level
            DiscountLevelInfo discountLevel = cart.SiteDiscountLevel;
            bool valid = (discountLevel != null) && discountLevel.IsInDepartment(departmentId) && discountLevel.IsValid;

            if (!valid)
            {
                // Try global discount level
                discountLevel = cart.DiscountLevel;
                valid         = (discountLevel != null) && discountLevel.IsInDepartment(departmentId) && discountLevel.IsValid;
            }

            // Apply discount to product price
            if (valid)
            {
                // Remember price before discount
                double oldPrice = price;

                // Get new price after discount
                price = price * (1 - discountLevel.DiscountLevelValue / 100);

                if ((oldPrice > 0) && (price < 0))
                {
                    price = 0;
                }
            }
        }

        int  stateId         = cart.StateID;
        int  countryId       = cart.CountryID;
        bool isTaxIDSupplied = ((cart.Customer != null) && (cart.Customer.CustomerTaxRegistrationID != ""));

        if ((skuId > 0) && ((stateId > 0) || (countryId > 0)))
        {
            // Apply taxes
            price += GetSKUTotalTax(price, skuId, stateId, countryId, isTaxIDSupplied);
        }

        // Apply exchange rate
        price = cart.ApplyExchangeRate(price);

        if (FormatPrice)
        {
            // Get formatted price
            return(cart.GetFormattedPrice(price, true));
        }
        else
        {
            // Get not-formated price
            return(price.ToString());
        }
    }