Want to add qty numerictextbox to category template

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 年 前
Problem is how do I find the qty control while in a listview in a web user control?

I tried a bunch of ideas and I just can't seem to figure it out. Any help would really be appreciated.
13 年 前
Hi,
I am not sure if I understand what do you want to achieve.
If you want to add a numeric text boxes with quantity of product to order directly to the category templates, you should add it to the Modules/ProductBox1.ascx and Modules/ProductBox2.ascx.
I did it in nopCommerce 1.8.

Modules/ProductBox1.ascx: I added following piece of code instead of the simple Add to Cart button.

<tr>
                    <td>
                        <nopCommerce:NumericTextBox runat="server" ID="txtQuantity" Value="1" RequiredErrorMessage="<% $NopResources:Products.EnterQuantity %>"
                            RangeErrorMessage="<% $NopResources:Products.QuantityRange %>" MinimumValue="1"
                            MaximumValue="999999" Width="50" ValidationGroup="ProductDetails" />
                    </td>
                    <td>
                        <asp:Button runat="server" ID="btnAddToCart" OnCommand="btnAddToCart_Click" Text="<% $NopResources:Products.AddToCart %>"
                            ValidationGroup="ProductDetails" CommandArgument='<%# Eval("ProductId") %>' CssClass="productgridaddtocartbutton" />
                    </td>
</tr>


Then I adjusted also the btnAddToCart_Click event handler in code behind to use the value typed in to the newly added field.
Hope this helped a little.
13 年 前
Thats just what I want to do but the event handler is where I'm having problems. Could you please post that information?
13 年 前
Ok, just the beginning of the method:

protected void btnAddToCart_Click(object sender, CommandEventArgs e)
    {
      if (Page.IsValid)
      {
        int productId = Convert.ToInt32(e.CommandArgument);
        try
        {
          if (this.product != null && this.product.ViewOnly)
          {
            return;
          }
          //get the quantity of the product box field
          int quantity = txtQuantity.Value;
          int productVariantId = 0;
          List<string> addToCartWarnings = null;
          if (ProductManager.DirectAddToCartAllowed(productId, out productVariantId)
          {
              //pass obtained quantity instead of 1
              addToCartWarnings = ShoppingCartManager.AddToCart(ShoppingCartTypeEnum.ShoppingCart,
                  productVariantId, string.Empty, decimal.Zero, quantity);
               if (addToCartWarnings.Count == 0)
              {
                    .....
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.