Add products to Wishlist from the Thumbnails view
Hi team,
I'd like to know how I can add an 'Add to wishlist button' beneath each product when I'm in the 'Thumbnail' mode.
I have a button for 'Add to cart', based on a blogpost.
Is this possible?
Daniel
Hi Daniel,
It is possible with some modifications. The default AddToWishlistWidget is expecting some things that won't be there in the thumbnails view.
First you need to create a new class that inherits from AddToWishlistWidget. You can't override the default event handler for the AddToWishlistButton.Command event but you can override InitializeControls and point it to your modified event handler.
protected
override
void
InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container)
AddToWishlistButton.Command +=
new
CommandEventHandler(AddToWishlistButton_Command2);
protected
void
AddToWishlistButton_Command2(
object
sender, CommandEventArgs e)
int
quantity = 1;
OptionsDetails optionDetails =
new
OptionsDetails();
string
defaultCurrencyName = Config.Get<EcommerceConfig>().DefaultCurrency;
Guid userId = SecurityManager.GetCurrentUserId();
try
if
(userId !=
null
&& userId != Guid.Empty)
IWishlistAdder wishlistAdder =
new
WishlistAdder();
wishlistAdder.AddItemToWishlist(
this
.Product, optionDetails, quantity, defaultCurrencyName, userId);
this
.AddedToWishlistMessage.ShowPositiveMessage(Res.Get<OrdersResources>(
"AddedToWishlist"
));
else
throw
new
ArgumentException(Res.Get<OrdersResources>(
"NotAddedToWishlistAnonymous"
));
catch
(ArgumentException ex)
this
.AddedToWishlistMessage.ShowNegativeMessage(ex.Message);
catch
(Exception)
this
.AddedToWishlistMessage.ShowNegativeMessage(Res.Get<OrdersResources>(
"NotAddedToWishlist"
));
<%@ Control Language="C#" %>
<%@ Import Namespace="Telerik.Sitefinity.Model" %>
<%@ Register TagPrefix="sfCatalog" Namespace="Telerik.Sitefinity.Modules.Ecommerce.Catalog.Web.UI.Fields" Assembly="Telerik.Sitefinity.Ecommerce"%>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.ContentUI" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.Comments" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.PublicControls.BrowseAndEdit" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Modules.Ecommerce.Catalog.Web.UI" Assembly="Telerik.Sitefinity.Ecommerce" %>
<%@ Register TagPrefix="sfwa" Namespace="SitefinityWebApp.UserControls.AddToWishlist" Assembly="SitefinityWebApp" %>
<
div
id
=
"widgetStatus"
runat
=
"server"
visible
=
"false"
class
=
"sfErrorSummary sfTopMsg"
>
<
asp:Label
ID
=
"widgetStatusMessage"
runat
=
"server"
/>
</
div
>
<
asp:Placeholder
id
=
"widgetBody"
runat
=
"server"
>
<
div
class
=
"sfClearfix"
>
<
div
class
=
"sfProductsSortByWrp"
id
=
"productSortControlWrp"
runat
=
"server"
>
<
sf:SortProductsControl
ID
=
"sortProductsControl"
runat
=
"server"
/>
</
div
>
<
sf:TotalProductsControl
runat
=
"server"
ID
=
"totalProductsControlTop"
CssClass
=
"sfCatalogTotalCount"
/>
<
sf:Pager
id
=
"topPager"
runat
=
"server"
DisplayCount
=
"3"
ShowPrevAndNext
=
"true"
CssClass
=
"sfCatalogPager"
/>
<
sf:ItemsPerPageSelector
ID
=
"itemsPerPageSelectorTop"
runat
=
"server"
GroupingKey
=
"Products"
CssClass
=
"sfitemsPerPageWrp"
/>
<
telerik:RadListView
ID
=
"productsListView"
runat
=
"server"
ItemPlaceholderID
=
"ProductContainer"
EnableEmbeddedSkins
=
"false"
EnableEmbeddedBaseStylesheet
=
"false"
>
<
LayoutTemplate
>
<
ul
class
=
"sfproductsList"
>
<
asp:PlaceHolder
ID
=
"ProductContainer"
runat
=
"server"
/>
</
ul
>
</
LayoutTemplate
>
<
ItemTemplate
>
<
li
class
=
"sfproductListItem"
>
<
div
class
=
"sfproductTmbWrp"
>
<
sf:DetailsViewHyperLink
ID
=
"thumbnailLink"
runat
=
"server"
ImageUrl='<%# Eval("ThumbnailUrl") %>' Text='<%# Eval("ThumbnailAlternativeText") %>' ToolTip='<%# Eval("Title") %>' />
</
div
>
<
h2
class
=
"sfproductTitle"
>
<
sf:DetailsViewHyperLink
Text='<%# (Eval("Title").ToString()).TruncateString(56, SitefinityExtensions.TruncateOptions.IncludeEllipsis) %>' runat="server" CssClass="sfproductTitleLnk" />
</
h2
>
<
div
class
=
"sfproductPrice"
>
<
sfCatalog:DisplayPriceField
id
=
"displayPriceField"
ObjectType
=
"Product"
ObjectId='<%# Eval("Id") %>' runat="server" />
</
div
>
<%--NOTE: Uncomment the next line to display custom product fields--%>
<%--<
sf:ProductDynamicFields
id
=
"productDynamicFields"
runat
=
"server"
></
sf:ProductDynamicFields
>--%>
<
div
class
=
"sfAddToWishlistWidget"
>
<
sfwa:AddToWishlistWidgetCustom
ID
=
"addToWishlistWidget"
ProductId='<%# Eval("Id") %>' runat="server" />
</
div
>
</
li
>
</
ItemTemplate
>
</
telerik:RadListView
>
<
sf:TotalProductsControl
runat
=
"server"
ID
=
"totalProductsControlBottom"
CssClass
=
"sfCatalogTotalCount"
/>
<
sf:Pager
id
=
"pager"
runat
=
"server"
DisplayCount
=
"3"
ShowPrevAndNext
=
"true"
CssClass
=
"sfCatalogPager"
/>
<
sf:ItemsPerPageSelector
ID
=
"itemsPerPageSelectorBottom"
runat
=
"server"
GroupingKey
=
"Products"
CssClass
=
"sfitemsPerPageWrp"
/>
</
div
>
</
asp:Placeholder
>
Hi Randy,
Thanks for your solution. I had thought of creating a class and inherit from the AddToWishlistWidget, but I thought that maybe there would be another way, like how it is done with the AddToCart widget.
I'm already have so much customizations... ;)
Anyway, I'm going to try this.
Kind regards,
Daniel
Hello Daniel,
Sounds good. Let me know if you have more questions.
Greetings,
Randy Hodge
the Telerik team
i tried this. but i got the error 'Error parsing the template'. plz send me example
Hello Cormac,
Clear our app_Data/sitefinity/logs. Reproduce the error parsing the template and paste the new entry here. We can see what exactly the error is and help you get past it.
Regards,