• Welcome to KonaKart Community Forum. Please login or sign up.
 

Multiple AddToCartForm on the same page

Started by virtueed, December 03, 2007, 06:47:22 pm

Previous topic - Next topic

virtueed

Hi,
I would like to have multiple AddToCartForm on the same page to let the customer add products to the cart from special offers pages. I've tried with the standard AddToCartForm but it messes up all the options value, I think because every form has the same name. Do you have any suggestion on the best way to do this. Just for information the number of products in those pages will be dynamic.

Thank you and best regards,
Mirko.

ryan

Hi Mirko,

What you could try is to define multiple form beans in struts-config.xml with different names. i.e.

      <form-bean name="AddToCartForm1" type="com.konakart.forms.AddToCartForm">
      </form-bean>
      <form-bean name="AddToCartForm2" type="com.konakart.forms.AddToCartForm">
      </form-bean>
      <form-bean name="AddToCartForm3" type="com.konakart.forms.AddToCartForm">
      </form-bean>

Then in your action-mappings you use AddToCartForm1, AddToCartForm2, AddToCartForm3 etc.

Ciao,

Ryan

virtueed

Hi Ryan,
I was actually searching for a more efficient way to solve the problem but actually I've done as you suggested and it works. The only problem that I had was in the AddToCartSubmitAction.java where the productId is taken from the selectedProduct, like this:

Quoteb.setProductId(kkAppEng.getProductMgr().getSelectedProduct().getId());


I changed it, because I don't have a specific selected product, to:

Quoteb.setProductId(new Integer(acf.getProductId()).intValue());


where acf is:
Quote
AddToCartForm1 acf = (AddToCartForm1) form;
or
AddToCartForm2 acf = (AddToCartForm2) form;
or
...


based on the AddToCartForm submitted.

Thank you.

Ciao,
Mirko.




virtueed

Hi Ryan,
I've found a way to use only 1 action and 1 form bean to receive a submit from any of the forms in jsp. Form in the jsp can all have the same name and the same action. When a form is submitted the form bean associated with the action is populated correctly with the values inside the form. Than the trick is just to get the productId from the form bean and not from the engine:

Quoteb.setProductId(kkAppEng.getProductMgr().getSelectedProduct().getId());


to

Quoteb.setProductId(new Integer(acf.getProductId()).intValue());


In this way no matter what is the selected product you insert in the basket the product that has been submitted by the form.

Ciao,
Mirko.