Table of Contents

Class DynamicRelationCalculationService

Namespace
Dynamicweb.Ecommerce.Products.DynamicRelations
Assembly
Dynamicweb.Ecommerce.dll

Provides service methods for managing and processing dynamic relation calculations. This service handles the creation, retrieval, processing, and deletion of calculations that derive values from product relationships based on configured calculation methods and field aggregations.

public abstract class DynamicRelationCalculationService
Inheritance
DynamicRelationCalculationService
Inherited Members

Remarks

Dynamic relation calculations enable automatic computation of product field values (such as weight, volume, dimensions) by analyzing related products through their dynamic product relationships. The calculations are performed using specified algorithms like sum aggregations and can be scoped to specific product groups and fields.

Methods

DeleteByConfigurationIds(IEnumerable<string>)

Deletes all dynamic relation calculations associated with the specified calculation configuration IDs. This operation is typically used when calculation configurations are removed or modified, requiring cleanup of previously generated calculation results.

public abstract void DeleteByConfigurationIds(IEnumerable<string> calculationConfigurationIds)

Parameters

calculationConfigurationIds IEnumerable<string>

A collection of calculation configuration IDs whose associated calculations should be deleted. Null, empty, or whitespace-only IDs are ignored.

Remarks

This method performs a bulk delete operation and is useful for maintaining data consistency when calculation configurations change. It ensures that obsolete calculation results are removed from the system to prevent confusion with current calculations.

DeleteByProductRelation(string)

Deletes all dynamic relation calculations associated with a specific dynamic product relation. This operation is typically performed when a dynamic product relation is removed or modified, requiring cleanup of calculations that were based on that relationship.

public abstract void DeleteByProductRelation(string dynamicProductRelationId)

Parameters

dynamicProductRelationId string

The identifier of the dynamic product relation whose associated calculations should be deleted. If null or empty, no action is taken.

Remarks

This method ensures data integrity by removing calculations that are no longer valid due to changes in the underlying product relationship structure. It is automatically called when dynamic product relations are modified or deleted.

DeleteByRelationGroup(string)

Deletes all entities associated with the specified dynamic relation group identifier.

public abstract void DeleteByRelationGroup(string dynamicRelationGroupId)

Parameters

dynamicRelationGroupId string

The unique identifier of the dynamic relation group whose associated entities are to be deleted. Cannot be null or empty.

DeleteLogsByConfigurationIds(IEnumerable<string>)

Deletes all logs associated with the specified calculation configuration IDs.

public abstract void DeleteLogsByConfigurationIds(IEnumerable<string> calculationConfigurationIds)

Parameters

calculationConfigurationIds IEnumerable<string>

A collection of calculation configuration IDs for which to delete logs. Cannot be null.

GetById(long)

Retrieves a dynamic relation calculation by its unique identifier.

public abstract DynamicRelationCalculation? GetById(long id)

Parameters

id long

The unique identifier of the calculation to retrieve. Must be greater than zero.

Returns

DynamicRelationCalculation

The DynamicRelationCalculation object if found; otherwise, null.

Exceptions

ArgumentOutOfRangeException

Thrown when id is less than or equal to zero.

GetByProductAndGroup(string, string)

Retrieves all dynamic relation calculations for a specific product and dynamic relation group.

public abstract IEnumerable<DynamicRelationCalculation> GetByProductAndGroup(string productId, string dynamicRelationGroupId)

Parameters

productId string

The identifier of the source product. Cannot be null or empty.

dynamicRelationGroupId string

The identifier of the dynamic relation group. Cannot be null or empty.

Returns

IEnumerable<DynamicRelationCalculation>

A collection of DynamicRelationCalculation objects that match the specified criteria. Returns an empty collection if no calculations are found.

Remarks

This method is useful for retrieving all calculated values for a specific product within a particular dynamic relation context, such as getting all aggregated field values for a product assembly.

Exceptions

ArgumentException

Thrown when productId or dynamicRelationGroupId is null or empty.

GetComputationLogById(long)

Retrieves the computation log associated with the specified identifier.

public abstract DynamicRelationCalculationComputationLog? GetComputationLogById(long id)

Parameters

id long

The unique identifier of the computation log to retrieve.

Returns

DynamicRelationCalculationComputationLog

A DynamicRelationCalculationComputationLog object representing the computation log if found; otherwise, null.

GetComputationLogsByConfigurationId(string)

Retrieves a collection of computation logs associated with the specified configuration identifier.

public abstract IEnumerable<DynamicRelationCalculationComputationLog> GetComputationLogsByConfigurationId(string configurationId)

Parameters

configurationId string

The unique identifier of the configuration for which to retrieve computation logs.

Returns

IEnumerable<DynamicRelationCalculationComputationLog>

An enumerable collection of DynamicRelationCalculationComputationLog objects representing the computation logs for the specified configuration. The collection will be empty if no logs are found.

Process(DynamicRelationCalculationConfiguration)

Processes a dynamic relation calculation configuration to generate calculation results. This method orchestrates the entire calculation workflow, including validation, data retrieval, calculator selection, and result generation.

public abstract DynamicRelationCalculationResult Process(DynamicRelationCalculationConfiguration calculationConfiguration)

Parameters

calculationConfiguration DynamicRelationCalculationConfiguration

The configuration that defines the calculation parameters, including the calculation method, target groups, fields, and related dynamic product relations. Cannot be null.

Returns

DynamicRelationCalculationResult

A DynamicRelationCalculationResult containing the generated calculations and execution status. If the operation fails, the result will contain error information and an empty calculation collection.

Remarks

The method supports various calculation methods as defined by DynamicRelationCalculationMethod, such as sum aggregations and product-specific calculations. Each method may produce different calculation results based on the underlying algorithm implementation.

Save(DynamicRelationCalculation)

Saves a dynamic relation calculation to the data store. If matching calculations already exist, they will be removed to prevent duplicates before saving the new calculation.

public abstract void Save(DynamicRelationCalculation calculation)

Parameters

calculation DynamicRelationCalculation

The calculation to save. Cannot be null.

Remarks

The save operation automatically handles duplicate prevention by removing any existing calculations that match the key properties of the provided calculation before inserting the new one. This ensures data consistency and prevents stale calculation results.

Exceptions

ArgumentNullException

Thrown when calculation is null.

To top