Page 1 of 1
Volume Discount Display
Posted: Thu May 06, 2010 12:43 pm
by Thistle3408
I would like to pose two questions about displaying Volume Discounts. The questions are related.
In both cases (see questions below), instead of the standard display approach that looks somewhat like the following:
Product X Volume Discount
Buy 25 To 99,
Save $1.00 Each
Buy 100 To 249,
Save $2.00 Each
Buy 250 To 499,
Save $3.00 Each
Buy 500 Or More,
Save $4.10 Each
I'd like to simplify that display to look more like:
Product X Volume Discount
List Price $14.00
25+ $13.00
100+ $12.00
250+ $11.00
500+ $9.90
Notice two things,
eliminates all the "Buy....to..Save" text
resulting price instead of how much is "off/saved" (which ideally I'd like to have regardless whether we're using a %-age or $-amount discount structure for the product/group.
Ques.1 - How can I do that to replace the currently generated table by ProductDiscountsDialog.ascx and ProductDiscountsDialog.ascx.cs?
In other words, does anyone have code for those modules that accomplishes our desired result (or even close)?
Ques. 2 - Is there a way to get this table into the product description? So it appears in the text (HTML) along with the description in line.
Re: Volume Discount Display
Posted: Fri May 07, 2010 6:55 am
by s_ismail
Check it out might be it will be helpful for you but before replacing your code make sure you have backup of your original code as well.
Go to ProductDiscountsDialog.ascx.cs Page and replace the 'GetLevels()' mathod
as
Code: Select all
protected string GetLevels(object dataItem)
{
Product product = ProductDataSource.Load(PageHelper.GetProductId());
StringBuilder levelList = new StringBuilder();
levelList.Append("<ul>");
VolumeDiscount discount = (VolumeDiscount)dataItem;
string minFormat, maxFormat;
if (discount.IsValueBased)
{
minFormat = "{0:ulc}";
maxFormat = "{1:ulc}";
}
else
{
minFormat = "{0:F0}";
maxFormat = "{1:F0}";
}
foreach (VolumeDiscountLevel level in discount.Levels)
{
LSDecimal discPrice = (product.Price - level.DiscountAmount);
levelList.Append("<li>");
levelList.Append(string.Format(minFormat, level.MinValue));
if (level.IsPercent) levelList.Append(string.Format("+ {0:0.##}%", discPrice));
else levelList.Append(string.Format("+ {0:ulc} ", discPrice));
levelList.Append("</li>");
}
levelList.Append("</ul>");
}
Re: Volume Discount Display
Posted: Fri May 07, 2010 9:43 am
by Thistle3408
Great that gets me what I needed. We may still tweak it but this is cool and works.
Thanks
Re: Volume Discount Display
Posted: Sun May 09, 2010 7:55 am
by GrfxDan
Just curious if this modification takes into account price variations? If a customer selects a variant that changes the price (which then updates on screen via AJAX) will the discounted prices also change (and also update on screen) with this modification?
Re: Volume Discount Display
Posted: Sun May 09, 2010 4:29 pm
by Thistle3408
Dan et al,
I've changed the code to handle percentage and dollar discounts, BUT the are dependent on the "product" price. So if you have a kit or variant that changes the price (problem for me is that I have a lot of kits where the price is calculated on the sum of the prices of the components. Therefore I have a problem because the "product" price is entered as zero. So, if anyone wants to alter this code to use the price updates via AJAX, I'd love ya.
Look down where "product.Price" is used to calculate the resulting price after discounts. "product.Price" is the price shown on the product summary form in admin (in case someone didn't know)
If there is a way to get the price calculated due to the selections that the customer choose, we'd be very happy indeed.
Here's the current code:
Code: Select all
protected string GetLevels(object dataItem)
{
Product product = ProductDataSource.Load(PageHelper.GetProductId());
StringBuilder levelList = new StringBuilder();
levelList.Append("<table>");
levelList.Append("<tr>");
VolumeDiscount discount = (VolumeDiscount)dataItem;
string minFormat, maxFormat;
if (discount.IsValueBased)
{
minFormat = "{0:ulc}";
maxFormat = "{1:ulc}";
}
else
{
minFormat = "{0:F0}";
maxFormat = "{1:F0}";
}
// here might be a good place to add the "qty = 1 price"
levelList.Append("<td>");
levelList.Append("Qty 1");
levelList.Append("<td>");
levelList.Append(string.Format("{0:ulc}", product.Price));
levelList.Append("</tr>");
// end add qty 1 price at row one of table
foreach (VolumeDiscountLevel level in discount.Levels)
{
LSDecimal discPrice = (product.Price - level.DiscountAmount);
levelList.Append("<tr>");
levelList.Append("<td>");
levelList.Append(string.Format("{0:F0} +", level.MinValue));
levelList.Append("<td>");
if (level.IsPercent)
{
// was levelList.Append(string.Format("+ {0:0.##}%", discPrice));
// is now
levelList.Append(string.Format("{0:ulc} ", product.Price * (1 - level.DiscountAmount/100)));
}
else
{
levelList.Append(string.Format("{0:ulc} ", discPrice));
levelList.Append("</tr>");
}
}
levelList.Append("</table>");
return levelList.ToString();
}
Re: Volume Discount Display
Posted: Thu Jul 29, 2010 4:49 pm
by mmackrell
Not sure what I am missing, but I am getting the following error when I apply the changes to a product that has a volume discount: [[ConLib:Custom\ProductDiscountsDialog]] e:\hshome\zackcorp\ac7.zackproducts.com\ConLib\Custom\ProductDiscountsDialog.ascx.cs(91): error CS1519: Invalid token '(' in class, struct, or interface member declaration
Here is my code:
Code: Select all
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CommerceBuilder.Common;
using CommerceBuilder.Products;
using CommerceBuilder.Marketing;
using CommerceBuilder.Utility;
public partial class ConLib_ProductDiscountsDialog : System.Web.UI.UserControl
{
private string _Caption = "Available Discounts";
[Personalizable(), WebBrowsable()]
public string Caption
{
get { return _Caption; }
set { _Caption = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
bool discountsFound = false;
int _ProductId = AlwaysConvert.ToInt(Request.QueryString["ProductId"]);
Product _Product = ProductDataSource.Load(_ProductId);
if (_Product != null)
{
VolumeDiscountCollection availableDiscounts = VolumeDiscountDataSource.GetAvailableDiscounts(_ProductId);
if (availableDiscounts.Count > 0)
{
//SEE WHETHER THERE IS ONE DISCOUNT
//AND IT ALWAYS HAS NO VALUE
bool show = true;
if (availableDiscounts.Count == 1)
{
VolumeDiscount testDiscount = availableDiscounts[0];
if (testDiscount.Levels.Count == 1)
{
VolumeDiscountLevel testLevel = testDiscount.Levels[0];
show = ((testLevel.MinValue > 1) || (testLevel.DiscountAmount > 0));
}
}
if (show)
{
phCaption.Text = this.Caption;
DiscountGrid.DataSource = availableDiscounts;
DiscountGrid.DataBind();
discountsFound = true;
}
}
}
//DO NOT DISPLAY THIS CONTROL IF NO DISCOUNTS AVAILABLE
if (!discountsFound) this.Controls.Clear();
}
protected string GetLevels(object dataItem)
{
Product product = ProductDataSource.Load(PageHelper.GetProductId());
StringBuilder levelList = new StringBuilder();
levelList.Append("<ul>");
VolumeDiscount discount = (VolumeDiscount)dataItem;
string minFormat, maxFormat;
if (discount.IsValueBased)
{
minFormat = "{0:ulc}";
maxFormat = "{1:ulc}";
}
else
{
minFormat = "{0:F0}";
maxFormat = "{1:F0}";
}
foreach (VolumeDiscountLevel level in discount.Levels)
{
LSDecimal discPrice = (product.Price - level.DiscountAmount);
levelList.Append("<li>");
levelList.Append(string.Format(minFormat, level.MinValue));
if (level.IsPercent) levelList.Append(string.Format("+ {0:0.##}%", discPrice));
else levelList.Append(string.Format("+ {0:ulc} ", discPrice));
levelList.Append("</li>");
}
levelList.Append("</ul>");
}
levelList.Append("</ul>");
return levelList.ToString();
}
any help would be appreciated - thx
Re: Volume Discount Display
Posted: Fri Jul 30, 2010 10:30 am
by Thistle3408
mmackrell,
Not sure, and don't have the time to check it in detail.
My latest ProductDiscountsDialog.ascx.cs module is attached...it's the copy that is working live in living color.
Code: Select all
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CommerceBuilder.Common;
using CommerceBuilder.Products;
using CommerceBuilder.Marketing;
using CommerceBuilder.Utility;
public partial class ConLib_ProductDiscountsDialog : System.Web.UI.UserControl
{
private string _Caption = "Available Discounts";
[Personalizable(), WebBrowsable()]
public string Caption
{
get { return _Caption; }
set { _Caption = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
bool discountsFound = false;
int _ProductId = AlwaysConvert.ToInt(Request.QueryString["ProductId"]);
Product _Product = ProductDataSource.Load(_ProductId);
if (_Product != null)
{
VolumeDiscountCollection availableDiscounts = VolumeDiscountDataSource.GetAvailableDiscounts(_ProductId);
if (availableDiscounts.Count > 0)
{
//SEE WHETHER THERE IS ONE DISCOUNT
//AND IT ALWAYS HAS NO VALUE
bool show = true;
if (availableDiscounts.Count == 1)
{
VolumeDiscount testDiscount = availableDiscounts[0];
if (testDiscount.Levels.Count == 1)
{
VolumeDiscountLevel testLevel = testDiscount.Levels[0];
show = ((testLevel.MinValue > 1) || (testLevel.DiscountAmount > 0));
}
}
if (show)
{
phCaption.Text = this.Caption;
DiscountGrid.DataSource = availableDiscounts;
DiscountGrid.DataBind();
discountsFound = true;
}
}
}
//DO NOT DISPLAY THIS CONTROL IF NO DISCOUNTS AVAILABLE
if (!discountsFound) this.Controls.Clear();
}
// new code
protected string GetLevels(object dataItem)
{
Product product = ProductDataSource.Load(PageHelper.GetProductId());
StringBuilder levelList = new StringBuilder();
levelList.Append("<table class=\"discountTable\">");
levelList.Append("<tr>");
VolumeDiscount discount = (VolumeDiscount)dataItem;
string minFormat, maxFormat;
if (discount.IsValueBased)
{
minFormat = "{0:ulc}";
maxFormat = "{1:ulc}";
}
else
{
minFormat = "{0:F0}";
maxFormat = "{1:F0}";
}
// here might be a good place to add the "qty = 1 price"
levelList.Append("<td>");
levelList.Append("Qty 1");
levelList.Append("<td>");
levelList.Append(string.Format("{0:ulc}", product.Price));
levelList.Append("</tr>");
// end of my attempt to add qty 1 price
// It works
//This code contains the essence of what is needed to offer the percent discount as dollars
/*
if (level.IsPercent) itemTemplate1.Controls.Add(new LiteralControl(string.Format("{0:ulc}", product.Price * (1 - level.DiscountAmount/100))));
else itemTemplate1.Controls.Add(new LiteralControl(string.Format("{0:ulc} off", level.DiscountAmount)));
*/
//
foreach (VolumeDiscountLevel level in discount.Levels)
{
LSDecimal discPrice = (product.Price - level.DiscountAmount);
levelList.Append("<tr>");
levelList.Append("<td>");
levelList.Append(string.Format("{0:F0} +", level.MinValue));
levelList.Append("<td>");
if (level.IsPercent)
{
// was levelList.Append(string.Format("+ {0:0.##}%", discPrice));
// is now
levelList.Append(string.Format("{0:ulc} ", product.Price * (1 - level.DiscountAmount/100)));
}
else
{
levelList.Append(string.Format("{0:ulc} ", discPrice));
levelList.Append("</tr>");
}
}
levelList.Append("</table>");
return levelList.ToString();
}
}