On the product page, we used a simple form to display an Add to comparison list button. We used the ProductListHandler.addProduct
method to add the product the user is viewing to a list of products to compare.
A View comparison list link is displayed on the page if there are products in the comparison list. Once a user adds a product to the list, the button is changed to display Remove from list and to use the ProductListHandler.removeProduct
method so that the product can be removed from the list.
Below is the code we used to implement the Product Comparisons section on the product page.
<dsp:form action="product.jsp" method="post"> <tr> <td bgcolor="#E5E5E5"> <input name="id" type="hidden" value="<dsp:valueof param="element.repositoryId"/>"> <dsp:input bean="CartModifierFormHandler.SessionExpirationURL" type="hidden" value="../common/session_expired.jsp"/> <dsp:input bean="CartModifierFormHandler.productId" paramvalue="product.repositoryId" type="hidden"/> <dsp:droplet name="ProductListContains"> <dsp:param bean="ProductList" name="productList"/> <dsp:param name="productID" param="element.repositoryId"/> <dsp:oparam name="true"> <dsp:input bean="ProductListHandler.productID" paramvalue="productID" type="hidden"/> <dsp:input bean="ProductListHandler.removeProduct" type="submit" value="Remove from list"/> </dsp:oparam> <dsp:oparam name="false"> <dsp:input bean="ProductListHandler.productID" paramvalue="productID" type="hidden"/> <dsp:input bean="ProductListHandler.addProduct" type="submit" value="Add to comparison list"/> </dsp:oparam> </dsp:droplet> </td> </tr> <!--check to see if there are items in comparison list--> <dsp:droplet name="IsEmpty"> <dsp:param bean="ProductList.items" name="value"/> <dsp:oparam name="false"> <tr> <td><span class=smallb><dsp:a href="compare.jsp">View comparison list</dsp:a></td> </tr> </dsp:oparam> </dsp:droplet> </dsp:form>