To select the first tax category when adding a new product, edit file:
Administration\Modules\ProductInfoAdd.ascx.csSee the update below (in this post) for a better implementation and for 1.80.In the
FillDropDowns() method, change the default code from:
this.ddlTaxCategory.Items.Clear();
ListItem itemTaxCategory = new ListItem("---", "0");
this.ddlTaxCategory.Items.Add(itemTaxCategory);
TaxCategoryCollection taxCategoryCollection = TaxCategoryManager.GetAllTaxCategories();
foreach (TaxCategory taxCategory in taxCategoryCollection)
{
ListItem item2 = new ListItem(taxCategory.Name, taxCategory.TaxCategoryID.ToString());
this.ddlTaxCategory.Items.Add(item2);
}
to the following:
this.ddlTaxCategory.Items.Clear();
TaxCategoryCollection taxCategoryCollection = TaxCategoryManager.GetAllTaxCategories();
if (taxCategoryCollection.Count == 0)
{
ListItem itemTaxCategory = new ListItem("---", "0");
this.ddlTaxCategory.Items.Add(itemTaxCategory);
}
else
{
foreach (TaxCategory taxCategory in taxCategoryCollection)
{
ListItem item2 = new ListItem(taxCategory.Name, taxCategory.TaxCategoryID.ToString());
this.ddlTaxCategory.Items.Add(item2);
}
}
This will remove the "---" (0) entry from the tax category list and the first tax class will be displayed and selected. If you don't have any tax classes, then the "---" (0) entry is inserted (this is needed so that the product can be created with a tax category ID of 0 if there are no tax classes). If you have more than one tax category, you can control which is selected first with the tax classes display order (Administration > Configuration > Tax > Tax Classes).
This is for version 1.50 and you will need to recompile the solution. Tested (adding products) with one tax category, no tax category, and multiple tax categories with this change.
----------------------------------------------------------
UPDATE (22-NOV-10)There is a better way to implement this change; by moving where the "---" (0) entry is inserted into the list to after the tax categories have been added. This way you can choose no tax category (the "---" entry) for a product -something that couldn't be done with the above change since it removed the entry.
In the
FillDropDowns() method, change the default code from (move the underlined code):
this.ddlTaxCategory.Items.Clear();
ListItem itemTaxCategory = new ListItem("---", "0");
this.ddlTaxCategory.Items.Add(itemTaxCategory);
var taxCategoryCollection = TaxCategoryManager.GetAllTaxCategories();
foreach (TaxCategory taxCategory in taxCategoryCollection)
{
ListItem item2 = new ListItem(taxCategory.Name, taxCategory.TaxCategoryId.ToString());
this.ddlTaxCategory.Items.Add(item2);
}
to the following:
this.ddlTaxCategory.Items.Clear();
var taxCategoryCollection = TaxCategoryManager.GetAllTaxCategories();
foreach (TaxCategory taxCategory in taxCategoryCollection)
{
ListItem item2 = new ListItem(taxCategory.Name, taxCategory.TaxCategoryId.ToString());
this.ddlTaxCategory.Items.Add(item2);
}
ListItem itemTaxCategory = new ListItem("---", "0");
this.ddlTaxCategory.Items.Add(itemTaxCategory);
By moving the 'no tax category' entry ("---") to the end of the list, the first tax category in the list is displayed first and used when the product is saved.
This change is for 1.80 and you will need to recompile the project.
.