Class NavigationTreeViewNodeExtensions
- Namespace
- Dynamicweb.Ecommerce.ProductCatalog
- Assembly
- Dynamicweb.Ecommerce.dll
public static class NavigationTreeViewNodeExtensions
- Inheritance
-
NavigationTreeViewNodeExtensions
- Inherited Members
Methods
GetProductGroup(NavigationTreeNodeViewModel)
Gets the product group associated with the navigation tree node.
public static ProductGroupViewModel GetProductGroup(this NavigationTreeNodeViewModel node)
Parameters
nodeNavigationTreeNodeViewModelThe navigation tree node.
Returns
- ProductGroupViewModel
The product group view model.
Remarks
The GetProductGroup method in the NavigationTreeViewNodeExtensions class is responsible for retrieving the product group associated with a navigation tree node. Let's break down how it makes decisions on its return value.
- The method takes a parameter node of type Dynamicweb.Frontend.Navigation.NavigationTreeNodeViewModel, which represents the navigation tree node.
- It first checks if the GroupId property of the node is not empty or null using the string.IsNullOrEmpty method.
- If the GroupId is not empty, it proceeds to retrieve the necessary information for creating the product group view model.
- It retrieves the languageId from Common.Context.LanguageID, which is the language ID of the current context.
- It retrieves the currencyCode from Common.Context.Currency.Code, which is the currency code of the current context.
- It retrieves the countryCode from Common.Context.Country?.Code2, which is the country code of the current context.The?. operator is used to handle the case when Common.Context.Country is null.
- It retrieves the shopId from Dynamicweb.Frontend.PageView.Current()?.Area?.EcomShopId, which represents the ID of the current e-commerce shop. The?. operator is used to handle the case when any of the properties in the chain is null.
- It retrieves the userId from UserContext.Current.UserId, which represents the ID of the current user.
- It then calls the Services.ProductGroups.GetGroup method, passing the node.GroupId and the previously retrieved information (languageId) as parameters.This method retrieves the product group based on the provided group ID and language ID.
- If the retrieved group is not null, it proceeds to create a ProductGroupViewModel using the ViewModelFactory.CreateView method.It passes the necessary settings (languageId, currencyCode, countryCode, shopId, userId) and the retrieved group as parameters.
- Finally, it returns the created model as the result of the method.
- If the GroupId was empty or if the retrieved group was null, it returns a new instance of ProductGroupViewModel using the default constructor. This method ensures that a valid ProductGroupViewModel is returned when a valid GroupId is provided and a corresponding product group is found.Otherwise, it returns an empty ProductGroupViewModel.