Page 1 of 1

Adding Database Field to Control

Posted: Wed Jan 18, 2012 6:18 pm
by napacabs
How would you add the field "EndDate" from the Specials (product pricing rules) table to the FeaturedProductsGrid control in a 01/01/2012 format? Thank You.

Re: Adding Database Field to Control

Posted: Thu Jan 19, 2012 8:48 am
by jmestep
To get that price, you would need to add that to the ConLib/ProductPrice. Use pcalc to get the price (that contains all the correct logic, like if it applies to the customer's user group)
The special price displays in the price popup in that file, so you would need either add code there to show the special price on the normal display for the page where it is used or add it separately to the file where the ProductPrice is used.
SpecialPrice.Text = string.Format(PopupSpecialPriceFormat, priceWithVAT, pcalc.AppliedSpecial.EndDate);
The special price format is defined at the top of the file
private string _PopupSpecialPriceLabel = "<b>Sale Price:</b>";
private string _PopupSpecialPriceFormat = "{0:ulc} ends {1:d}";

Re: Adding Database Field to Control

Posted: Thu Jan 19, 2012 11:15 am
by napacabs
Hi Judy,

Tried that but what I need is to only isolate the EndDate, to be used as a variable in a Javascript. I would like to create a timer which counts down to the end of sale, the script works properly on the product detail page content scriptlet as follows:

<script language="JavaScript">
StartCountDown("clock1","#foreach($pcf in $Product.Specials)#if($pcf.ProductID == $Product.ProductId)$pcf.EndDate.ToString("MMM dd, yyyy")#end#end 11:59:59 PM -0700")
function StartCountDown(myDiv,myTargetDate)...

However, within a control such as "Featured Products" using a modified price user control "<%@ Register Src="~/ConLib/Utility/ProductPrice_MOD.ascx" TagName="ProductPrice" TagPrefix="uc" %>" with code behind "private string _SpecialPriceFormat = "{1:d}";"
the variable EndDate is hidden as follows:

Viewed from page source:
<script language="JavaScript">
StartCountDown("clock11699","<input type="hidden" name="ctl00$wpm$...$Price2$VS" id="ctl00...VS" value="sB6J...hD" /> 11:59:59 PM -0700")
function StartCountDown(myDiv,myTargetDate)...

The ProductId used in the ID "clock11699" was properly inserted with "clock<%# ProdID(Container.DataItem)%>". How can I get ac_Specials EndDate (from "EditProduct > Pricing Rules") to be used as <%# EndDate(Container.DataItem)%> or what is the code to be able to assign a value to the hidden variable field?

Thanks

Re: Adding Database Field to Control

Posted: Fri Jan 20, 2012 9:17 am
by jmestep
In your code behind you would do something like
protected DateTime GetEndDate(object dataItem)
{

Product product = (Product)dataItem;
DateTime endDate = LocalHelper.LocalNow; //whatever date time you want to start with
//do the pcalc stuff here like what is in the Utility/ProductPrice
//check the date against the endDate above
return endDate

}