I have some code here:
(It basically checks if a product is a kit product or not then applys the New Price with the Price Modification)
if (!newItem.m_IsAKit)
{
NewPR = AppLogic.DetermineLevelPrice(newItem.m_VariantID, m_ThisCustomer.CustomerLevelID, out IsOnSale);
Decimal PrMod = AppLogic.GetColorAndSizePriceDelta(DB.RSField(rs, "ChosenColor"), DB.RSField(rs, "ChosenSize"), DB.RSFieldInt(rs, "TaxClassID"), ThisCustomer, true, false);
if (PrMod != System.Decimal.Zero)
{
NewPR += PrMod;
}
}
else
{
NewPR = DB.RSFieldDecimal(rs, "ProductPrice");
if (LevelDiscountPercent != 0.0M)
{
NewPR = AppLogic.GetKitTotalPrice(m_ThisCustomer.CustomerID, m_ThisCustomer.CustomerLevelID, newItem.m_ProductID, newItem.m_VariantID, newItem.m_ShoppingCartRecordID);
}
}
I have a product which IS a kit product so i am refering to the code after the else statement.
I need to apply NewPr += PrMod.
NewPr = 22
PrMod = 5
I have tried adding this code:
Decimal PrMod = AppLogic.GetColorAndSizePriceDelta(DB.RSField(rs, "ChosenColor"), DB.RSField(rs, "ChosenSize"), DB.RSFieldInt(rs, "TaxClassID"), ThisCustomer, true, false);
if (PrMod != System.Decimal.Zero)
{
NewPR += PrMod;
}
But during debugging the PrMod doesnt seem to hold a value.
Can you help point me in the right direction?
Thanks
I have the following method but i cant seem to see where the problem is. When the product IS a kit product it works fine.
static public decimal GetColorAndSizePriceDelta(String ChosenColor, String ChosenSize, int TaxClassID, Customer ThisCustomer, bool WithDiscount, bool WithVAT)
{
bool VATEnabled = AppLogic.ProductIsMLExpress() == false && AppLogic.AppConfigBool("VAT.Enabled");
bool VATOn = (VATEnabled && ThisCustomer.VATSettingReconciled == VATSettingEnum.ShowPricesInclusiveOfVAT);
decimal CustLevelDiscountPct = 1.0M;
decimal price = System.Decimal.Zero;
String ColorPriceModifier = String.Empty;
String SizePriceModifier = String.Empty;
if (ThisCustomer.CustomerLevelID > 0 && WithDiscount)
{
decimal LevelDiscountPercent = System.Decimal.Zero;
using (SqlConnection dbconn = new SqlConnection(DB.GetDBConn()))
{
dbconn.Open();
string sSql = string.Format("select LevelDiscountPercent from CustomerLevel with (NOLOCK) where CustomerLevelID={0}", ThisCustomer.CustomerLevelID);
using (IDataReader rs = DB.GetRS(sSql, dbconn))
{
if (rs.Read())
{
LevelDiscountPercent = DB.RSFieldDecimal(rs, "LevelDiscountPercent");
}
}
}
if (LevelDiscountPercent != System.Decimal.Zero)
{
CustLevelDiscountPct -= LevelDiscountPercent / 100.0M;
}
}
if (ChosenColor.IndexOf("[") != -1)
{
int i1 = ChosenColor.IndexOf("[");
int i2 = ChosenColor.IndexOf("]");
if (i1 != -1 && i2 != -1)
{
ColorPriceModifier = ChosenColor.Substring(i1 + 1, i2 - i1 - 1);
}
}
if (ChosenSize.IndexOf("[") != -1)
{
int i1 = ChosenSize.IndexOf("[");
int i2 = ChosenSize.IndexOf("]");
if (i1 != -1 && i2 != -1)
{
SizePriceModifier = ChosenSize.Substring(i1 + 1, i2 - i1 - 1);
}
}
if (ColorPriceModifier.Length != 0)
{
price += Localization.ParseDBDecimal(ColorPriceModifier);
}
if (SizePriceModifier.Length != 0)
{
price += Localization.ParseDBDecimal(SizePriceModifier);
}
if (VATOn && WithVAT)
{
decimal TaxRate = 0.0M;
TaxRate = ThisCustomer.TaxRate(TaxClassID);
Decimal TaxMultiplier = (1.0M + (TaxRate / 100.00M));
price = TaxMultiplier * price;
}
return price * CustLevelDiscountPct;
}
Why dont you initialize the varaible PrMod tp Zero
You need to debbug AppLogic.GetColorAndSizePriceDelta method because if the return type is Decimal, it should atleast return a deafult value as 0.0M