The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.
Sitefinity provides different options for configuring taxes based on location and and tax class for products. Some cases require a user to be exempt from taxes, for example in a B2B scenario.
This can easily be achieved by creating a new tax class for products that is tax exempt. It will not be applied to any products, we need to be able to modify the products in the cart to use this class.
A simple widget is placed on the checkout page that will perform the following:
The control can be placed on the Checkout page to ensure that when the user is done shopping, the taxes will be altered accordingly.
Here is the code of the control:
using
System;
using
System.Linq;
using
System.Web;
using
Telerik.Sitefinity.Ecommerce.Orders.Model;
using
Telerik.Sitefinity.Modules.Ecommerce;
using
Telerik.Sitefinity.Modules.Ecommerce.Orders;
using
Telerik.Sitefinity.Security;
using
Telerik.Sitefinity.Security.Claims;
using
Telerik.Sitefinity.Security.Model;
using
Telerik.Sitefinity.Services;
namespace
SitefinityWebApp
{
public
partial
class
RemoveTax : System.Web.UI.UserControl
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
var currentUser = ClaimsManager.GetCurrentIdentity();
var exempt = IsUserInRole(currentUser.Name,
"Exempt"
);
HttpCookie shoppingCartCookie = SystemManager.CurrentHttpContext.Request.Cookies[EcommerceConstants.OrdersConstants.ShoppingCartIdCookieName];
if
(exempt && shoppingCartCookie!=
null
)
{
var oMan = OrdersManager.GetManager();
TaxClass taxClass = oMan.GetTaxClasses().Where(t => t.Title ==
"Exempt"
).SingleOrDefault();
var cartId =
new
Guid(shoppingCartCookie.Value);
var cartOrder = oMan.GetCartOrder(cartId);
var details = oMan.GetCartDetails().Where(d => d.Parent.Id == cartOrder.Id);
foreach
(var item
in
details)
{
item.TaxClassId = taxClass.Id;
item.TaxRate = 0;
}
cartOrder.EffectiveTaxRate = 0;
cartOrder.Tax = 0;
oMan.SaveChanges();
}
}
public
static
bool
IsUserInRole(
string
userName,
string
roleName)
{
bool
isUserInRole =
false
;
UserManager userManager = UserManager.GetManager();
RoleManager roleManager = RoleManager.GetManager(
"Default"
);
bool
userExists = userManager.UserExists(userName);
bool
roleExists = roleManager.RoleExists(roleName);
if
(userExists && roleExists)
{
User user = userManager.GetUser(userName);
isUserInRole = roleManager.IsUserInRole(user.Id, roleName);
}
return
isUserInRole;
}
}
}
You can also find the full sample on Github:Remove Tax.
Atanas Valchev is a Tech Support Engineer at Telerik. He joined the Sitefinity Support team in March 2012.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites
Progress collects the Personal Information set out in our Privacy Policy and the Supplemental Privacy notice for residents of California and other US States and uses it for the purposes stated in that policy.
You can also ask us not to share your Personal Information to third parties here: Do Not Sell or Share My Info
We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.
Thank you for your continued interest in Progress. Based on either your previous activity on our websites or our ongoing relationship, we will keep you updated on our products, solutions, services, company news and events. If you decide that you want to be removed from our mailing lists at any time, you can change your contact preferences by clicking here.