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

Custom Header w/ Cart Items and Cart Total

Post by sschlager » Tue Jun 24, 2008 2:45 pm

I have looked and looked for some kind of help with this. I have seen it on several sites and figured there would be a control that did it. That is why I included it in my design. Anyone have a control or know of where to find one that does this. An example is http://www.eurekaclothing.com/ when you add an item, in the right corner, what I am looking for comes up. It is the same in my mock design at http://www.thebackup.com/adamson/511.html Sorry, to ask so many questions.

Thanks,

Shaun

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 » Tue Jun 24, 2008 3:32 pm

Here's a custom control I did- it doesn't count the items, though. Only the dollar amount. Put it in Conlib/Custom.
HeaderBasketTotal.ascx

Code: Select all

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="HeaderBasketTotal.ascx.cs" Inherits="ConLib_Custom_HeaderBasketTotal" EnableViewState="false" %>
<%--
<conlib>
<summary>Display totals and summary of contents of basket.</summary>
</conlib>
--%>

        <table cellpadding="0" cellspacing="0" class="headerBasket">
             <tr>
                <td style="color:RGB(72,127,159); font-size:14px; font-weight:bold; text-align:right; padding: 24px 16px 0 0 ; margin:24px 16px 0 0 "><asp:Label ID="Total" runat="server"></asp:Label></td>
            </tr>
        </table>
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;
        Basket basket = Token.Instance.User.Basket;
        foreach (BasketItem item in basket.Items)
        {
            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 (total > 0)
        {
            Total.Text = total.ToString("ulc");
        }
    }

}

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

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 » Thu Jun 26, 2008 8:22 am

This works great, but there is one little change I think would be good. As it stands, if there are no items in the cart, nothing is displayed. How could we get $0.00 to display if nothing is in the cart? That way, a customer knows what the icon (in our case) in the upper corner is for. :-)

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 » Thu Jun 26, 2008 10:17 am

Yes Thanks! It works great but I also was wondering about that. I am not a programer but I believe all you would need is an if statement that says if cart equals zero display $0.00 or Empty. How you write that I have no clue.

User avatar
m_plugables
Commander (CMDR)
Commander (CMDR)
Posts: 149
Joined: Tue Mar 11, 2008 12:44 am
Contact:

Re: Custom Header w/ Cart Items and Cart Total

Post by m_plugables » Thu Jun 26, 2008 10:34 am

Change the following part of the code posted by Judy

Code: Select all

if (total > 0)
        {
            Total.Text = total.ToString("ulc");
        }
and make it look like

Code: Select all

if (total > 0)
        {
            Total.Text = total.ToString("ulc");
        }
else
{
Total.Text = "$0.00";
}
If you would like to show any custom text for example Empty Basket etc
just put it with in the double quotes where i put $0.00. For Empty Basket text it would be like

Code: Select all

if (total > 0)
        {
            Total.Text = total.ToString("ulc");
        }
else
{
Total.Text = "Empty Basket";
}

Image
Visit the links below to Download Plugins for your AC7 Store
http://www.plugables.com
http://blog.plugables.com

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 » Thu Jun 26, 2008 10:55 am

Thanks! You guys are awesome!

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 » Thu Jun 26, 2008 11:13 am

Thanks! I, too, am far from a programmer, so instead of messing with the file (I do that as little as possible :wink: ), I thought it better to ask. Besides, I thought that it may be of value to others, as well.

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 » Sun Jun 29, 2008 10:15 pm

How would one go about adding a second line under the total in the cart showing $x remaining to free shipping? When such a promotion is being run, it may be good for a customer to see how much (or little) they need to add in order to achieve this level. I tinkered a bit with the file, but without success.

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 Jun 30, 2008 2:12 am

Try this- I haven't tested:

Code: Select all

<tr>
 <td><asp:Label ID="ToFreeShip" runat="server"></asp:Label></td>
            </tr>

Code: Select all

if (total < 100)
        {
            ToFreeShip.Text = (100-total).ToString("ulc");
        }
