Adding SKU to the Search in Admin

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
MMIKAL
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 32
Joined: Thu Mar 11, 2010 9:30 am

Adding SKU to the Search in Admin

Post by MMIKAL » Wed Jul 14, 2010 11:46 am

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

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Adding SKU to the Search in Admin

Post by mazhar » Thu Jul 15, 2010 6:04 am

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.

MMIKAL
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 32
Joined: Thu Mar 11, 2010 9:30 am

Re: Adding SKU to the Search in Admin

Post by MMIKAL » Thu Jul 15, 2010 3:14 pm

Thanks Mazhar , it works exactly the way it is suppose to. Appriciate your help.

User avatar
rhuffman
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 24
Joined: Thu May 19, 2005 6:36 pm
Location: Dublin, OH
Contact:

Re: Adding SKU to the Search in Admin

Post by rhuffman » Wed Jul 21, 2010 7:57 am

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.

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Adding SKU to the Search in Admin

Post by mazhar » Wed Jul 21, 2010 8:09 am

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.

User avatar
rhuffman
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 24
Joined: Thu May 19, 2005 6:36 pm
Location: Dublin, OH
Contact:

Re: Adding SKU to the Search in Admin

Post by rhuffman » Wed Jul 21, 2010 2:34 pm

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

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Adding SKU to the Search in Admin

Post by mazhar » Thu Jul 22, 2010 5:01 am

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.

User avatar
rhuffman
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 24
Joined: Thu May 19, 2005 6:36 pm
Location: Dublin, OH
Contact:

Re: Adding SKU to the Search in Admin

Post by rhuffman » Thu Jul 22, 2010 7:07 am

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.

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Adding SKU to the Search in Admin

Post by mazhar » Thu Jul 22, 2010 7:25 am

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.

User avatar
rhuffman
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 24
Joined: Thu May 19, 2005 6:36 pm
Location: Dublin, OH
Contact:

Re: Adding SKU to the Search in Admin

Post by rhuffman » Thu Jul 22, 2010 2:00 pm

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

Post Reply