Class ProductCollection
- Namespace
- Dynamicweb.Ecommerce.Products
- Assembly
- Dynamicweb.Ecommerce.dll
Represents a collection of the products.
[Serializable]
public class ProductCollection : Collection<Product>, IList<Product>, ICollection<Product>, IReadOnlyList<Product>, IReadOnlyCollection<Product>, IEnumerable<Product>, IList, ICollection, IEnumerable
- Inheritance
-
ProductCollection
- Implements
- Inherited Members
- Extension Methods
Examples
using Dynamicweb.Ecommerce.Products;
using Dynamicweb.Rendering;
namespace Dynamicweb.Ecommerce.Examples.Products
{
class BomConfiguratorSample
{
private Template _template;
private ProductCollection _bomProducts;
private ProductItemCollection _configurators;
private Product _product;
public void SplitBom()
{
//### Split BOM items from configurators
_bomProducts = new ProductCollection();
_configurators = new ProductItemCollection();
_product = new Product();
_template = new Template();
if (_template.LoopExists("BOMConfigurators") || _template.LoopExists("BOMProducts"))
{
foreach (ProductItem item in _product.Items)
{
if (item.BomGroupId == string.Empty)
{
_bomProducts.Add(item.Products[0]);
}
else
{
_configurators.Add(item);
}
}
}
}
}
}
Fields
DefaultSortByField
Default Sort By Field Name
public static readonly string DefaultSortByField
Field Value
UserDefinedSortByField
User Defined Sort By Field Name
public static readonly string UserDefinedSortByField
Field Value
Properties
SortByField
Gets or sets the sort by field.
public string SortByField { get; set; }
Property Value
- string
- The sort by field.
Methods
AddRange(IEnumerable<Product>, bool)
Adds a range of products to this collection.
public void AddRange(IEnumerable<Product> collection, bool allowDuplicates)
Parameters
collection
IEnumerable<Product>- The range of products to add.
allowDuplicates
bool- If True, then the same product can be added more than once. Otherwise it will not be added again
Contains(Product)
Search the ProductCollection for existence of the given product
public bool Contains(Product product)
Parameters
product
Product
Returns
- bool
true
if the list contains the specified product; otherwise,false
.
Contains(Product, bool)
Search the ProductCollection for existence of the product.
public bool Contains(Product product, bool defaultCheck)
Parameters
Returns
- bool
true
if the list contains the specified product; otherwise,false
.
GetProductById(string)
Gets the product by ID.
public Product GetProductById(string productId)
Parameters
productId
string- The product ID.
Returns
GetProductById(string, string)
Gets the product by ID and variant ID.
public Product GetProductById(string productId, string variantId)
Parameters
Returns
GetSortByFieldsList()
Returns Product sorting fields, Product Custom Fields and Calculated Fields list
public static List<string> GetSortByFieldsList()
Returns
IndexOf(string)
Searches product in the list by ID.
public int IndexOf(string productId)
Parameters
productId
string- The product ID.
Returns
Insert(int, Product)
Inserts the given product at the specified index.
public void Insert(int index, Product product)
Parameters
Remarks
If the index is less the zero then the product will be inserted at the beginning of the list. If the index is greater (or equal to) the number of products in the collection then the product will be inserted at the end of the list.
IsCustomFieldSortByField(string)
Returns true if field name is custom product field. Otherwise false
public static bool IsCustomFieldSortByField(string fieldName)
Parameters
fieldName
string- Field name to check
Returns
IsFieldNamesEqual(string, string)
Returns true if field names are equal(ignore case). Otherwise false
public static bool IsFieldNamesEqual(string x, string y)
Parameters
Returns
IsProductSortByField(string)
Returns true if field name is product field. Otherwise false
public static bool IsProductSortByField(string fieldName)
Parameters
fieldName
string- Field name to check
Returns
Load(string)
Loads data for products from DB.
public void Load(string query)
Parameters
query
string- The SQL query.
Load(string, bool)
Loads the data for products from DB.
public void Load(string query, bool doRefactoring)
Parameters
query
string- The SQL query.
doRefactoring
bool- if set to
true
then removes not used items from product list.
Load(string, bool, bool)
Loads the data for products from DB.
public void Load(string query, bool doRefactoring, bool useAssortments)
Parameters
query
string- The SQL query.
doRefactoring
bool- if set to
true
then removes not used items from product list. useAssortments
bool- if set to
true
then assortments are used to re-factor the product collection.
LoadPrices()
Loads the prices.
public void LoadPrices()
LoadProductCategoryValues()
Loads the product category values.
public void LoadProductCategoryValues()
LoadProductItems()
Loads the product items.
public void LoadProductItems()
LoadStocks()
Loads the stocks.
[Obsolete]
public void LoadStocks()
LoadStockUnits()
Loads the stock units.
[Obsolete("This method is no longer used.")]
public void LoadStockUnits()
ReFactorProductList()
Removes not used items from product list.
public void ReFactorProductList()
ReFactorProductList(bool)
Removes not used items from product list.
public void ReFactorProductList(bool useAssortments)
Parameters
useAssortments
bool- If set to
true
then assortments are used to re-factor the product collection.
Remove(ProductCollection)
Removes the specified products.
public void Remove(ProductCollection products)
Parameters
products
ProductCollection- The products.
Replace(int, Product)
Replaces the product at specified position with another one.
public void Replace(int index, Product data)
Parameters
SaveAllProducts()
Saves all Product objects the this ProductCollection.
public void SaveAllProducts()
Sort()
Sorts this instance.
public void Sort()
Sort(string)
Sorts this instance.
public void Sort(string sortBy)
Parameters
sortBy
string- The sort by product field name.
Sort(string, SortDirection)
Sorts this instance.
public void Sort(string sortBy, SortDirection sortDirectionEnum)
Parameters
sortBy
string- The sort by product field name.
sortDirectionEnum
SortDirection- The sort direction enum.
Sort(string, SortDirection, string)
Sorts this instance.
public void Sort(string sortBy, SortDirection sortDirectionEnum, string groupId)
Parameters
sortBy
string- The sort by product field name.
sortDirectionEnum
SortDirection- The sort direction enum.
groupId
string- An ID of the group to perform a sorting within.
SortByFieldExists(string)
Checks if the sortBy exists
public static bool SortByFieldExists(string fieldName)
Parameters
fieldName
string- Name that should be found in the Product fields, custom and calculated fields