an ASP.NET Open Source CMS & eCommerce platform
Search:
Skip Navigation LinksHome > DotShoppingCart Forums > Support > Using DotShoppingCart > Apply coupon to a whole category
Last Post 11/4/2009 11:16:46 AM By lukezy. 8 replies.
10/13/2009 7:00:09 AM
bansal_db
Posts: 181
Joined: 4/13/2009
Apply coupon to a whole category
Is there a way to apply coupon on the whole category instead of one product?
 
or apply to a bunch of products?
 
Thanks
10/13/2009 9:30:49 AM
lukezy
Posts: 2109
Joined: 6/12/2007
Location:WA, US
Re: Apply coupon to a whole category
No. You will need to do customization.
DotShoppingCart Staff
10/29/2009 11:24:10 AM
bansal_db
Posts: 181
Joined: 4/13/2009
Re: Apply coupon to a whole category
Hey Luke, I am trying to customize this.
 
I modified the coupon.ascx to display new field for category. I added the categories as the dropdownlist. Is there any better way to do this?
 
<asp:TemplateField headertext="<%$ Resources:Common,ApplyToCategory %>">
                            <EditItemTemplate>
                                <span class="sign"></span>
                                <asp:DropDownList id="categoryID" runat="server" Width="206px">
                                </asp:DropDownList>
                            </EditItemTemplate>
                        </asp:TemplateField>
 
 
protected void btnAdd_Click(object sender, EventArgs e)
    {
        mvwMain.SetActiveView(vwAdd);
        dvwCoupon.ChangeMode(DetailsViewMode.Insert);

        //getting all the categories
        Category[] categories = Category.GetAll();
 
//storing the category ids and category names
        string[] categoryIds = new string[categories.Length + 1];
        string[] categoryNames = new string[categories.Length + 1];

        //first element in the dropdown list should be empty
        categoryIds[0] = "0";
        categoryNames[0] = "Everything";

        for (int i = 0; i < categories.Length; i++)
        {
            categoryIds[i + 1] = categories[i].CategoryId.ToString();
            categoryNames[i + 1] = categories[i].Name;
        }

        //bind that string array to dropdownlist
        categoryID.DataSource = categoryNames;
        categoryID.DataBind();
 
}
 
 
This loads fine on the page but i need to change the edit coupon part too. When i go edit, its displaying the empty list. I don't know how to bind the list when someone is trying to edit the coupon and set the selected index from the database.
 
Can you please help?
 
Thanks
10/29/2009 12:03:51 PM
lukezy
Posts: 2109
Joined: 6/12/2007
Location:WA, US
Re: Apply coupon to a whole category
You can use ObjectDataSource without writing code.
 
<asp:ObjectDataSource id="odsCategory" runat="server" typename="DotShoppingCart.Commercial.Core.Category" selectmethod="GetAll"></asp:ObjectDataSource>
 
<asp:DropDownList datasourceid="odsCategory" datatextfield="FullPath" datavaluefield="CategoryId"
 
 

 

 

DotShoppingCart Staff
10/29/2009 12:22:28 PM
bansal_db
Posts: 181
Joined: 4/13/2009
Re: Apply coupon to a whole category
I need to add one more element to the list, Everything or NULL. How would i do that?
 
Also when i am updating or editing the coupon, i need the selected index to be the category assigned to the coupon already.
 
How would i do that?
 
Thanks
 
 
 
10/29/2009 2:23:36 PM
bansal_db
Posts: 181
Joined: 4/13/2009
Re: Apply coupon to a whole category
Also, is there a function that i can use to get all the category ids to which a product belongs to?
 
If heriracy is like this
 
Category1-->Sub Category-->Product
 
Is there a function i can use to which i provide the product id and it returns an array of both the category ids??
 
because if the coupon is applied to category1, product_category_map table only has the relationship between SubCategory and Product.
 
thanks
 
 
I took care of the above problem.
 
 
I still need help with this
 
I need to add one more element to the list, Everything or NULL. How would i do that?
 
Also when i am updating or editing the coupon, i need the selected index to be the category assigned to the coupon already.
 
Also another error started showing up for me.
 
What does CoreHelper.GetCouponAmount(Cart) check for???
 
System.IndexOutOfRangeException: Index was outside the bounds of the array.

Source Error:

<table bgcolor="#ffffcc" style="width: 645px; height: 13px;"> <tbody> <tr> <td>
Line 62:             {
Line 63:                 pnlGiftWrap.Visible = CommercialStoreConfigurationSection.GetSection().GiftWrapEnabled;
Line 64:                 couponDiscount = CoreHelper.GetCouponAmount(Cart);
Line 65: giftCertificateTotal = CoreHelper.GetGiftCertificatesAmount(); Line 66: UpdateTotals();
</td> </tr> </tbody> </table>
10/30/2009 10:58:49 AM
bansal_db
Posts: 181
Joined: 4/13/2009
Re: Apply coupon to a whole category
Hey Luke,
 
I fixed the error. Can you please help with
 
1.) add one more element to the dropdown list, everythinng or NULL.
2.) when updating the coupon, the selected value should display the assigned category to the coupon.
 
Thanks
11/3/2009 7:07:23 AM
bansal_db
Posts: 181
Joined: 4/13/2009
Re: Apply coupon to a whole category
Luke Anything on these two things?
 
Thanks
11/4/2009 11:16:46 AM
lukezy
Posts: 2109
Joined: 6/12/2007
Location:WA, US
Re: Apply coupon to a whole category
Sorry, we are busy in getting V4 out of door. You cannot expect us to answer every customization related question in a timely fashion. I will take a look at this once I have time.
DotShoppingCart Staff