get total for cart in header

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
15 years ago
I want to add a total to the header. I can't find the correct code to add it.

This is something i tried but doesn't work

Total:<%=ShoppingCartManager.GetCurrentShoppingCart(ShoppingCartManager.GetShoppingCartSubTotal).ToString %>

Does any one know the correct code?

thanks

Mike
15 years ago
Show subtotal (and not total):

[quote]ShoppingCart Cart = ShoppingCartManager.GetCurrentShoppingCart(ShoppingCartTypeEnum.ShoppingCart);
decimal shoppingCartSubTotalDiscount;
decimal shoppingCartSubTotal = ShoppingCartManager.GetShoppingCartSubTotal(Cart, NopContext.Current.User, out shoppingCartSubTotalDiscount);
decimal shoppingCartSubTotalConverted = CurrencyManager.ConvertCurrency(shoppingCartSubTotal, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);                
lblSubTotalAmount.Text = LocalizationManager.GetCurrencyString(shoppingCartSubTotalConverted, true, NopContext.Current.WorkingCurrency);[/quote]
15 years ago
I am getting an error

Compiler Error Message: CS0103: The name 'NopContext' does not exist in the current context

Source Error:



Line 36:             ShoppingCart Cart = ShoppingCartManager.GetCurrentShoppingCart(ShoppingCartTypeEnum.ShoppingCart);
Line 37:             decimal shoppingCartSubTotalDiscount;
Line 38:             decimal shoppingCartSubTotal = ShoppingCartManager.GetShoppingCartSubTotal(Cart, NopContext.Current.User, out shoppingCartSubTotalDiscount);
Line 39:             decimal shoppingCartSubTotalConverted = CurrencyManager.ConvertCurrency(shoppingCartSubTotal, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
Line 40:             lblSubTotalAmount.Text = LocalizationManager.GetCurrencyString(shoppingCartSubTotalConverted, true, NopContext.Current.WorkingCurrency);
15 years ago
Add a using directive at the top of the file to specify the namespace of NopContext class
15 years ago
What is NopContext class under. I can't find it

using NopSolutions.NopCommerce.Common.Orders; ?

I managed to do it. Not used to C#

Thanks
15 years ago
using NopSolutions.NopCommerce.Common
15 years ago
This is working to a certain extent but when i go to my product and add to cart it is not updating the subtotal on first postback this is my code? Seems to be one update behind?

protected void Page_Load(object sender, EventArgs e)
        {

            ShoppingCart Cart = ShoppingCartManager.GetCurrentShoppingCart(ShoppingCartTypeEnum.ShoppingCart);
            decimal shoppingCartSubTotalDiscount;
            decimal shoppingCartSubTotal = ShoppingCartManager.GetShoppingCartSubTotal(Cart, NopContext.Current.User, out shoppingCartSubTotalDiscount);
            decimal shoppingCartSubTotalConverted = CurrencyManager.ConvertCurrency(shoppingCartSubTotal, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
            lblSubTotalAmount.Text = LocalizationManager.GetCurrencyString(shoppingCartSubTotalConverted, true, NopContext.Current.WorkingCurrency);
              
          
        }
15 years ago
Refresh your page after updaing shopping cart: CommonHelper.ReloadCurrentPage();
15 years ago
That doesn't seem to work. The label is in the header.ascx and the code is on page load of the header.
15 years ago
I have put the code in the prerender and seems to be working
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.