Created
October 5, 2012 15:34
-
-
Save SitefinityGuru/3840553 to your computer and use it in GitHub Desktop.
Ecommerce Products Minimum and Maximum Quantity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AddToCartWidget.ascx.cs" Inherits="SitefinityWebApp.Templates.AddToCartWidget" %> | |
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %> | |
<asp:UpdatePanel ID="UpdatePanel" runat="server"> | |
<ContentTemplate> | |
<sf:Message runat="server" ID="addedToCartMessage" CssClass="sfMessage sfTopMsg" | |
RemoveAfter="10000" /> | |
</ContentTemplate> | |
</asp:UpdatePanel> | |
<asp:Label ID="quantityLabel" runat="server" Text='<%$Resources:OrdersResources, QuantityColon %>' | |
AssociatedControlID="quantity" CssClass="sfTxtLbl" /> | |
<asp:RequiredFieldValidator ID="quantityRequiredFieldValidator" runat="server" ControlToValidate="quantity" | |
ValidationGroup="addToCart" Display="Dynamic" CssClass="sfErrorWrp"> | |
<span class="sfError"> | |
<asp:Literal runat="server" ID="lProductQuantityIsRequired" Text="<%$Resources:OrdersResources, ProductQuantityIsRequired %>" /></span> | |
</asp:RequiredFieldValidator> | |
<asp:RangeValidator ID="quantityValidator" runat="server" MinimumValue="1" MaximumValue="9999" | |
ControlToValidate="quantity" ValidationGroup="addToCart" Type="Integer" Display="Dynamic" | |
CssClass="sfErrorWrp"> | |
<span class="sfError">Invalid Quantity</span> | |
</asp:RangeValidator> | |
<asp:TextBox ID="quantity" runat="server" CssClass="sfTxt sfQuantity" /> | |
<asp:Button ID="addToCartButton" runat="server" Text='<%$Resources:OrdersResources, AddToCart %>' | |
ValidationGroup="addToCart" CssClass="sfAddToCartBtn" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class AddToCartWidget : System.Web.UI.UserControl | |
{ | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
// only setup on first load | |
if (IsPostBack) return; | |
// Get the product url parameter | |
var itemUrl = this.GetUrlParameterString(true); | |
string redirectUrl = ""; | |
// Get the product from the Catalog | |
var manager = CatalogManager.GetManager(); | |
var product = manager.GetItemFromUrl(typeof(Product), itemUrl, out redirectUrl) as Product; | |
if (product == null) return; | |
// ensure type matches expected | |
var type = product.GetType().Name; | |
if (!type.Contains("generalproduct")) return; | |
// get min/max values and bind to validation | |
var min = product.GetValue<decimal>("Minimum"); | |
var max = product.GetValue<decimal>("Maximum"); | |
quantityValidator.MinimumValue = min.ToString(); | |
quantityValidator.MaximumValue = max.ToString(); | |
// set input value to match minimum | |
quantity.Text = min.ToString(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ShoppingCart.ascx.cs" Inherits="SitefinityWebApp.Templates.ShoppingCart" %> | |
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> | |
<%@ Register Assembly="Telerik.Sitefinity.Ecommerce" Namespace="Telerik.Sitefinity.Modules.Ecommerce.Catalog.Web.UI.Fields" | |
TagPrefix="sfCatalog" %> | |
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %> | |
<%@ Register TagPrefix="orders" Namespace="Telerik.Sitefinity.Modules.Ecommerce.Orders.Web.UI" | |
Assembly="Telerik.Sitefinity.Ecommerce" %> | |
<%@ OutputCache Duration="1" VaryByParam="*" %> | |
<%@ Import Namespace="Telerik.Sitefinity.Ecommerce" %> | |
<%@ Import Namespace="Telerik.Sitefinity.Modules.Ecommerce" %> | |
<div class="sfshoppingCartWrp"> | |
<!-- This container is used to display warning messages about set up of the widget; | |
when control is set correctly, this container is invisible --> | |
<div id="widgetStatus" runat="server" visible="false" class="sfshoppingCartStatus"> | |
<asp:Label ID="widgetStatusMessage" runat="server" /> | |
</div> | |
<asp:PlaceHolder ID="widgetBody" runat="server"> | |
<h1 class="sfshoppingCartTitle" id="widgetHeading" runat="server"> | |
<asp:Literal ID="Literal1" runat="server" Text='<%$Resources:OrdersResources, ShoppingCart %>' /> | |
</h1> | |
<sf:Message runat="server" ID="cartUpdateMessage" /> | |
<asp:PlaceHolder runat="server" ID="itemsCountPlaceholder"> | |
<div class="sfProductsInCart"> | |
<asp:Literal ID="productsCountLabel" runat="server" /> <asp:Literal | |
runat="server" Text='<%$Resources:OrdersResources, items %>' /> | |
</div> | |
</asp:PlaceHolder> | |
<telerik:RadGrid ID="shoppingCartGrid" runat="server" Skin="Basic" ShowFooter="False" | |
EnableEmbeddedBaseStylesheet="false" EnableEmbeddedSkins="false" OnItemDataBound="shoppingCartGrid_ItemDataBound"> | |
<MasterTableView AutoGenerateColumns="false" DataKeyNames="Id"> | |
<Columns> | |
<telerik:GridTemplateColumn HeaderText='' UniqueName="ProductImage" ItemStyle-CssClass="sfItmTmbCol" | |
HeaderStyle-CssClass="sfItmTmbCol"> | |
<ItemTemplate> | |
<div class="sfproductTmbWrp"> | |
<img src='<%# HttpUtility.HtmlAttributeEncode(Eval("ThumbnailUrl") as string) %>' | |
alt='<%# Eval("ThumbnailAlternativeText") %>' class="sfproductTmb" /> | |
</div> | |
</ItemTemplate> | |
</telerik:GridTemplateColumn> | |
<telerik:GridTemplateColumn HeaderText='<%$Resources:OrdersResources, ProductDescription %>' | |
UniqueName="ProductDescription" ItemStyle-CssClass="sfItmTitleCol" HeaderStyle-CssClass="sfItmTitleCol"> | |
<ItemTemplate> | |
<div class="sfItmTitleWrp"> | |
<asp:HyperLink ID="productTitleLink" runat="server" Text='<%# Eval("Title") %>' CssClass="sfItmTitle" /> | |
</div> | |
<asp:Label ID="OutOfStock" CssClass="sfItemOutOfStockMessage" Text="<%$Resources:OrdersResources, OutOfStock %>" | |
Visible="false" runat="server" /> | |
<asp:Label ID="InventoryChange" CssClass="sfItmTitleInventoryChangeCol" Text="<%$Resources:OrdersResources, InventoryChange %>" | |
Visible="false" runat="server" /> | |
<div class="sfItmLnksWrp"> | |
<asp:LinkButton ID="removeButton" runat="server" Text='<%$Resources:OrdersResources, Remove %>' | |
CommandName="remove" CssClass="sfItmRemove" /> | |
</div> | |
</ItemTemplate> | |
</telerik:GridTemplateColumn> | |
<telerik:GridTemplateColumn HeaderText='<%$Resources:OrdersResources, ProductOptions %>' | |
UniqueName="Options" ItemStyle-CssClass="sfItmOptionsCol" HeaderStyle-CssClass="sfItmOptionsCol"> | |
<ItemTemplate> | |
<div> | |
<%# Eval("Options")%> | |
</div> | |
</ItemTemplate> | |
</telerik:GridTemplateColumn> | |
<telerik:GridTemplateColumn UniqueName="BasePrice" ItemStyle-CssClass="sfSingleItmPriceCol" | |
HeaderStyle-CssClass="sfSingleItmPriceCol"> | |
<ItemTemplate> | |
<sfCatalog:DisplayPriceField ID="displayPriceField" ObjectType="Cart" ObjectId='<%# Eval("Id") %>' | |
runat="server" /> | |
</ItemTemplate> | |
</telerik:GridTemplateColumn> | |
<telerik:GridTemplateColumn UniqueName="ProductQuantity" HeaderText="<%$Resources:OrdersResources, Quantity %>" | |
ItemStyle-CssClass="sfItmQuantityCol" HeaderStyle-CssClass="sfItmQuantityCol"> | |
<ItemTemplate> | |
<span>x</span> | |
<asp:HiddenField ID="cartDetailId" runat="server" /> | |
<asp:TextBox ID="quantity" runat="server" Text='<%# Eval("Quantity") %>' CssClass="sfTxt" /> | |
<asp:RangeValidator ID="quantityValidator" runat="server" MinimumValue="0" MaximumValue="9999" | |
ControlToValidate="quantity" Type="Integer" Display="Dynamic" CssClass="sfErrorWrp"> | |
<span class="sfError"> | |
<asp:Literal ID="Literal2" runat="server" Text="<%$Resources: OrdersResources, ProductQuantityIsInvalidInShoppingCart %>" /> | |
</span> | |
</asp:RangeValidator> | |
</ItemTemplate> | |
</telerik:GridTemplateColumn> | |
<telerik:GridTemplateColumn UniqueName="NewPrice" HeaderText='<%$Resources:OrdersResources, Price %>' | |
ItemStyle-CssClass="sfItmPriceCol" FooterStyle-CssClass="sfItmPriceCol" HeaderStyle-CssClass="sfItmPriceCol"> | |
<ItemTemplate> | |
<asp:Label ID="newPriceLabel" runat="server" Text='<%# EcommerceControlExtensions.ToCurrencyString((decimal)Eval("DisplayTotal")) %>' | |
CssClass="sfTxtLbl" /> | |
</ItemTemplate> | |
</telerik:GridTemplateColumn> | |
</Columns> | |
</MasterTableView> | |
</telerik:RadGrid> | |
<asp:Panel ID="shoppingCartGridFooter" runat="server" CssClass="sfShoppingCartGridFooter sfClearfix"> | |
<asp:UpdatePanel runat="server" UpdateMode="Conditional" ID="outerCouponCodeUpdatePanel"> | |
<ContentTemplate> | |
<div class="sfShoppingCartCouponEntryField"> | |
<orders:couponcodeentryview id="couponCodeEntryView" runat="server" ischangemode="False" /> | |
</div> | |
</ContentTemplate> | |
</asp:UpdatePanel> | |
<asp:UpdatePanel ID="UpdatePanel1" runat="server"> | |
<ContentTemplate> | |
<div class="sfShoppingCartTotal"> | |
<table class="sfShoppingCartDiscountList"> | |
<tbody> | |
<tr runat="server" id="beforeDiscountRow"> | |
<th> | |
<asp:Label ID="Label1" runat="server" Text="<%$ Resources:OrdersResources, BeforeDiscounts %>" | |
CssClass="sfTxtLbl" />: | |
</th> | |
<td> | |
<asp:Label ID="totalPrice" runat="server" Text="" CssClass="sfTxtLbl" /> | |
</td> | |
</tr> | |
<orders:discountlist runat="server" id="discountRows" /> | |
</tbody> | |
</table> | |
</div> | |
<div class="sfTotalRowWrp"> | |
<asp:Label ID="productTotalQuantity" runat="server" /> | |
<asp:Label ID="subTotalLabel" runat="server" Text='<%$Resources:OrdersResources, Subtotal %>' | |
CssClass="sfTxtLbl" />: <strong class="sfPriceTotal"> | |
<asp:Label ID="afterDiscountPrice" runat="server" Text="" CssClass="sfTxtLbl" /></strong> | |
</div> | |
</ContentTemplate> | |
</asp:UpdatePanel> | |
<asp:LinkButton ID="updateButton" Text="<%$Resources:OrdersResources, Update %>" | |
runat="server" CssClass="sfshoppingCartUpdateLnk" /> | |
</asp:Panel> | |
<asp:Panel ID="noProductsInShoppingCartPanel" runat="server" Visible="false" CssClass="sfNoProductsInCartMsg"> | |
<asp:Literal ID="Literal3" runat="server" Text='<%$Resources:OrdersResources, NoProductsInShoppingCart %>' /> | |
</asp:Panel> | |
<div class="sfshoppingCartBtnsWrp sfClearfix"> | |
<asp:HyperLink ID="continueShoppingLink" runat="server" Text='<%$Resources:OrdersResources, ContinueShopping %>' | |
NavigateUrl="#" CssClass="sfBackBtn" /> | |
<div id="checkoutButtonDiv" runat="server"> | |
<asp:Button ID="checkoutButton" runat="server" Text='<%$Resources:OrdersResources, Checkout %>' | |
CssClass="sfCheckoutBtn" /> | |
</div> | |
</div> | |
</asp:PlaceHolder> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class ShoppingCart : System.Web.UI.UserControl | |
{ | |
protected void shoppingCartGrid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) | |
{ | |
if (e.Item.ItemType == Telerik.Web.UI.GridItemType.Item || e.Item.ItemType == Telerik.Web.UI.GridItemType.AlternatingItem) | |
{ | |
var item = e.Item.DataItem as CartDetail; | |
if (item == null) return; | |
// Get the actual product | |
var manager = CatalogManager.GetManager(); | |
var product = manager.GetProduct(item.ProductId); | |
if (product == null) return; | |
// only memberships have min/max | |
var type = product.GetType().Name; | |
if (!type.Contains("generalproduct")) return; | |
var validation = e.Item.FindControl("quantityValidator") as RangeValidator; | |
if (validation == null) return; | |
validation.MinimumValue = product.GetValue("Minimum").ToString(); | |
validation.MaximumValue = product.GetValue("Maximum").ToString(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment