an ASP.NET Open Source CMS & eCommerce platform
Search:
Skip Navigation LinksHome > DotShoppingCart Forums > Support > Using DotShoppingCart > Custom Product Discounts
Last Post 2/23/2011 5:36:23 PM By lukezy. 14 replies.
Page 1 of 2 (15 posts) << First < Prev 1 2 Next > Last >> 
7/6/2009 8:36:13 AM
bansal_db
Posts: 181
Joined: 4/13/2009
Custom Product Discounts
Hey Luke,
 
I did the custom discounts for each product on my site for different customer roles. You might remember we talked about it on phone couple of months back.
 
I created a table with productID, role ID and % discount for the item and was picking up this discounted price to show up on the site when the customer logs in.
 
I noticed something lately which I didn't test for before. If the person is logged in for a long time and there is no activity, the prices go back to the default prices. The site stops displaying the discounted prices. User will have to log out and log back in again to see their discounted prices.
 
I am thinking it might be something to do with the session but I am not sure. Any Ideas?
 
Thanks
 
-Divyanshu
7/6/2009 10:16:34 AM
lukezy
Posts: 2109
Joined: 6/12/2007
Location:WA, US
Re: Custom Product Discounts
This seems like a session issue. Could you please post the code that is used to calculate the discount price?
DotShoppingCart Staff
7/7/2009 11:59:11 AM
bansal_db
Posts: 181
Joined: 4/13/2009
Re: Custom Product Discounts
I did the following changes


Changed this line in ProductPrices.ascx.cs


lblCurrentPrice.Text = WebUtils.GetDiscountPrice(product.Price).ToString("c");



to



 lblCurrentPrice.Text = custom.GetCustomDiscountPrice(product.Price, Product.ProductId, Roles.GetRolesForUser(Utils.GetUserName())).ToString("c");




The code for this new function is



 public decimal GetCustomDiscountPrice(decimal price, int productID, string[] roles)

    {

        return Utils.Round(price * (100 - getCustomDiscountRate(productID, roles)) / 100);

    }




public decimal getCustomDiscountRate(int productId, string[] roles)

    {

       

        int roleID = getRoleID(roles[0]);

        decimal discountRate = 0;

        DiscountsDataContext db = new DiscountsDataContext(ConfigurationController.SiteConfigurationController.GetSiteConnectionString(SiteNavigation.GetHost()));

        var discount =  from d in db.DSC_CustomDiscounts

               where (d.productId == productId && d.roleId == roleID)

               select d;

        foreach (var x in discount)

        {

            discountRate = x.discountRate;

        }

        return discountRate;

    }





Customer will never be assigned to more than one roles.



I also fixed the Final Price in cart page and checkout page to take my custom price. Also the stored procedure DSC_Order_Add_OrderItem.



I didnot play around with the session at all. Everything works fine until the session is left idle for sometime. What's the timeout on the session?



I don't think the site logs out the user after timeout.



Also I noticed another thing, If i login as admin and then go to users and use the switch button (to login as customer), I don't see customer's discounted prices. I see the list price. I am guessing this also has to do with session.



WHat do you think?



Thanks


-Divyanshu










7/8/2009 10:42:31 PM
lukezy
Posts: 2109
Joined: 6/12/2007
Location:WA, US
Re: Custom Product Discounts
I know GetDiscountPrice() reads HttpContext.Current.Session["discountRate"]. Since you replace it with your own code, I cannot think of a reason why it doesn't always work. Could you please try set a breakpoint on your dev machine and debug it?
DotShoppingCart Staff
7/9/2009 6:23:18 AM
bansal_db
Posts: 181
Joined: 4/13/2009
Re: Custom Product Discounts
I don;t think its the discount price, I think it's the "discount" that gets messed up in the session.
 
For example when a user logs in and he is supposed to see discounted price, site displays the prices like this
 
 
Product Name
$79.00  $52.00
 
But when the session is left idle for some time,  It only displays the MSRP
 
 
ProductName
$79.00
 
 
No discounted price. Doesn't even say your discounted price is this in the product detail page.
 
I am thinking somehow the discount available to the customer is not there anymore. May be the session is getting currupted in this method
 
WebUtils.IsDiscountGroup()
 
What do you think?
 
 
 

