C#/VB.NET Code:
public virtual string GetVariantPriceAUD(String sVariantID, String sHidePriceUntilCart, string sPrice, string sSalePrice, string sExtPrice, String sPoints, string sSalesPromptName)
{
return GetVariantPriceAUD(sVariantID, sHidePriceUntilCart, sPrice, sSalePrice, sExtPrice, sPoints, sSalesPromptName, "True", "1", "0.00");
}
public virtual string GetVariantPriceAUD(String sVariantID, String sHidePriceUntilCart, string sPrice, string sSalePrice, string sExtPrice, String sPoints, string sSalesPromptName, string sTaxClassID)
{
return GetVariantPriceAUD(sVariantID, sHidePriceUntilCart, sPrice, sSalePrice, sExtPrice, sPoints, sSalesPromptName, "True", sTaxClassID, "0.00");
}
public virtual string GetVariantPriceAUD(String sVariantID, String sHidePriceUntilCart, string sPrice, string sSalePrice, string sExtPrice, String sPoints, string sSalesPromptName, String sShowpricelabel, string sTaxClassID)
{
return GetVariantPriceAUD(sVariantID, sHidePriceUntilCart, sPrice, sSalePrice, sExtPrice, sPoints, sSalesPromptName, sShowpricelabel, sTaxClassID, "0.00");
}
public virtual string GetVariantPriceAUD(String sVariantID, String sHidePriceUntilCart, string sPrice, string sSalePrice, string sExtPrice, String sPoints, string sSalesPromptName, String sShowpricelabel, string sTaxClassID, String sChosenAttributesPriceDelta)
{
// validate paramters
InputValidator IV = new InputValidator("GetVariantPriceAUD");
int variantID = IV.ValidateInt("VariantID", sVariantID);
bool hidePriceUntilCart = IV.ValidateBool("HidePriceUntilCart", sHidePriceUntilCart);
decimal regularPrice = IV.ValidateDecimal("Price", sPrice);
decimal salePrice = IV.ValidateDecimal("SalePrice", sSalePrice);
decimal extPrice = IV.ValidateDecimal("ExtPrice", sExtPrice);
int points = IV.ValidateInt("Points", sPoints);
string salesPromptName = IV.ValidateString("SalesPromptName", sSalesPromptName);
bool showPriceLabel = IV.ValidateBool("Showpricelabel", sShowpricelabel);
int taxClassID = IV.ValidateInt("TaxClassID", sTaxClassID);
decimal attributesPriceDelta = IV.ValidateDecimal("AttributesPriceDelta", sChosenAttributesPriceDelta);
// instantiate return variable
StringBuilder results = new StringBuilder(1024);
// short-circuit this procedure if the price will be hidden
if (hidePriceUntilCart)
{
return string.Empty;
}
// round it by 2
regularPrice = decimal.Round(regularPrice, 2, MidpointRounding.AwayFromZero);
// calculate customerLevel price (in default currency, with no inclusive taxes added yet)
decimal customerLevelMultiplier = 1 - ThisCustomer.LevelDiscountPct / 100;
decimal customerLevelPrice = regularPrice * customerLevelMultiplier; // defaults to regular price with applied discount
if (extPrice != 0) // if extended pricing is defined (non-zero), use it instead
{
if (ThisCustomer.DiscountExtendedPrices) // do customerLevel discounts apply to extended pricing?
{
customerLevelPrice = extPrice * customerLevelMultiplier; // yes, use extended pricing and apply discount
}
else
{
customerLevelPrice = extPrice; // no, just use extended price with no additional discount
}
}
// get inclusive tax rate
decimal taxMultiplier = 1; // this is the default tax rate (e.g. no inclusive taxes)
string taxSuffix = string.Empty;
if (m_VATOn)
{
bool isNotTaxable = false;
// check if the variant is defined as NOT taxable
using (SqlConnection conn = new SqlConnection(DB.GetDBConn()))
{
conn.Open();
string sql = string.Format("SELECT IsTaxable FROM ProductVariant WHERE VariantID = {0}", variantID);
using (IDataReader reader = DB.GetRS(sql, conn))
{
isNotTaxable = reader.Read() && DB.RSFieldTinyInt(reader, "IsTaxable") == 0;
}
}
if (isNotTaxable)
{
taxMultiplier = 1;
}
else
{
taxMultiplier += ThisCustomer.TaxRate(taxClassID) / 100; // add any inclusive taxes into tax multiplier
}
// get suffix to display after pricing
if (AppLogic.ProductIsMLExpress() == false
&& m_VATEnabled)
{
// put another validation stuff here if the product variant is taxable or not
// set tax suffix to an empty string when the item is non-taxable regardless if the VAT Setting is either
// Inclusive or Exclusive
if (m_VATOn && isNotTaxable)
{
taxSuffix = String.Empty;
}
else if (m_VATOn && !isNotTaxable)
{
taxSuffix = AppLogic.GetString("setvatsetting.aspx.6", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
}
else if (!m_VATOn && !isNotTaxable)
{
taxSuffix = AppLogic.GetString("setvatsetting.aspx.7", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
}
}
}
// add inclusive tax, convert all pricing to ThisCustomer's currency, and round
regularPrice = decimal.Round(Currency.Convert(regularPrice + attributesPriceDelta, Localization.StoreCurrency(), ThisCustomer.CurrencySetting) * taxMultiplier, 2, MidpointRounding.AwayFromZero);
salePrice = decimal.Round(Currency.Convert(salePrice, Localization.StoreCurrency(), ThisCustomer.CurrencySetting) * taxMultiplier, 2, MidpointRounding.AwayFromZero);
customerLevelPrice = decimal.Round(Currency.Convert(customerLevelPrice, Localization.StoreCurrency(), ThisCustomer.CurrencySetting) * taxMultiplier, 2, MidpointRounding.AwayFromZero);
// format pricing
string regularPriceFormatted = Localization.CurrencyStringForDisplayWithExchangeRate(regularPrice, "AUD");
string salePriceFormatted = Localization.CurrencyStringForDisplayWithExchangeRate(salePrice, "AUD");
string customerLevelPriceFormatted = Localization.CurrencyStringForDisplayWithExchangeRate(customerLevelPrice, "AUD");
// get pricing labels
string genericPriceLabel = string.Empty;
string regularPriceLabel = string.Empty;
string salePriceLabel = string.Empty;
string customerLevelName = string.Empty;
if (showPriceLabel)
{
genericPriceLabel = AppLogic.GetString("showproduct.aspx.26", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + " ";
regularPriceLabel = AppLogic.GetString("showproduct.aspx.27", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + " " + "Equivalent to:";
salePriceLabel = " " + salesPromptName + ": ";
customerLevelName = ThisCustomer.CustomerLevelName + " ";
}
// format micropay points
string pointsFormatted = string.Empty;
if (AppLogic.AppConfigBool("MicroPay.ShowPointsWithPrices"))
{
pointsFormatted = "(" + points.ToString() + " Points)";
}
// create results string
// handle non-discounted customerLevel cases
if (ThisCustomer.CustomerLevelID == 0 || (ThisCustomer.LevelDiscountPct == 0 && extPrice == 0))
{
if (ThisCustomer.CustomerLevelID == 0 && AppLogic.AppConfigBool("WholesaleOnlySite")) // wholesale site with default customerLevel
{
results.Append(" ");
}
else // show Level 0 Pricing
{
if (salePrice == 0 || ThisCustomer.CustomerLevelID > 0)
{
results.Append("<span class=\"variantpriceAUD\">" + "Equivalent to:" + regularPriceFormatted + "</span>");
}
else
{
results.Append("<span class=\"RegularPrice\" >" + regularPriceLabel + "Equivalent to:" + regularPriceFormatted + "</span><br />");
results.Append("<span class=\"SalePrice\" style=\"color: " + AppLogic.AppConfig("OnSaleForTextColor") + "\">" + salePriceLabel + salePriceFormatted + "</span>");
}
results.Append(" ");
results.Append(taxSuffix);
}
}
// handle discounted customerLevels
else
{
results.Append("<span class=\"RegularPrice\" >" + regularPriceLabel + regularPriceFormatted + "</span><br />");
results.Append("<span class=\"LevelPrice\" style=\"color:" + AppLogic.AppConfig("OnSaleForTextColor") + "\">" + customerLevelName + regularPriceLabel + customerLevelPriceFormatted + "</span>");
results.Append(pointsFormatted);
results.Append(taxSuffix);
}
return results.ToString();
}