Custom Header w/ Cart Items and Cart Total

Store UI, layout, design, look and feel; Discussion on the customer facing pages of your online store. Cascading Style Sheets, Themes, Scriptlets, NVelocity and the components in the ConLib directory.
User avatar
sschlager
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 21
Joined: Mon Jun 16, 2008 9:04 am
Location: Coeur D Alene, ID

Re: Custom Header w/ Cart Items and Cart Total

Post by sschlager » Fri Jan 23, 2009 9:53 am

Mazhar What program do you use to work on your sites?

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

Re: Custom Header w/ Cart Items and Cart Total

Post by mazhar » Fri Jan 23, 2009 10:00 am

If you are asking regarding the last post I made, its the FireBug plugin for FireFox.

User avatar
draneb
Captain (CAPT)
Captain (CAPT)
Posts: 314
Joined: Sun Jun 12, 2005 4:07 pm
Location: Texas
Contact:

Re: Custom Header w/ Cart Items and Cart Total

Post by draneb » Sun Sep 06, 2009 5:46 pm

Hello,

I am wanting to add this conlib control to my newest ac7 site. I am using the code from dappy2's post so I am getting the same results.

I tried the other suggestions and it didn't correct the problem for me, unless I am doing something wrong, which is quite possible. I got a little lost in this thread.

Does anyone have a final version of the code which works?

The couple of things I see is
1) Once you get to the shipping part of checking out it will add (1) to the Item(s) but display the correct total.
2) If I add any quantity greater than 1 to the basket, then move it to the Wishlist, then move it back to the Basket it will lower the Item(s) quantity by 1 but display the correct total.

If the Item(s) part is just too much trouble I may have to just use the Subtotal part of the code but it sure would be nice to use them both.
Thank you.
AC 7.0.3 build 13937

Brewhaus
Vice Admiral (VADM)
Vice Admiral (VADM)
Posts: 878
Joined: Sat Jan 19, 2008 4:30 pm

Re: Custom Header w/ Cart Items and Cart Total

Post by Brewhaus » Mon Dec 28, 2009 8:26 am

I have found one problem with the control (we are using the HeaderBasket files provided earlier in this thread)- the value showing includes tax if the items are taxable, even though there is no shipping address present. The total showing on the basket page (~/basket.aspx) is correct (ie. it does not show tax unless a person is logged in and is within TX (our taxable state)). However, the total in the Header Basket shows the amount with tax once a customer has gone to the login page, even if they do not log in.

How do we adapt the HeaderBasket file to pull the total excluding tax?
Rick Morris
Brewhaus (America) Inc.
Hot Sauce Depot

User avatar
draneb
Captain (CAPT)
Captain (CAPT)
Posts: 314
Joined: Sun Jun 12, 2005 4:07 pm
Location: Texas
Contact:

Re: Custom Header w/ Cart Items and Cart Total

Post by draneb » Mon Dec 28, 2009 8:28 am

Yes, that is the same problem I am having.. I am even in TX also. haha
AC 7.0.3 build 13937

User avatar
Beatroot
Commander (CMDR)
Commander (CMDR)
Posts: 119
Joined: Thu Jan 20, 2005 2:23 am
Location: Massapequa Park, New York
Contact:

Re: Custom Header w/ Cart Items and Cart Total

Post by Beatroot » Tue Jan 05, 2010 2:18 pm

I set up a shopping cart a while ago in version 5.5, .aspx.

Because of personal shopping experiences, I think it helps a lot to display the item total and cart subtotal... so not being much of a programmer I'm trying to display these 2 values in the header for all my pages but have failed miserably. I'm looking at the suggestions here but I don't think the code suggested will work for our old ship. Any code suggestions for Able 5.5 aspx to display the cart item total and subtotal values?

User avatar
draneb
Captain (CAPT)
Captain (CAPT)
Posts: 314
Joined: Sun Jun 12, 2005 4:07 pm
Location: Texas
Contact:

Re: Custom Header w/ Cart Items and Cart Total

