Possible bug with ProductPrice utility conlib

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
evanb@firefold.com
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 36
Joined: Mon Jul 21, 2008 3:45 pm

Possible bug with ProductPrice utility conlib

Post by evanb@firefold.com » Tue Oct 21, 2008 9:59 am

Thought of posting this to CRM but due to the fact that it is probably user error I figured I'd post it here.

When setting a pricing rule for a product:
Image

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>&nbsp;<asp:Literal ID="Msrp" runat="server"></asp:Literal>
            </asp:PlaceHolder>

            <asp:Literal ID="HiddenPriceLabel" runat="server" Text="Our Price:"></asp:Literal>&nbsp;<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>&nbsp;<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" />
Here is the code behind:

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);
        }
    }
}
Thank You!

Robbie@FireFold
Commodore (COMO)
Commodore (COMO)
Posts: 433
Joined: Wed May 28, 2008 9:42 am
Location: Concord, NC
Contact:

Re: Possible bug with ProductPrice utility conlib

Post by Robbie@FireFold » Wed Oct 22, 2008 10:53 pm

Anyone else seen this issue? This is a feature we want to use, but it doesn't seem to work right.
Robbie Hodge
General Manager
Robbie@FireFold.com
http://www.FireFold.com

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: Possible bug with ProductPrice utility conlib

Post by jmestep » Thu Oct 23, 2008 7:32 am

I just tried it and had the same issue. It's that way on the category display page for the product also.
Build 10152
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Possible bug with ProductPrice utility conlib

Post by mazhar » Thu Oct 23, 2008 9:57 am

Well if you want to show actual price for our price label then you have to made a small modification in the following block of code

Code: Select all

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;
                    }
                }
Change the

Code: Select all

Price.Text = pcalc.Price.ToString("ulc");
to

Code: Select all

Price.Text = _Product.Price.ToString("ulc");

Post Reply