Rank: Advanced Member
Groups: Developers
Joined: 11/7/2018(UTC) Posts: 303
Thanks: 21 times Was thanked: 5 time(s) in 5 post(s)
|
Do you have any plans to include a category page that displays catalog nodes- categories, webpages, links, products? We have sites wanting to upgrade that use is. I'm trying to work on one, but it's fumbling around as far as if I need to set up a new model,etc. I've added code to the CategoryController and created the view.Can I get any help? Here's is part of what I have so far by copying the categorygrid2 code and changing it. [RegisterWidget(DisplayName = "Catalog Node Grid", IconUrl = "category_grid.png", Category = WidgetCategory.Category, Description = "Displays only the products within the category being viewed. Uses admin sort order as the default display.")] public ActionResult CategoryGridPage4(CategoryGridPageParams parameters, int page = 1, int pageSize = 0, string sortExpression = "OrderBy ASC, Name ASC") { if (pageSize == 0) pageSize = (int)parameters.MaxItems;
var pageIndex = page - 1; int categoryId = parameters.CategoryId;
Category category = _categoryRepo.Load(categoryId); if (category == null) { categoryId = AlwaysConvert.ToInt(this.RouteData.Values["Id"]); if (categoryId > 0) { category = _categoryRepo.Load(categoryId); } }
// IF IT IS ROOT CATEGORY if (category == null || category.Visibility == CatalogVisibility.Private) { Response.Redirect(Url.Content("~/Default"), false); return RedirectToLocal(Url.Content("~/Default")); }
var store = AbleContext.Current.Store; // LOAD PRODUCTS MEETING CRITERIA //int count = _nodeRepo.CountForCategory<Product>(category.Id); int count = _catalogNodeRepo.CountForCategory(categoryId);//true, true should be here int index = pageSize * pageIndex; if (index >= count) index = 0; var categories = _catalogRepo.LoadForCategory(category.Id, false, pageSize, (pageSize * pageIndex), sortExpression); var categoriesModel = categories.Select(node => new CategoryModel() {
Name = node.Name, NavigateUrl = node.NavigateUrl, ThumbnailAltText = node.ThumbnailAltText, ThumbnailUrl = node.ThumbnailUrl, Summary=node.Summary }).ToList();
..... more not included here
I've added public StaticPagedList<CategoryModel> Categories { get; set; } to the CategoryGridPageModel
I'm getting the error on the page, but no errors in the build. could not resolve property: Name of: CommerceBuilder.Catalog.CatalogNode
Thanks for any help.
|
|
|
|
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)
|
Hi,
I have opened a discussion about this and we will let you know if we have plans to include in the next release or not.
For the error, can you please share the error details from the admin panel error log listing page. The error seems to be in the view file you are using for this widget. Please confirm so we can assist you further.
|
|
|
|
Rank: Advanced Member
Groups: Developers
Joined: 11/7/2018(UTC) Posts: 303
Thanks: 21 times Was thanked: 5 time(s) in 5 post(s)
|
Ah, I see. I haven't worked in AC9 for a couple of months so I'm re-learning everything! Error is Inner Exception: could not resolve property: Name of: CommerceBuilder.Catalog.CatalogNode
I've reworked some things, changed some places on the view (I had missed a few Model.Products) and been able to get past that error.
I do have another issue: If I use int count = _catalogNodeRepo.CountForCategory(categoryId,true,true) (adding true, true), I get the error The arguments for the method.... cannot be inferred from the usage. Try specifying the type arguments explicitly. So far I haven't been able to find anything helpful by googling. I have checked other places in AC code where the method is used and they don't throw an error. Can you give me any help on that? Thanks
|
|
|
|
Rank: Advanced Member
Groups: Developers
Joined: 11/7/2018(UTC) Posts: 303
Thanks: 21 times Was thanked: 5 time(s) in 5 post(s)
|
OK, I'm an idiot. I changed it to int count = _catalogRepo.CountForCategory(categoryId,true) instead of _catalogNodeRepo
|
|
|
|
Rank: Advanced Member
Groups: Developers
Joined: 11/7/2018(UTC) Posts: 303
Thanks: 21 times Was thanked: 5 time(s) in 5 post(s)
|
I ran into another stump. I've got the catalognodes loading on this page and am trying to use the _ProductItemDisplay.chstml, like on the other category pages, when the node is a product. It is looking to have a ProductModel passed to it. How can I convert a Product to a ProductModel? Here is where I'm trying to use it: @foreach (var catalogNode in Model.CatalogNodes) { if (catalogNode.NodeType == CatalogNodeType.Product) { Product product = catalogNode.CatalogNode.ChildObject as Product;
<div class="col-xs-6 col-sm-4 col-md-@ViewBag.Columns"> @Html.Partial("_ProductItemDisplay", product, new ViewDataDictionary { { "ShowSku", ViewBag.Parameters.ShowSku }, { "ShowManufacturer", ViewBag.Parameters.ShowManufacturer }, { "ShowRating", ViewBag.Parameters.ShowProductReviews }, { "ShowSummary", ViewBag.Parameters.ShowProductSummary }, { "ShowProductQuickViewDisplay", ViewBag.Parameters.ShowProductQuickViewDisplay } }) </div> } } Or is there a better way of doing this? Thanks again.
|
|
|
|
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)
|
Hi Judy,
You need to create a ProductModel object to pass it to _ProductsItemDisplay partial view. A good way is to place your logic in controller and send the ProductModel object list to the view side. Similar code can be seen in CategoryController CategoryGirdPage action methods (widgets).
|
|
|
|
Rank: Advanced Member
Groups: Developers
Joined: 11/7/2018(UTC) Posts: 303
Thanks: 21 times Was thanked: 5 time(s) in 5 post(s)
|
Thank you for your help. Could you look these files over and give suggestions. I'm sure some of the code is amateurish, but I'm just learning this. On the view file, I would change the CatalogNodeItemDisplay to ProductItemDisplay if I could figure out how to connect the catalog node's product productmodel. I might have done some of these things in a non-optimal way, but I got everything to work as far as showing all the objects, but need to have the add to cart button for the products- use the ProductItemDisplay or integrate similar code into the CatalogNodeItemDisplay. The add to cart does work from the quickview. Thanks Edited by user Wednesday, June 10, 2020 10:41:27 AM(UTC)
| Reason: Not specified
|
|
|
|
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 show the addToCart button for products, follow these steps: 1- Find this code in _CatalogNodeItemDisplay.cshtml Code: @*@if (ShowAddToCart)
{
@Html.Partial("~/Views/Product/_AddToCartLink.cshtml", product)
}*@
2- Replace it with Code:@if (ShowAddToCart)
{
var productModel = new ProductModel()
{
Id = product.Id,
NavigateUrl = product.NavigateUrl,
DisablePurchase = product.DisablePurchase,
HasChoices = product.HasChoices,
UseVariablePrice = product.UseVariablePrice,
IsSubscription = product.IsSubscription,
InventoryMode = product.InventoryMode,
InStock = product.InStock
};
@Html.Partial("~/Views/Product/_AddToCartLink.cshtml", productModel)
}
Edited by user Tuesday, June 2, 2020 6:11:39 AM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Advanced Member
Groups: Developers
Joined: 11/7/2018(UTC) Posts: 303
Thanks: 21 times Was thanked: 5 time(s) in 5 post(s)
|
Thank you, that helped. I had tried to create the productmodel in the view before, but must have been doing something wrong.
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
Important Information:
The AbleCommerce Forums uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close