Setting the RestrictedQuantity of the Upsell Item will work if this is the only instance where you will have the item in the cart. If you wish to allow the purchase of this item separately (and in any quantity) then you will need to implement something like the following:
This is an example pulled directly from Viewing Source of a shoppingcart.aspx page. The below snippet is the <table> that was generated from the cart.DisplayItems() function.
HTML Code:
<table width="100%" cellpadding="2" cellspacing="0" border="0">
<tr>
<td align="left" valign="middle"><b>Product</b></td>
<td align="center" valign="middle"><b>Quantity</b></td>
<td align="right" valign="middle"><b>Sub Total:</b></td>
</tr>
<tr>
<td colspan="3"><hr style="height: 1px; width:100%; color: #DDDDDD;"></td>
</tr>
<tr>
<td align="left" valign="top">
<a href="p-23-sweaters-all-styles.aspx">
<b>Sweaters-All styles-Cardigan-V-neck</b></a>
<br/>SKU: <br/>Size: Youth Lg(14-16)
</td>
<td align="center" valign="top">
<input type="text" name="Quantity_173" id="Quantity_173" size="4" value="1" maxlength="4" >
<input type="submit" name="bt_Delete" class="CartDeleteButton" value="Delete" onClick="document.getElementById('Quantity_173').value='0';">
</td>
<td align="right" valign="top">$27.00</td>
</tr>
<tr>
<td colspan="3"><hr style="height: 1px; width:100%; color: #DDDDDD;"></td>
</tr>
<tr>
<td align="left" valign="top">
<a href="p-96-pants.aspx"><b>Pants</b></a>
<br/>SKU: 7121<br/>Size: 7H [+$7.50]
</td>
<td align="center" valign="top">
<input type="text" name="Quantity_174" id="Quantity_174" size="4" value="1" maxlength="4" >
<input type="submit" name="bt_Delete" class="CartDeleteButton" value="Delete" onClick="document.getElementById('Quantity_174').value='0';">
</td>
<td align="right" valign="top">$26.00</td>
</tr>
</table>
What you will need to do is create a custom class in the App_Code folder. We will call it customlogic.cs. In that class we will create a method:
Code:
public static string DisplayCartItems(Customer ViewingCustomer, bool ShowItemDeleteButton, ShoppingCart cart){...}
Notice that we have removed the first parameter. As we are making this determination ourselves on a per item basis we do not need a parameter to make the determination for all items. Also notice we have added a ShoppingCart class parameter.
Replace the line of code:
Code:
CartItems.Text = cart.DisplayItems(true, ThisCustomer, true);
with:
Code:
CartItems.Text = customlogic.DisplayCartItems(ThisCustomer, true, cart);
This will call our new custom function instead of the built-in cart method.
For our custom function we will want to do something like this (keep in mind our goal is to generate the exact same <table> as the original function with the exception of the quantity field):
Code:
public static string DisplayCartItems(Customer ViewingCustomer, bool ShowItemDeleteButton, ShoppingCart cart)
{
StringBuilder sb = new StringBuilder();
sb.Append("<table width=\"100%\" cellpadding=\"2\" cellspacing=\"0\" border=\"0\">");
sb.Append("<tr>");
sb.Append("<td align=\"left\" valign=\"middle\"><b>Product</b></td>");
sb.Append("<td align=\"left\" valign=\"middle\"><b>Quantity</b></td>");
sb.Append("<td align=\"left\" valign=\"middle\"><b>Sub Total:</b></td>");
sb.Append("</tr>");
foreach (CartItem ci in cart.CartItems)
{
sb.Append("<tr>");
sb.Append("<td colspan=\"3\"><hr style=\"height: 1px; width: 100%; color: #DDDDDD;\"></td>");
sb.Append("</tr>");
sb.Append("<tr>");
sb.Append("<td align=\"left\" valign=\"top\">");
// INSERT LOGIC HERE TO GENERATE IMAGE (IF DESIRED) AND PRODUCT NAME/LINK
sb.Append("</td>");
sb.Append("<td align=\"left\" valign=\"top\">");
// INSERT LOGIC HERE TO DETERMINE IF THIS ITEM WILL DISPLAY AN EDITABLE TEXTBOX FOR QUANTITY AND A DELETE BUTTON OR ELSE SIMPLY A LABEL
sb.Append("</td>");
sb.Append("<td align=\"left\" valign=\"top\">");
// INSERT LOGIC HERE TO GENERATE PRODUCT PRICE
sb.Append("</td>");
sb.Append("</tr>");
}
sb.Append("</table>");
return sb.ToString();
}
HTH
Edited to: Insert missing sb.Append("<tr>"); line in code.