public virtual bool IsSatisfiedBy(ExpProduct product) { if (product == null) { throw new ArgumentNullException(nameof(product)); } return(product.IndexedProduct.IsActive.GetValueOrDefault(false) && product.IndexedProduct.IsBuyable.GetValueOrDefault(false) && (product.AllPrices.FirstOrDefault()?.ListPrice.Amount ?? 0) > 0); }
public virtual bool IsSatisfiedBy(ExpProduct expProduct) { var result = AbstractTypeFactory <CatalogProductIsBuyableSpecification> .TryCreateInstance().IsSatisfiedBy(expProduct); if (!expProduct.IndexedProduct.TrackInventory.GetValueOrDefault(false) || expProduct.AllInventories.IsNullOrEmpty()) { return(result); } return(expProduct.AllInventories.Any(x => x.AllowBackorder) || expProduct.AllInventories.Any(x => x.AllowPreorder) || expProduct.AllInventories.Sum(inventory => Math.Max(0, inventory.InStockQuantity - inventory.ReservedQuantity)) > 0); }
public void ProductType_Properties_NoLocalization_ShouldGetDefaultValueForDictionary() { // Arrange var alias = "i_grouped"; var propValues = _fixture .Build <PropertyValue>() .With(x => x.LanguageCode, "de-De") .With(x => x.Property, default(Property)) .With(x => x.Alias, alias) .CreateMany() .ToList(); var product = new ExpProduct { IndexedProduct = new CatalogProduct { Properties = new List <Property> { new Property { Values = propValues, Dictionary = true } } } }; var resolveContext = new ResolveFieldContext() { Source = product, UserContext = new Dictionary <string, object> { { "cultureName", CULTURE_NAME } } }; // Act var result = _productType.Fields.FirstOrDefault(x => x.Name.EqualsInvariant("properties")).Resolver.Resolve(resolveContext); // Assert result.Should().BeOfType <List <Property> >(); ((List <Property>)result).Count.Should().Be(1); ((List <Property>)result).Any(p => p.Values.Any(pv => pv.Value.ToString().EqualsInvariant(alias))).Should().BeTrue(); }
public void ProductType_Properties_ShouldReturnPropertyWithCurrentCultureName() { // Arrange var propValues = _fixture .Build <PropertyValue>() .With(x => x.LanguageCode, CULTURE_NAME) .With(x => x.Property, default(Property)) .With(x => x.Alias, "i_grouped") .CreateMany(2) .ToList(); propValues.First().LanguageCode = "de-De"; var product = new ExpProduct { IndexedProduct = new CatalogProduct { Properties = new List <Property> { new Property { Values = propValues } } } }; var resolveContext = new ResolveFieldContext() { Source = product, UserContext = new Dictionary <string, object> { { "cultureName", CULTURE_NAME } } }; // Act var result = _productType.Fields.FirstOrDefault(x => x.Name.EqualsInvariant("properties")).Resolver.Resolve(resolveContext); // Assert result.Should().BeOfType <List <Property> >(); ((List <Property>)result).Count.Should().Be(1); }
public void ProductType_Properties_SelectedLanguageNotFound_ShouldReturnFlatList() { // Arrange var propValue = _fixture .Build <PropertyValue>() .With(x => x.LanguageCode, "de-De") .With(x => x.Property, default(Property)) .Create(); var product = new ExpProduct { IndexedProduct = new CatalogProduct { Properties = new List <Property> { new Property { Values = new List <PropertyValue> { propValue } } } } }; var resolveContext = new ResolveFieldContext() { Source = product, UserContext = new Dictionary <string, object> { { "cultureName", CULTURE_NAME } } }; // Act var result = _productType.Fields.FirstOrDefault(x => x.Name.EqualsInvariant("properties")).Resolver.Resolve(resolveContext); // Assert result.Should().BeOfType <List <Property> >(); ((List <Property>)result).Count.Should().Be(1); ((List <Property>)result).First().Values.First().Should().BeEquivalentTo(propValue); }
protected ExpProduct GetExpProduct(ExpProductOptions options) { var product = new ExpProduct(); product.IndexedProduct = new CatalogProduct() { IsActive = options.IsActive, IsBuyable = options.IsBuyable, TrackInventory = options.TrackInventory, }; if (options.HasPrices) { var productPrice = _fixture.Create <ProductPrice>(); productPrice.ListPrice = GetMoney(100); product.AllPrices = new List <ProductPrice>() { productPrice }; } if (options.HasInventory) { var inventory = _fixture.Create <InventoryInfo>(); inventory.AllowBackorder = options.AllowBackorder; inventory.AllowPreorder = options.AllowPreorder; inventory.InStockQuantity = options.InStockQuantity; inventory.ReservedQuantity = options.ReservedQuantity; product.AllInventories = new List <InventoryInfo>() { inventory }; } return(product); }
public ExpVariation(ExpProduct expProduct) { IndexedProduct = expProduct.IndexedProduct; AllPrices = expProduct.AllPrices; AllInventories = expProduct.AllInventories; }