When setting a pricing rule for a product:
But as you can see, by visiting this link: http://www.firefold.com/VCRDVR-Security ... 6C412.aspx
Even though the price which we sell this product for is $99.99, the pricing rule has changed both our original price and the new sale price to $59.99.
Here is the code for our conlib:
Code: Select all
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ProductPrice.ascx.cs" Inherits="ConLib_Utility_ProductPrice" EnableViewState="false" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<asp:PlaceHolder ID="phFixedPrice" runat="server">
<asp:Literal ID="Price" runat="server"></asp:Literal><br />
<asp:Literal ID="SpecialNote" runat="server" Text="Sale Price: {0:ulc}<br />Expires: {1:d}" Visible="false"></asp:Literal>
</asp:PlaceHolder>
<asp:PlaceHolder ID="phPricePopup" runat="server">
<asp:LinkButton ID="ShowPriceLink" runat="server" Text="Click To See Price"></asp:LinkButton>
<asp:Panel ID="PricePopup" runat="server">
<asp:PlaceHolder ID="trMsrp" runat="server">
<asp:Literal ID="MsrpLabel" runat="server" Text="List Price:"></asp:Literal> <asp:Literal ID="Msrp" runat="server"></asp:Literal>
</asp:PlaceHolder>
<asp:Literal ID="HiddenPriceLabel" runat="server" Text="Our Price:"></asp:Literal> <asp:Literal ID="HiddenPrice" runat="server"></asp:Literal><br />
<asp:Literal ID="SpecialNote2" runat="server" EnableViewState="false" Text="Sale Price: {0:ulc} Expires: {1:d}" Visible="false"></asp:Literal>
<asp:PlaceHolder ID="trYouSave" runat="server">
<asp:Literal ID="YouSaveLabel" runat="server" Text="You Save:"></asp:Literal> <asp:Literal ID="YouSave" runat="server"></asp:Literal>
</asp:PlaceHolder>
<asp:LinkButton ID="ClosePopUpLink" runat="server" Text="Close" SkinID="Button"></asp:LinkButton>
</asp:Panel>
</asp:PlaceHolder>
<asp:HiddenField ID="VS" runat="server" EnableViewState="false" />
Code: Select all
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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.Utility;
using CommerceBuilder.Orders;
using System.Collections.Generic;
using CommerceBuilder.Catalog;
using CommerceBuilder.DigitalDelivery;
public partial class ConLib_Utility_ProductPrice : System.Web.UI.UserControl
{
private int _ProductId = 0;
private Product _Product = null;
private string _OptionList = string.Empty;
private List<int> _SelectedKitProducts = new List<int>();
private bool _AddedItem = false;
/* properties that specify what product to show price for */
public int ProductId
{
set
{
_ProductId = AlwaysConvert.ToInt(value);
_Product = ProductDataSource.Load(_ProductId);
}
}
public object Product
{
set
{
_Product = value as Product;
if (_Product == null)
{
CatalogNode node = value as CatalogNode;
if (node != null) _Product = node.ChildObject as Product;
}
if (_Product != null) _ProductId = _Product.ProductId;
else _ProductId = 0;
}
}
public string OptionList
{
set { _OptionList = value; }
}
public List<int> SelectedKitProducts
{
set { _SelectedKitProducts = value; }
}
public string ShowPriceLinkText
{
get { return ShowPriceLink.Text; }
set { ShowPriceLink.Text = value; }
}
protected void Page_Init(object sender, EventArgs e)
{
LoadCustomViewState();
string scrollScript = @"var _lastWin;
function initPricePopup(divid)
{
_lastWin = divid;
reposPricePopup();
window.onscroll = reposPricePopup;
}
function reposPricePopup()
{
var div = document.getElementById(_lastWin);
var st = document.body.scrollTop;
if (st == 0) {
if (window.pageYOffset) st = window.pageYOffset;
else st = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
}
//div.style.top = 150 + st + ""px"";
}";
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "PricePopup", scrollScript, true);
ShowPriceLink.OnClientClick = "initPricePopup('" + PricePopup.ClientID + "');document.getElementById('" + PricePopup.ClientID + "').style.display='block';return false;";
ClosePopUpLink.OnClientClick = "document.getElementById('" + PricePopup.ClientID + "').style.display='none';return false;";
}
//save these from viewstate to process add request
private int _AddProductId;
private string _AddOptionList;
private List<int> _AddKitProducts = new List<int>();
private void LoadCustomViewState()
{
if (Page.IsPostBack)
{
string vsContent = Request.Form[VS.UniqueID];
string decodedContent = EncryptionHelper.DecryptAES(vsContent);
UrlEncodedDictionary customViewState = new UrlEncodedDictionary(decodedContent);
this.ProductId = AlwaysConvert.ToInt(customViewState.TryGetValue("PID"));
_AddProductId = _ProductId;
_OptionList = customViewState.TryGetValue("OL");
_AddOptionList = _OptionList;
int[] skp = AlwaysConvert.ToIntArray(customViewState.TryGetValue("SKP"));
if (skp != null && skp.Length > 0)
{
_SelectedKitProducts.AddRange(skp);
_AddKitProducts.AddRange(skp);
}
}
}
protected void Page_PreRender(object sender, EventArgs e)
{
if (_Product != null)
{
if (!_Product.UseVariablePrice)
{
// UPDATE THE INCLUDED KITPRODUCTS (Included-Hidden and Included-Shown)
if(_SelectedKitProducts == null || _SelectedKitProducts.Count == 0) UpdateIncludedKitOptions();
ProductCalculator pcalc = ProductCalculator.LoadForProduct(_Product.ProductId, 1, _OptionList, _SelectedKitProducts);
if (!_Product.HidePrice)
{
//PRICE IS VISIBLE, NO POPUP
phPricePopup.Visible = false;
Price.Text = pcalc.Price.ToString("ulc");
if (pcalc.AppliedSpecial != null && pcalc.AppliedSpecial.EndDate != DateTime.MinValue)
{
SpecialNote.Text = String.Format(SpecialNote.Text, pcalc.AppliedSpecial.Price, pcalc.AppliedSpecial.EndDate);
SpecialNote.Visible = true;
}
}
else
{
//HIDDEN PRICE, USE POPUP
Price.Visible = false;
if (_Product.MSRP > 0)
{
trMsrp.Visible = true;
Msrp.Text = _Product.MSRP.ToString("ulc");
LSDecimal youSaveAmount = (_Product.MSRP - _Product.Price);
decimal youSavePercent = ((decimal)(youSaveAmount / _Product.MSRP)) * 100;
YouSave.Text = youSaveAmount.ToString("ulc") + " (" + youSavePercent.ToString("F0") + "%)";
}
else
{
trMsrp.Visible = false;
trYouSave.Visible = false;
}
HiddenPrice.Text = pcalc.Price.ToString("ulc");
if (pcalc.AppliedSpecial != null && pcalc.AppliedSpecial.EndDate != DateTime.MinValue)
{
SpecialNote2.Text = String.Format(SpecialNote2.Text, pcalc.AppliedSpecial.Price, pcalc.AppliedSpecial.EndDate);
SpecialNote2.Visible = true;
}
}
}
else
{
//DO NOT DISPLAY THIS CONTROL IF THE PRODUCT HAS VARIABLE PRICE
this.Controls.Clear();
}
}
else
{
//DO NOT DISPLAY THIS CONTROL IF THE PRODUCT IS UNAVAILABLE
this.Controls.Clear();
}
SaveCustomViewState();
}
private void SaveCustomViewState()
{
UrlEncodedDictionary customViewState = new UrlEncodedDictionary();
customViewState["PID"] = _ProductId.ToString();
customViewState["OL"] = string.Empty + _OptionList;
customViewState["SKP"] = GetCommaDelimitedKitProducts();
VS.Value = EncryptionHelper.EncryptAES(customViewState.ToString());
}
private string GetCommaDelimitedKitProducts()
{
if ((_SelectedKitProducts == null) || (_SelectedKitProducts.Count == 0)) return string.Empty;
List<string> stringArray = new List<string>();
foreach (int item in _SelectedKitProducts) stringArray.Add(item.ToString());
return string.Join(",", stringArray.ToArray());
}
protected void UpdateIncludedKitOptions()
{
if (_SelectedKitProducts == null || _SelectedKitProducts.Count == 0) _SelectedKitProducts = new List<int>();
//COLLECT ANY KIT VALUES
Kit kit = new Kit(_Product);
List<KitProduct> defaultProducts = kit.GetDefaultKitProducts();
foreach (KitProduct p in defaultProducts)
{
_SelectedKitProducts.Add(p.KitProductId);
}
}
}