Try These Categories Fix


https://forum.kartris.com/Topic6382.aspx
Print Topic | Close Window

By jcosmo - Fri 15 Jan 2016
I tried to turn off Try These Categories by setting frontend.crossselling.trythesecategories to 0. It didn't work, and when I traced through the code to see why I found that the Try These Categories functionality wasn't using this parameter at all for determining how many categories to show. I corrected this through the following changes:

Updated the Stored Procedure to accept and use the number of Categories to display with the following SQL Statement:
ALTER PROCEDURE [dbo].[spKartrisCategories_GetByProductID]
(
@P_ID int,
@LANG_ID tinyint,
@numTryTheseCategories int
)
AS
SET NOCOUNT ON;
SELECT TOP (@numTryTheseCategories) vKartrisTypeCategories.CAT_ID, vKartrisTypeCategories.CAT_Name
FROM vKartrisTypeCategories INNER JOIN
tblKartrisProductCategoryLink ON vKartrisTypeCategories.CAT_ID = tblKartrisProductCategoryLink.PCAT_CategoryID
WHERE (vKartrisTypeCategories.LANG_ID = @LANG_ID) AND (tblKartrisProductCategoryLink.PCAT_ProductID = @P_ID)
GO


Updated the katrisCategoriesData.xsd data adapter to include the new parameter

Updated the CategoriesBLL.vb at line 59 to be:
Public Shared Function GetCategoriesByProductID(ByVal _ProductID As Integer, ByVal _LanguageID As Short, ByVal _numTryTheseCategories As Integer) As DataTable
Return Adptr.GetByProductID(_ProductID, _LanguageID, _numTryTheseCategories)
End Function


Updated the CarryOnShopping.ascx.vb at line 120 to be:
Sub LoadLinkedCategories()


Dim intTryTheseCategories As Integer


Try
intTryTheseCategories = CInt(GetKartConfig("frontend.crossselling.trythesecategories"))
Catch ex As Exception
intTryTheseCategories = 0
End Try


If intTryTheseCategories > 0 Then
'' Add the linked categories to a DataTable
Dim tblCategories As New DataTable
tblCategories = CategoriesBLL.GetCategoriesByProductID(_ProductID, _LanguageID, intTryTheseCategories)


'' If there is no linked categories, then exit this section.
If tblCategories.Rows.Count = 0 Then Exit Sub


'' Bind the linked categories in to rptLinkedCategories, and View its container.
phdLinkedCategories.Visible = True
rptLinkedCategories.DataSource = tblCategories.DefaultView
rptLinkedCategories.DataBind()
Else
''Hide try these categories section
phdLinkedCategories.Visible = False
End If
End Sub


This appears to be a bug fix and not new functionality, so it would be great to see these changes implemented in the next release.
By Paul - Fri 5 Feb 2016
I've approached this slightly simpler way. I've kept the sproc unchanged; at present it pulls out all categories, but in most cases products aren't going to be in more than a handful of categories, so there isn't really a performance issue returning more than we might actually need.

I've just modified the LoadLinkedCategories() sub:


Dim intLinkedCategories As Integer

Try
intLinkedCategories = CInt(GetKartConfig("frontend.crossselling.trythesecategories"))
Catch ex As Exception
intLinkedCategories = 0
End Try

If intLinkedCategories > 0 Then
'' Add the linked categories to a DataTable
Dim tblCategories As DataTable = CategoriesBLL.GetCategoriesByProductID(_ProductID, _LanguageID).Rows.Cast(Of System.Data.DataRow)().Take(intLinkedCategories).CopyToDataTable()
'dt.Rows.Cast<System.Data.DataRow>().Take(n)

'' If there is no linked categories, then exit this section.
If tblCategories.Rows.Count = 0 Then Exit Sub

'' Bind the linked categories in to rptLinkedCategories, and View its container.
phdLinkedCategories.Visible = True
rptLinkedCategories.DataSource = tblCategories.DefaultView
rptLinkedCategories.DataBind()
Else
phdLinkedCategories.Visible = False
End If


This hides the control if the value is zero to display. But if it is a number above that, we just apply a 'Take' to the datatable for the number of records we want. It's just a simple way of limiting the number we display without having to modify the sproc and DAL.