Select version
v7.7 v7.6 v7.5 v7.3 v7.1 v7.0 v6.8 v6.7 v6.6 v6 v5 v4 v3 v2

Querying Products by Custom Properties in uCommerce

One of the questions I’ve come across a couple of times with uCommerce is using the LINQ API to query products by custom properties added to a product definition.

Here’s how:

    
    
    var q = from product in Product.All()
      where product.ProductProperties.Where(property => 
        (property.ProductDefinitionField.Name == "MyProperty" && property.Value == "MyPropertyValue") 
        || (property.ProductDefinitionField.Name == "MyOtherProperty" && property.Value == "MyotherPropertyValue")).Count() == 2
        && product.ParentProductId == null
      select product;
    
    
uCommerce Aps - Studsgade 29B - 8000 Aarhus C - Denmark
Phone +45 61 799 997 - Email info@ucommerce.dk uCommerce logo