7/9/2009 8:01:11 AM
lukezy
Posts: 2109
Joined: 6/12/2007
Location:WA, US
Re: Custom Product Discounts
The data in the session will be gone after it's timed out. I don't see anywhere that you use WebUtils.IsDiscountGroup()?
Anywhere you can call CoreHelper.WriteDiscountGroupToSession() before WebUtils.IsDiscountGroup() is called so that the session data are refreshed always.
DotShoppingCart Staff
7/9/2009 8:11:34 AM
bansal_db
Posts: 181
Joined: 4/13/2009
Re: Custom Product Discounts
I didn't use WebUtils.IsDiscountGroup(), it was already getting used but since my code is within that condition, that the only thing I can think of. Can I set the site to logout the user after the session is idle for sometime?
 
This is the product prices.ascx.cs
 
 
protected void Page_Load(object sender, EventArgs e) {
        if (!IsPostBack) {
            custom = new customDiscount();
            if (Page.User.Identity.IsAuthenticated)
            {
                if (WebUtils.IsDiscountGroup())
                {
                    lblCrossPriceTitle.Text = (string)HttpContext.GetGlobalResourceObject("Common", "RetailPriceInput");
                    lblCurrentPriceTitle.Text = (string)HttpContext.GetGlobalResourceObject("Common", "YourDiscountedPriceInput");
                    lblCrossPrice.Text = product.Price.ToString("c");
                    //lblCurrentPrice.Text = WebUtils.GetDiscountPrice(product.Price).ToString("c");
                    lblCurrentPrice.Text = custom.GetCustomDiscountPrice(product.Price, Product.ProductId, Roles.GetRolesForUser(Utils.GetUserName())).ToString("c");

                }
                else
                {
                    if (null != product.SalePrice)
                    {
                        lblCrossPriceTitle.Text = (string)HttpContext.GetGlobalResourceObject("Common", "OriginalPriceInput");
                        lblCurrentPriceTitle.Text = (string)HttpContext.GetGlobalResourceObject("Common", "SalePriceInput");
                        lblCrossPrice.Text = product.Price.ToString("c");
                        lblCurrentPrice.Text = ((Decimal)product.SalePrice).ToString("c");
                        lblSave.Text = string.Format((string)HttpContext.GetGlobalResourceObject("Common", "SomethingOff"), product.SavePercentage);
                        rowYouSave.Visible = true;
                    }
                    else if (null != product.RetailPrice)
                    {
                        lblCurrentPriceTitle.Text = (string)HttpContext.GetGlobalResourceObject("Common", "OurPriceInput");
                        lblCrossPrice.Text = ((Decimal)product.RetailPrice).ToString("c");
                        lblCurrentPrice.Text = product.Price.ToString("c");
                        lblSave.Text = string.Format((string)HttpContext.GetGlobalResourceObject("Common", "SomethingOff"), product.SavePercentage);
                        rowYouSave.Visible = true;
                    }
                    else
                    {
                        rowCrossPrice.Visible = false;
                        lblCurrentPriceTitle.Text = (string)HttpContext.GetGlobalResourceObject("Common", "PriceInput");
                        lblCurrentPrice.Text = product.Price.ToString("c");
                    }
                }
            }
            lblAvailability.Text = Product.Availability;
        }
    }
7/9/2009 8:45:16 AM
lukezy
Posts: 2109
Joined: 6/12/2007
Location:WA, US
Re: Custom Product Discounts
Ok, it makes sense now. Just put CoreHelper.WriteDiscountGroupToSession() before if (WebUtils.IsDiscountGroup()) and it should fix the problem.
DotShoppingCart Staff
7/9/2009 9:11:57 AM
bansal_db
Posts: 181
Joined: 4/13/2009
Re: Custom Product Discounts
Thanks
2/22/2011 1:39:14 AM
malshini
Posts: 29
Joined: 11/9/2010
Re: Custom Product Discounts
Please let me know the condition for WebUtils.IsDiscountGroup()
and how can we add a product which has a sale price to this group.
 
Urgent!
 
Thanks a lot!
2/22/2011 2:10:54 AM
malshini
Posts: 29
Joined: 11/9/2010
Re: Custom Product Discounts
Where does this HttpContext.Current.Items["Cart"] gets its value intially ?
 
Cart cart = (Cart)HttpContext.Current.Items["Cart"]; (for anonymous user)
Page 1 of 2 (15 posts) << First < Prev 1 2 Next > Last >>