Products

Solutions

Resources

Partners

Community

About

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDNN Open Source...DNN Open Source...Module ForumsModule ForumsStoreStoreAdding Quantity box manually - Help Please!Adding Quantity box manually - Help Please!
Previous
 
Next
New Post
2/13/2008 11:26 PM
 

Ok, I've got the source code, I've added a quantity textfield in ProductDetail.ascx like this:

 

case "ADDTOCARTQTY":
                    TextBox txtAddToCartQty = new TextBox();
                    txtAddToCartQty.Text = "1";
                    txtAddToCartQty.Width = System.Web.UI.WebControls.Unit.Pixel(40);
                    return txtAddToCartQty;

 

 That all works fine, it shows the text field when I add the [ADDTOCARTQTY] in the HTML template.  I then changed the two (2) AddToCart functions (one for image button, one for link button) to pass the Quantity, but it does not work. I think it's the "FindControl" line... Can someone help me with this?? Thanks!!

Sample code that is NOT working, it always passes "1":

 

private void btnAddToCartImg_Click(object sender, ImageClickEventArgs e)
        {
            ImageButton button = (sender as ImageButton);
            if (button != null)
            {
                TextBox tQty = (button.Parent.FindControl("txtAddToCartQty") as TextBox);

                if (tQty != null)
                {
                    AddToCart(int.Parse(button.Attributes["ProductID"]), int.Parse(tQty.Text));
                }
                else
                {
                    AddToCart(int.Parse(button.Attributes["ProductID"]), 1);
                }
            }
        }

 

 

 
New Post
2/14/2008 9:49 AM
 

Hi Don,

The problem occurs because you have more than on textbox with the same id. I solved this by adding the product id. Now, I'm at my office and I do not have my pc. In some hours (~5), I will edit this post with sample code.

Gilles

Edit: Here my solution.

Open the file ProductDetail.ascx.resx and add this resource:

Name: Quantity.Text
Value: Quantity: 

Open ProductDetail.ascx.cs then inside processToken add this code:

case "ADDQUANTITY:

Label lblQuantity = new Label();
LiteralControl litQuantity = new LiteralControl(Localization.GetString("Quantity", this.LocalResourceFile)); // Here we use the resource, more simple for modify and translate
TextBox txtAddToCartQty = new TextBox();
txtAddToCartQty.ID = "txtQuantity" + productInfo.ProductID.ToString(); // Here is the key! ;-)
txtAddToCartQty.CssClass = "Store-QuantityTextBox"; // It's better to use a cssclass instead the Width property, because you can change it without rebuild
txtAddToCartQty.Text = "1";
lblQuantity.Controls.Add(litQuantity);
lblQuantity.Controls.Add(txtAddToCartQty);
return lblQuantity;

Replace Puchase by:

        private void Purchase(int productID, int quantity)
        {
            CurrentCart.AddItem(PortalId, productID, quantity);
            CartNavigation cartnav = new CartNavigation();
            StoreController storeController = new StoreController();
            StoreInfo storeInfo = storeController.GetStoreInfo(PortalId);
            cartnav.TabId = storeInfo.ShoppingCartPageID;
            Response.Redirect(cartnav.GetNavigationUrl(), false);
        }

Add this procedure:

        private int GetQuantity(string quantityID)
        {
            int quantity = 1;
            TextBox txtQuantity = (TextBox)this.FindControl(quantityID);
            if (txtQuantity != null)
            {
                if (!int.TryParse(txtQuantity.Text, out quantity)) quantity = 1;
            }
            return quantity;
        }

 Inside btnPurchase_Click and btnPurchaseImg_Click replace the call to Purchase by

Purchase(int.Parse(button.Attributes["ProductID"]), GetQuantity(("txtQuantity" + button.Attributes["ProductID"])));

Replace AddToCart by:

        private void AddToCart(int productID, int quantity)
        {
            CurrentCart.AddItem(PortalId, productID, quantity);
            Response.Redirect(catalogNav.GetNavigationUrl(), false);
        }

Inside btnAddToCart_Click and btnAddToCartImg_Click replace the call to AddItem by:

            CurrentCart.AddItem(PortalId, productID, quantity);

Rebuild the solution. It's work!

Open the file ...\DesktopModules\Store\Templates\StyleSheet\Common.css and add:

.Store-QuantityTextBox { width: 30px }

Gilles


We (team members) are Humans offering their knowledge, their work and their spare time FOR FREE to benefit the community. It would be so particularly appreciated that your messages begin with "Hello" and end with "Thank you" or any other form of politeness. Ask yourself what your reaction would be, if you were approached by me (a total stranger) on the street to ask you something without saying "Hello" nor "Thank you"? After several years of services dedicated to the community, I begin to be tired to read requests without any form of politeness.
 
New Post
2/14/2008 1:55 PM
 

Thanks Gilles, that would be greatly appreciated!

 

I look forward to your post. 

 
New Post
2/15/2008 11:05 AM
 

Hi Dom,

Did you read my response?

Gilles


We (team members) are Humans offering their knowledge, their work and their spare time FOR FREE to benefit the community. It would be so particularly appreciated that your messages begin with "Hello" and end with "Thank you" or any other form of politeness. Ask yourself what your reaction would be, if you were approached by me (a total stranger) on the street to ask you something without saying "Hello" nor "Thank you"? After several years of services dedicated to the community, I begin to be tired to read requests without any form of politeness.
 
New Post
2/17/2008 5:08 PM
 

Hi Gilles, yes, thank you very much. I added the code over the weekend, it works perfectly :-)

 

Thanks again!!

 

 
Previous
 
Next
HomeHomeDNN Open Source...DNN Open Source...Module ForumsModule ForumsStoreStoreAdding Quantity box manually - Help Please!Adding Quantity box manually - Help Please!


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out