Page 1 of 1
Adding SKU to the Search in Admin
Posted: Wed Jul 14, 2010 11:46 am
by MMIKAL
Hi guys
The product listing on admin page shows only names, is it possible to show for
example SKU & Name in that page, say when product is selected?
Thanks
Re: Adding SKU to the Search in Admin
Posted: Thu Jul 15, 2010 6:04 am
by mazhar
Yes its possible. Edit your Website/Admin/Catalog/Search.aspx file and locate following lines
Code: Select all
<asp:TemplateField HeaderText="Sort">
<HeaderStyle HorizontalAlign="center" Width="27px" />
<ItemStyle Width="27px" HorizontalAlign="Center" />
<ItemTemplate>
<img src="<%# GetCatalogIconUrl(Container.DataItem) %>" border="0" alt="<%#Eval("CatalogNodeType")%>" />
</ItemTemplate>
</asp:TemplateField>
and then update them as below
Code: Select all
<asp:TemplateField HeaderText="Sort">
<HeaderStyle HorizontalAlign="center" Width="27px" />
<ItemStyle Width="27px" HorizontalAlign="Center" />
<ItemTemplate>
<img src="<%# GetCatalogIconUrl(Container.DataItem) %>" border="0" alt="<%#Eval("CatalogNodeType")%>" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="SKU">
<HeaderStyle HorizontalAlign="center" Width="27px" />
<ItemStyle Width="27px" HorizontalAlign="Center" />
<ItemTemplate>
<%# GetSku(Container.DataItem) %>
</ItemTemplate>
</asp:TemplateField>
Finally edit your Website/Admin/Catalog/Search.aspx.cs file and add following code lines just above the very last closing curly brace "}" like
Code: Select all
protected string GetSku(Object dataItem)
{
CatalogNode catalogNode = (CatalogNode)dataItem;
if (catalogNode.CatalogNodeType == CatalogNodeType.Product)
return ((Product)catalogNode.ChildObject).Sku;
return string.Empty;
}
Save the files and now try the admin search again.
Re: Adding SKU to the Search in Admin
Posted: Thu Jul 15, 2010 3:14 pm
by MMIKAL
Thanks Mazhar , it works exactly the way it is suppose to. Appriciate your help.
Re: Adding SKU to the Search in Admin
Posted: Wed Jul 21, 2010 7:57 am
by rhuffman
This solution worked find. However, it would also be nice to be able to search by SKU.
It would also be nice to have the product browse
http://website/Admin/Catalog/Browse.aspx display the SKU by default.
Any suggestions on coding to accomplish both of these.
Re: Adding SKU to the Search in Admin
Posted: Wed Jul 21, 2010 8:09 am
by mazhar
In order show sku on browse page simply locate following code block in Admin/Catalog/Browse.aspx file
Code: Select all
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:LinkButton ID="N" runat="server" Text='<%# Eval("Name") %>' CommandName="Do_Open" CommandArgument='<%#string.Format("{0}|{1}", Eval("CatalogNodeTypeId"), Eval("CatalogNodeId"))%>'></asp:LinkButton>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" />
</asp:TemplateField>
and update it as below
Code: Select all
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:LinkButton ID="N" runat="server" Text='<%# Eval("Name") %>' CommandName="Do_Open" CommandArgument='<%#string.Format("{0}|{1}", Eval("CatalogNodeTypeId"), Eval("CatalogNodeId"))%>'></asp:LinkButton>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Sku">
<ItemTemplate>
<%#GetSku(Container.DataItem) %>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" />
</asp:TemplateField>
then edit Admin/catalog/browse.aspx.cs file and add following code just above last closing curly brace
Code: Select all
protected string GetSku(Object dataItem)
{
CatalogNode catalogNode = (CatalogNode)dataItem;
if (catalogNode.CatalogNodeType == CatalogNodeType.Product)
return ((Product)catalogNode.ChildObject).Sku;
return string.Empty;
}
This change should list the sku next to product name on browse page.
Re: Adding SKU to the Search in Admin
Posted: Wed Jul 21, 2010 2:34 pm
by rhuffman
Mazhar:
Following the directions and got the following error:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: System.Web.UI.WebControls.DataControlFieldCollection must have items of type 'System.Web.UI.WebControls.DataControlField'. 'ItemTemplate' is of type 'System.Web.UI.HtmlControls.HtmlGenericControl'.
Source Error:
Line 168:
Line 169:
Line 170: <ItemTemplate>
Line 171: <a href="<%# GetPreviewUrl(Eval("CatalogNodeType"), Eval("CatalogNodeId"), Eval("Name")) %>" Title="Preview" Target="_blank"><img src="<%# GetIconUrl("Preview.gif") %>" border="0" alt="Preview" /></a>
Line 172:
Source File: /Admin/Catalog/Browse.aspx Line: 170
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.4927; ASP.NET Version:2.0.50727.4927
Re: Adding SKU to the Search in Admin
Posted: Thu Jul 22, 2010 5:01 am
by mazhar
Make sure you modified the file accordingly. Seems like may you have replaced some unnecessary part in the file. It would be better simply locate the TemplateField for name and then after its closing tag </asp:TemplateField> try adding
Code: Select all
<asp:TemplateField HeaderText="Sku">
<ItemTemplate>
<%#GetSku(Container.DataItem) %>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" />
</asp:TemplateField>
save the file and in code file add method as described above
Code: Select all
protected string GetSku(Object dataItem)
{
CatalogNode catalogNode = (CatalogNode)dataItem;
if (catalogNode.CatalogNodeType == CatalogNodeType.Product)
return ((Product)catalogNode.ChildObject).Sku;
return string.Empty;
}
save the file and test it.
Re: Adding SKU to the Search in Admin
Posted: Thu Jul 22, 2010 7:07 am
by rhuffman
Mazhar:
Thanks you! It works exactly the way I needed. This will save us a lot of time.
One more request that's related.
In Able 5.x we were able to search by SKU. Can we add a check box in the search (browse.aspx or is it search.aspx?) that will allow us to search by sku?
Thank you.
Re: Adding SKU to the Search in Admin
Posted: Thu Jul 22, 2010 7:25 am
by mazhar
I think in catalog search this option is not available and there is no easy workaround to put it there. But SKU is considered when you search from admin search page. Simply trigger the search for SKU through search box available in admin header and it will list the product.
Re: Adding SKU to the Search in Admin
Posted: Thu Jul 22, 2010 2:00 pm
by rhuffman
Mashar:
Duuh! Way too obvious. Didn't even try in the general search.
Thanks again for your help. It is greatly appreciated.
Ray Huffman
www.DarbyCreekTrading.com