else
{
ToFreeShip.Text = "Free shipping on orders over $100";
}
I'll post back later if there is a problem- I'm in the middle of an upgrade now, so can't test.
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

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 Jun 30, 2008 10:08 pm

I have tinkered a bit and come up with this:

if (total < 69)
{
ToFreeShip.Text = (69-total).ToString("ulc");
ToFreeShipExtra.Text = "more for free shipping";
}
else
{
ToFreeShip.Text = "Order ships Free";
ToFreeShipExtra.Text = "in the 48 states";
}

but cannot figure out how to get none of this to display if the cart is empty (leaving just the previously discussed "Cart Empty" code). Maybe I am not indenting properly, or maybe you cannot use a second level if / then / else.

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 » Tue Jul 01, 2008 4:50 pm

Something like:
if (total < 69) and (total>0) maybe.
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
nickc
Captain (CAPT)
Captain (CAPT)
Posts: 276
Joined: Thu Nov 29, 2007 3:48 pm

Re: Custom Header w/ Cart Items and Cart Total

Post by nickc » Tue Jul 01, 2008 5:31 pm

Code: Select all

ToFreeShip.Visible = ToFreeShipExtra.Visible = basket.Items.Count > 0 ? true : false;

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 » Tue Jul 01, 2008 7:56 pm

Thank you for the code suggestion, but where would this be placed exactly- in the ascx or ascx.cs file?

User avatar
nickc
Captain (CAPT)
Captain (CAPT)
Posts: 276
Joined: Thu Nov 29, 2007 3:48 pm

Re: Custom Header w/ Cart Items and Cart Total

Post by nickc » Wed Jul 02, 2008 10:18 am

In .cs:

Code: Select all

if (total < 69)
{
ToFreeShip.Text = (69-total).ToString("ulc");
ToFreeShipExtra.Text = "more for free shipping";
}
else
{
ToFreeShip.Text = "Order ships Free";
ToFreeShipExtra.Text = "in the 48 states";
}
ToFreeShip.Visible = ToFreeShipExtra.Visible = basket.Items.Count > 0 ? true : false;


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 » Wed Jul 02, 2008 11:03 am

That works perfectly- thank you! :D

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 Oct 06, 2008 6:34 pm

One more question- How would we get this to refresh in the header when the customer is on the basket page and makes a change to the basket?
Thanks
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
Shopping Cart Admin
AbleCommerce Admin
AbleCommerce Admin
Posts: 3055
Joined: Mon Dec 01, 2003 8:41 pm
Location: Vancouver, WA
Contact:

Re: Custom Header w/ Cart Items and Cart Total

Post by Shopping Cart Admin » Mon Oct 06, 2008 7:46 pm

Hello Judy,

Use a different header, it's normal not to have the mini-basket on the basket page.
One more question- How would we get this to refresh in the header when the customer is on the basket page and makes a change to the basket?
Thanks for your support

Shopping Cart Guru
AbleCommerce.com
Follow us on Facebook

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 » Fri Nov 21, 2008 2:07 pm

I figured out how to refresh the basket total in the header if the total in the basket changes (like adjust quantity and click recalculate). In my code, it is:

Code: Select all

<Ajax:UpdatePanel ID="UpdateBasket" runat="server">
<ContentTemplate>
<span style="color:#9A1C75; font-size:12px; ; text-align:right; padding-right:2px;"><asp:Hyperlink ForeColor="#9a1c75" ID="CartText" NavigateUrl= "~/basket.aspx" runat="server">Shopping Cart:</asp:Hyperlink></span>
<span style="color:#0668b2; font-size:12px; ; text-align:right; padding-right:2px;"><asp:Label ID="Total" runat="server"></asp:Label></span>
</ContentTemplate>
</Ajax:UpdatePanel>
I had to wrap it in the ajax.
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 Jan 09, 2009 8:38 am

So I've been using this and it isn't quite working right. The price display is perfect but I added an item count and it isn't displaying the count correctly. This issue has been discussed elsewhere (viewtopic.php?f=44&t=6683&hilit=mini+basket , viewtopic.php?f=42&t=8528&hilit=header+basket) however I can't seem to get it to work. The second link seems like it should work but I'm not sure how to combine the code in that post with the code in this post.