Post by draneb » Sun Jan 10, 2010 8:19 pm

Brehaus,

I was worried it might be including/displaying tax for everyone. I guess I need to ask a friend that lives in some other state to add an item to their cart and see what it shows.

I don't mind it displaying tax just as long as it is in sync with the checkout process so any totals match.
For example, I am on the Checkout/Default.aspx page right now and the headerbaskettotal shows 18.97 but the Basket.aspx total shows 17.52.
Is there an AC genius who could fix this for us?

It also looks like I will be needing an AC developer and web designer. I do not know what happened to my person I haven't been able to get a reply.

Thank you.
AC 7.0.3 build 13937

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

Re: Custom Header w/ Cart Items and Cart Total

Post by jmestep » Mon Jan 11, 2010 6:16 am

I don't have time to look it up, but I think there have been a post or two on the forum about removing the tax line from the basket summary and something similar should work in the header basket.
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

dappy2
Commander (CMDR)
Commander (CMDR)
Posts: 114
Joined: Wed Jan 18, 2006 5:53 pm
Contact:

Re: Custom Header w/ Cart Items and Cart Total

Post by dappy2 » Fri Apr 09, 2010 2:10 pm

Sorry to resurrect such an old post, but I'm having a small issue with this and I'm slowly squashing some more minor bugs in the site design and function so...

If a user clicks "buy now" they are redirected to the basket page and the header control updates. However, if you click "back" in the browser, the header control reverts to the previous state, without items in the basket even though the store knows items are there.

Is this just a browser issue - such as the page is cached and it isn't requesting anything from the server? If not, is there anyway to force the UpdatePanel to update itself on a browser back event? If you refresh the page after the back event, the basket header updates. Does it have to do with the Page_PreRender? Perhaps a different call should be there?

I have the update mode set to always, I also tried making it conditional and forcing the Update() method in the code behind with no luck.

You can see the action here: http://www.devonsuperstore.com

Thanks!
Dappy

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

Re: Custom Header w/ Cart Items and Cart Total

Post by jmestep » Sat Apr 10, 2010 7:03 am

I have put header basket code within an update panel because there were times it wasn't updating otherwise.
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

dappy2
Commander (CMDR)
Commander (CMDR)
Posts: 114
Joined: Wed Jan 18, 2006 5:53 pm
Contact:

Re: Custom Header w/ Cart Items and Cart Total

Post by dappy2 » Mon Apr 12, 2010 8:23 am

I do have the header basket code within an update panel. It still doesn't update when the user clicks the back button in the browser (At least in Firefox and IE as far as I can tell).

lbjones26
Ensign (ENS)
Ensign (ENS)
Posts: 2
Joined: Thu Nov 11, 2010 11:17 am

Re: Custom Header w/ Cart Items and Cart Total

Post by lbjones26 » Thu Nov 11, 2010 11:32 am

My header basket code is working fine for individual items, but for bundles/kits it's counting the kit as 1 and then adding to the count each item included inside the kit. So for example, the kit is made up of 5 items. When you add the item to cart, initially the count is correct ("1 item"). If you update the cart (delete an item/recalcluate) the # is thrown off - in this example, a kit made up of 5 items will be listed a "6 items".

HeaderBasketTotal.ascx.cs

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.Orders;

