Add new product. How to make First Catagory to be selected by default.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
14 years ago
Edited Post please read from post 3 down.



Can some help me with make the Tax box when adding new products always be ticked by default.

I tried to change the properties of the checkbox in vs2008 but it did not seem to make any difference. Do I need to change code to accompolish ths?
14 years ago
did you try editing

administration/modules/ProductInfoAdd.ascx

and changing
        <td class="adminData">
            <asp:CheckBox ID="cbIsTaxExempt" runat="server" Checked="False"></asp:CheckBox>
        </td>

to

        <td class="adminData">
            <asp:CheckBox ID="cbIsTaxExempt" runat="server" Checked="True"></asp:CheckBox>
        </td>
14 years ago
I should have read my question better before posting.

Thanks for the tip it worked although that is not what I need.

I want the Tax Catagory to have already pre-selected my default Tax catagory so I do not forget to select the it.
I have forgotten on the odd occasion and its a nessecary item.

So I'm looking at this code..

<td class="adminData">
            <asp:DropDownList ID="ddlTaxCategory" CssClass="adminInput" AutoPostBack="False"
                runat="server">
            </asp:DropDownList>
        </td>

ither that or what is the simplest way to require that a field be selcted before the form will save. I could at least at that line of code to all the required data to be filled.
14 years ago
try this - admin
configuration --> tax -->tax classes

edit the display order to suit your needs 1=top of list
14 years ago
I only have one Tax code in classes.

By default nopcommerce puts "---" as default in drop down list. Basically nothing chosen. Next down is my GST class.
14 years ago
ok, i see.

i looked at the file - not sure, but you could try the following:

this is NOT tested

go tho the codebehind for       ProductInfoAdd.ascx

UNTESTED

find
            this.ddlTaxCategory.Items.Clear();
            ListItem itemTaxCategory = new ListItem("---", "0");

and change to

            this.ddlTaxCategory.Items.Clear();
            ListItem itemTaxCategory = new ListItem("0");

you will need to REBUILD the store once you have done this
14 years ago
Tested

("---", "0")  The output is    ---, GST  <- This is list box first line comma second line
("0")  The Output is    0
("GST") The Output is     GST, GST
() The Output is   blank, GST

So none of these options I above hve worked. Any more suggestions.

Thanks
13 years ago
sorry :)   1 more guess -  try this instead

            this.ddlTaxCategory.Items.Clear();
            ListItem itemTaxCategory = new ListItem("0", "---");
13 years ago
To select the first tax category when adding a new product, edit file: Administration\Modules\ProductInfoAdd.ascx.cs

See 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.

.
13 years ago
Thanks for all your help haydie, it was all worth trying.

Thanks mb your solution fix my problem, I should be able to use this or similar on tsome other areas I need to change too.

Thanks everyone.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.