Also, the item count works exactly right if I'm logged in. It doesn't work if I'm not logged in - the count of 1 is correct, but as soon as I go to 2 or more items it is 1 short - which probably is because I used the wrong method to get an item count and then subtracted 1. Again, the code posted works if I'm logged in, it seems.

HeaderBasketTotal.ascx

Code: Select all

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="HeaderBasketTotal.ascx.cs" Inherits="ConLib_Custom_HeaderBasketTotal" EnableViewState="false" %>
<%--
<conlib>
<summary>Display totals and summary of contents of basket.</summary>
</conlib>
--%>

<Ajax:UpdatePanel ID="UpdateBasket" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:Hyperlink NavigateUrl="~/Basket.aspx" CssClass="headBasket" runat="server" id="headerBasketLink">
Basket
<span><asp:Label ID="lblBasketCount" runat="server"></asp:Label></span>
<span><asp:Label ID="lblTotal" runat="server"></asp:Label></span>
</asp:Hyperlink>
</ContentTemplate>
</Ajax:UpdatePanel>
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";
            itemCount = itemCount - 1;
            if (itemCount > 1)
            {
                lblBasketCount.Text = itemCount.ToString() + " items";
            }
            else
            {
                lblBasketCount.Text = "1 item";
            }
        }
    }

}
I'm really winging it with the code and whatever happens to pop-up for the intelisense in VS2008. But I did manage to get my CSS to change on my basket link when there are items in it which I really like - see attached.

Thanks for any help,
Dappy

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 09, 2009 9:22 am

Are you recalculate the basket after increasing the quantity. The basket it updated when you recalculate it. Also check by commenting out the following line of code

Code: Select all

itemCount = itemCount - 1;
and it will show the proper item count after logout as well.

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 Jan 09, 2009 9:43 am

That's the problem. When I comment that out it works when the user isn't logged in (the correct quantity) but the quantity is 1 higher when logged in.

So:
User not logged in, 1 item in basket = 1 item up top

User logged in, 1 item in basket = 2 items up top.

Is it counting shipping / tax as an item? I just thought of that - how would I exclude items if they aren't an actual product in the catalog?

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 09, 2009 9:55 am

hmm, then replace the line of code with the following

Code: Select all

if(!Token.Instance.User.IsAnonymous)
            itemCount = itemCount - 1;

User avatar
nickc
Captain (CAPT)
Captain (CAPT)
Posts: 276
Joined: Thu Nov 29, 2007 3:48 pm

Re: Custom Header w/ Cart Items and Cart Total

Post by nickc » Fri Jan 09, 2009 10:17 am

how would I exclude items if they aren't an actual product in the catalog?

Code: Select all

itemCount += item.OrderItemType == OrderItemType.Product ? item.Quantity : 0;

krittleb
Commander (CMDR)
Commander (CMDR)
Posts: 111
Joined: Tue Jan 06, 2009 11:27 pm

Re: Custom Header w/ Cart Items and Cart Total

Post by krittleb » Thu Jan 22, 2009 10:37 pm

I realize that this is a really old post and I don't know if people actually see new posts on the old ones or not, but here's a shot...

I was able to get the basket listed in the code above (with the item quantities included) into my conlib and then placed in my scriptlet where I want it. However, it is just plain text by default and being a newbie, I have no idea how to create all of the style sheets and links to the right divs to change the appearance. If someone could give me an example of their styles for this mini basket, I could then just alter it to how I would like it to appear.

Thanks,
Kristi

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 4:59 am

krittleb wrote:I realize that this is a really old post and I don't know if people actually see new posts on the old ones or not, but here's a shot...

I was able to get the basket listed in the code above (with the item quantities included) into my conlib and then placed in my scriptlet where I want it. However, it is just plain text by default and being a newbie, I have no idea how to create all of the style sheets and links to the right divs to change the appearance. If someone could give me an example of their styles for this mini basket, I could then just alter it to how I would like it to appear.

Thanks,
Kristi
Here is a snap for HTML layout and CSS changes for one of the sites using this control

Post Reply