Rank: Advanced Member
Groups: Admin, Developers, Registered, HelpDesk, Authorized User Joined: 10/5/2018(UTC) Posts: 704
Thanks: 5 times Was thanked: 113 time(s) in 112 post(s)
|
To fix the sorting issue for Browse Catalog page, you can follow these steps: 1- Open file \Website\Areas\Admin\Controllers\CategoryController.cs 2- Find the code for function SortcategoryItem Code:public ActionResult SortcategoryItem(string CommandName, int itemIndex, int catalogNodeId, int catalogNodeTypeId)
{
Category currentCategory = GetCategory();
CatalogNodeType catalogNodeType = (CatalogNodeType)AlwaysConvert.ToInt(catalogNodeTypeId);
int index;
switch (CommandName)
{
case "MoveUp":
index = currentCategory.CatalogNodes.IndexOf(currentCategory.Id, catalogNodeId, (byte)catalogNodeType);
if (index > 0)
{
CatalogNode tempNode = currentCategory.CatalogNodes[index - 1];
currentCategory.CatalogNodes[index - 1] = currentCategory.CatalogNodes[index];
currentCategory.CatalogNodes[index] = tempNode;
short newOrderBy = 0;
foreach (CatalogNode node in currentCategory.CatalogNodes)
{
node.OrderBy = newOrderBy;
_catalogNodeRepo.Save(node);
newOrderBy++;
}
// recalculate orderby for impacted child products
RecalculateOrderBy(currentCategory.CatalogNodes[index - 1]);
RecalculateOrderBy(currentCategory.CatalogNodes[index]);
// reset the category menu cache for retail side
ResetCategoryMenuCache();
}
break;
case "MoveDown":
index = currentCategory.CatalogNodes.IndexOf(currentCategory.Id, catalogNodeId, (byte)catalogNodeType);
if (index < currentCategory.CatalogNodes.Count - 1)
{
CatalogNode tempNode = currentCategory.CatalogNodes[index + 1];
currentCategory.CatalogNodes[index + 1] = currentCategory.CatalogNodes[index];
currentCategory.CatalogNodes[index] = tempNode;
short newOrderBy = 0;
foreach (CatalogNode node in currentCategory.CatalogNodes)
{
node.OrderBy = newOrderBy;
_catalogNodeRepo.Save(node);
newOrderBy++;
}
// recalculate orderby for impacted child products
RecalculateOrderBy(currentCategory.CatalogNodes[index + 1]);
RecalculateOrderBy(currentCategory.CatalogNodes[index]);
// reset the category menu cache for retail side
ResetCategoryMenuCache();
}
break;
}
return ListCategories();
}
3- And replace it with Code:public ActionResult SortcategoryItem(string CommandName, int itemIndex, int catalogNodeId, int catalogNodeTypeId, int page = 1, int pageSize = 20)
{
Category currentCategory = GetCategory();
CatalogNodeType catalogNodeType = (CatalogNodeType)AlwaysConvert.ToInt(catalogNodeTypeId);
int index;
switch (CommandName)
{
case "MoveUp":
index = currentCategory.CatalogNodes.IndexOf(currentCategory.Id, catalogNodeId, (byte)catalogNodeType);
if (index > 0)
{
CatalogNode tempNode = currentCategory.CatalogNodes[index - 1];
currentCategory.CatalogNodes[index - 1] = currentCategory.CatalogNodes[index];
currentCategory.CatalogNodes[index] = tempNode;
short newOrderBy = 0;
foreach (CatalogNode node in currentCategory.CatalogNodes)
{
node.OrderBy = newOrderBy;
_catalogNodeRepo.Save(node);
newOrderBy++;
}
// recalculate orderby for impacted child products
RecalculateOrderBy(currentCategory.CatalogNodes[index - 1]);
RecalculateOrderBy(currentCategory.CatalogNodes[index]);
// reset the category menu cache for retail side
ResetCategoryMenuCache();
}
break;
case "MoveDown":
index = currentCategory.CatalogNodes.IndexOf(currentCategory.Id, catalogNodeId, (byte)catalogNodeType);
if (index < currentCategory.CatalogNodes.Count - 1)
{
CatalogNode tempNode = currentCategory.CatalogNodes[index + 1];
currentCategory.CatalogNodes[index + 1] = currentCategory.CatalogNodes[index];
currentCategory.CatalogNodes[index] = tempNode;
short newOrderBy = 0;
foreach (CatalogNode node in currentCategory.CatalogNodes)
{
node.OrderBy = newOrderBy;
_catalogNodeRepo.Save(node);
newOrderBy++;
}
// recalculate orderby for impacted child products
RecalculateOrderBy(currentCategory.CatalogNodes[index + 1]);
RecalculateOrderBy(currentCategory.CatalogNodes[index]);
// reset the category menu cache for retail side
ResetCategoryMenuCache();
}
break;
}
return ListCategories(page: page, pageSize: pageSize);
}
4- Now open view file \Website\Areas\Admin\Views\Category\_ListCategories.cshtml 5- Find the code Code:@Ajax.ActionLink(" ", "SortCategoryItem", "Category", new { CategoryId = category.ParentCategoryId, catalogNodeId = category.CatalogNodeId, catalogNodeTypeId = category.CatalogNodeTypeId, itemIndex = i, CommandName = "MoveUp" }, new AjaxOptions() { UpdateTargetId = "categories-list-container", OnSuccess = "initAbleGrid" }, new { @class = "fa fa-arrow-up" })
@Ajax.ActionLink(" ", "SortCategoryItem", "Category", new { CategoryId = category.ParentCategoryId, catalogNodeId = category.CatalogNodeId, catalogNodeTypeId = category.CatalogNodeTypeId, itemIndex = i, CommandName = "MoveDown" }, new AjaxOptions() { UpdateTargetId = "categories-list-container", OnSuccess = "initAbleGrid" }, new { @class = "fa fa-arrow-down" })
6- Replace it with Code:@Ajax.ActionLink(" ", "SortCategoryItem", "Category", new { page = Model.Categories.PageNumber, pageSize = Model.Categories.PageSize, CategoryId = category.ParentCategoryId, catalogNodeId = category.CatalogNodeId, catalogNodeTypeId = category.CatalogNodeTypeId, itemIndex = i, CommandName = "MoveUp" }, new AjaxOptions() { UpdateTargetId = "categories-list-container", OnSuccess = "initAbleGrid" }, new { @class = "fa fa-arrow-up" })
@Ajax.ActionLink(" ", "SortCategoryItem", "Category", new { page = Model.Categories.PageNumber, pageSize = Model.Categories.PageSize, CategoryId = category.ParentCategoryId, catalogNodeId = category.CatalogNodeId, catalogNodeTypeId = category.CatalogNodeTypeId, itemIndex = i, CommandName = "MoveDown" }, new AjaxOptions() { UpdateTargetId = "categories-list-container", OnSuccess = "initAbleGrid" }, new { @class = "fa fa-arrow-down" })
7- This includes a change in a controller file, so you need to compile the project.
|