Table of Contents

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

node NavigationTreeNodeViewModel

The 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.

  1. The method takes a parameter node of type Dynamicweb.Frontend.Navigation.NavigationTreeNodeViewModel, which represents the navigation tree node.
  2. It first checks if the GroupId property of the node is not empty or null using the string.IsNullOrEmpty method.
  3. If the GroupId is not empty, it proceeds to retrieve the necessary information for creating the product group view model.
  4. It retrieves the languageId from Common.Context.LanguageID, which is the language ID of the current context.
  5. It retrieves the currencyCode from Common.Context.Currency.Code, which is the currency code of the current context.
  6. 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.
  7. 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.
  8. It retrieves the userId from UserContext.Current.UserId, which represents the ID of the current user.
  9. 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.
  10. 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.
  11. Finally, it returns the created model as the result of the method.
  12. 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.
To top