public partial class ConLib_Custom_HeaderBasketTotal : System.Web.UI.UserControl
{
    //USE PRERENDER TO ALLOW FOR CALCULATIONS TO BASKET CONTENTS
    protected void Page_PreRender(object sender, EventArgs e)
    {
        LSDecimal subtotal = 0;
        LSDecimal shipping = 0;
        LSDecimal taxes = 0;
        LSDecimal coupons = 0;
        LSDecimal total = 0;
        LSDecimal giftwrap = 0;
        int itemCount = 0;
        Basket basket = Token.Instance.User.Basket;
        foreach (BasketItem item in basket.Items)
        {
            itemCount += item.Quantity;
            LSDecimal extendedPrice = item.ExtendedPrice;
            switch (item.OrderItemType)
            {
                case OrderItemType.Shipping:
                case OrderItemType.Handling:
                    shipping += extendedPrice;
                    break;
                case OrderItemType.Tax:
                    taxes += extendedPrice;
                    break;
                case OrderItemType.Coupon:
                    coupons += extendedPrice;
                    break;
                case OrderItemType.GiftWrap:
                    giftwrap += extendedPrice;
                    break;
                default:
                    subtotal += extendedPrice;
                    break;
            }
            total += item.ExtendedPrice;
        }
        if (subtotal > 0)
        {
            lblTotal.Text = subtotal.ToString("ulc");
            headerBasketLink.CssClass = "headBasketFilled";
            if (itemCount > 1)
            {
                lblBasketCount.Text = itemCount.ToString() + " items";
            }
            else
            {
                lblBasketCount.Text = "1 item";
            }
        }
        else
        {
            lblTotal.Text = "$0.00";
            headerBasketLink.CssClass = "headBasketEmpty";
            lblBasketCount.Text = "0 items";
        }
    }

    protected string GetCheckoutURL()
    {
        return NavigationHelper.GetCheckoutUrl(); 
    }

    protected void BtnCheckout_Click(object sender, EventArgs e)
    {
        Response.Redirect(NavigationHelper.GetCheckoutUrl());  
    }
}
Any ideas? We need to count a kit as just 1 item.

lbjones26
Ensign (ENS)
Ensign (ENS)
Posts: 2
Joined: Thu Nov 11, 2010 11:17 am

Re: Custom Header w/ Cart Items and Cart Total

Post by lbjones26 » Thu Nov 11, 2010 4:17 pm

Figured it out!

We made changes to keep shipping/coupons/tax from adding to the total, as well as turning off the count for children of kits.

HeaderBasketTotal.ascx.cs

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.Orders;

public partial class ConLib_Custom_HeaderBasketTotal : System.Web.UI.UserControl
{
    //USE PRERENDER TO ALLOW FOR CALCULATIONS TO BASKET CONTENTS
    protected void Page_PreRender(object sender, EventArgs e)
    {
        LSDecimal subtotal = 0;
        LSDecimal shipping = 0;
        LSDecimal taxes = 0;
        LSDecimal coupons = 0;
        LSDecimal total = 0;
        LSDecimal giftwrap = 0;
        int itemCount = 0;
        Basket basket = Token.Instance.User.Basket;
        foreach (BasketItem item in basket.Items)
        {
            if (item.OrderItemType == OrderItemType.Product && !item.IsChildItem)
            {
                itemCount += item.Quantity;
            }
                LSDecimal extendedPrice = item.ExtendedPrice;
                switch (item.OrderItemType)
                {
                    case OrderItemType.Shipping:
                    case OrderItemType.Handling:
                        shipping += extendedPrice;
                        break;
                    case OrderItemType.Tax:
                        taxes += extendedPrice;
                        break;
                    case OrderItemType.Coupon:
                        coupons += extendedPrice;
                        break;
                    case OrderItemType.GiftWrap:
                        giftwrap += extendedPrice;
                        break;
                    default:
                        subtotal += extendedPrice;
                        break;
                }
                total += item.ExtendedPrice;
           
        }
        if (subtotal > 0)
        {
            lblTotal.Text = subtotal.ToString("ulc");
            headerBasketLink.CssClass = "headBasketFilled";
            if (itemCount > 1)
            {
                lblBasketCount.Text = itemCount.ToString() + " items";
            }
            else
            {
                lblBasketCount.Text = "1 item";
            }
        }
        else
        {
            lblTotal.Text = "$0.00";
            headerBasketLink.CssClass = "headBasketEmpty";
            lblBasketCount.Text = "0 items";
        }
    }

    protected string GetCheckoutURL()
    {
        return NavigationHelper.GetCheckoutUrl(); 
    }

    protected void BtnCheckout_Click(object sender, EventArgs e)
    {
        Response.Redirect(NavigationHelper.GetCheckoutUrl());  
    }
}


Post Reply