本文整理汇总了C#中Nop.Core.Domain.Catalog.Product.ParseAllowedQuantities方法的典型用法代码示例。如果您正苦于以下问题:C# Product.ParseAllowedQuantities方法的具体用法?C# Product.ParseAllowedQuantities怎么用?C# Product.ParseAllowedQuantities使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nop.Core.Domain.Catalog.Product
的用法示例。
在下文中一共展示了Product.ParseAllowedQuantities方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_parse_allowed_quantities
public void Can_parse_allowed_quantities()
{
var product = new Product
{
AllowedQuantities = "1, 5,4,10,sdf"
};
var result = product.ParseAllowedQuantities();
result.Length.ShouldEqual(4);
result[0].ShouldEqual(1);
result[1].ShouldEqual(5);
result[2].ShouldEqual(4);
result[3].ShouldEqual(10);
}
示例2: PrepareProductDetailsPageModel
//.........这里部分代码省略.........
//currency code
model.ProductPrice.CurrencyCode = _workContext.WorkingCurrency.CurrencyCode;
//rental
if (product.IsRental)
{
model.ProductPrice.IsRental = true;
var priceStr = _priceFormatter.FormatPrice(finalPriceWithDiscount);
model.ProductPrice.RentalPrice = _priceFormatter.FormatRentalProductPeriod(product, priceStr);
}
}
}
}
else
{
model.ProductPrice.HidePrices = true;
model.ProductPrice.OldPrice = null;
model.ProductPrice.Price = null;
}
#endregion
#region 'Add to cart' model
model.AddToCart.ProductId = product.Id;
model.AddToCart.UpdatedShoppingCartItemId = updatecartitem != null ? updatecartitem.Id : 0;
//quantity
model.AddToCart.EnteredQuantity = updatecartitem != null ? updatecartitem.Quantity : product.OrderMinimumQuantity;
//allowed quantities
var allowedQuantities = product.ParseAllowedQuantities();
foreach (var qty in allowedQuantities)
{
model.AddToCart.AllowedQuantities.Add(new SelectListItem
{
Text = qty.ToString(),
Value = qty.ToString(),
Selected = updatecartitem != null && updatecartitem.Quantity == qty
});
}
//minimum quantity notification
if (product.OrderMinimumQuantity > 1)
{
model.AddToCart.MinimumQuantityNotification = string.Format(_localizationService.GetResource("Products.MinimumQuantityNotification"), product.OrderMinimumQuantity);
}
//'add to cart', 'add to wishlist' buttons
model.AddToCart.DisableBuyButton = product.DisableBuyButton || !_permissionService.Authorize(StandardPermissionProvider.EnableShoppingCart);
model.AddToCart.DisableWishlistButton = product.DisableWishlistButton || !_permissionService.Authorize(StandardPermissionProvider.EnableWishlist);
if (!_permissionService.Authorize(StandardPermissionProvider.DisplayPrices))
{
model.AddToCart.DisableBuyButton = true;
model.AddToCart.DisableWishlistButton = true;
}
//pre-order
if (product.AvailableForPreOrder)
{
model.AddToCart.AvailableForPreOrder = !product.PreOrderAvailabilityStartDateTimeUtc.HasValue ||
product.PreOrderAvailabilityStartDateTimeUtc.Value >= DateTime.UtcNow;
model.AddToCart.PreOrderAvailabilityStartDateTimeUtc = product.PreOrderAvailabilityStartDateTimeUtc;
}
//rental
model.AddToCart.IsRental = product.IsRental;
示例3: GetStandardWarnings
/// <summary>
/// Validates a product for standard properties
/// </summary>
/// <param name="customer">Customer</param>
/// <param name="shoppingCartType">Shopping cart type</param>
/// <param name="product">Product</param>
/// <param name="attributesXml">Attributes in XML format</param>
/// <param name="customerEnteredPrice">Customer entered price</param>
/// <param name="quantity">Quantity</param>
/// <returns>Warnings</returns>
public virtual IList<string> GetStandardWarnings(Customer customer, ShoppingCartType shoppingCartType,
Product product, string attributesXml, decimal customerEnteredPrice,
int quantity)
{
if (customer == null)
throw new ArgumentNullException("customer");
if (product == null)
throw new ArgumentNullException("product");
var warnings = new List<string>();
//deleted
if (product.Deleted)
{
warnings.Add(_localizationService.GetResource("ShoppingCart.ProductDeleted"));
return warnings;
}
//published
if (!product.Published)
{
warnings.Add(_localizationService.GetResource("ShoppingCart.ProductUnpublished"));
}
//we can add only simple products
if (product.ProductType != ProductType.SimpleProduct)
{
warnings.Add("This is not simple product");
}
//ACL
if (!_aclService.Authorize(product, customer))
{
warnings.Add(_localizationService.GetResource("ShoppingCart.ProductUnpublished"));
}
//Store mapping
if (!_storeMappingService.Authorize(product, _storeContext.CurrentStore.Id))
{
warnings.Add(_localizationService.GetResource("ShoppingCart.ProductUnpublished"));
}
//disabled "add to cart" button
if (shoppingCartType == ShoppingCartType.ShoppingCart && product.DisableBuyButton)
{
warnings.Add(_localizationService.GetResource("ShoppingCart.BuyingDisabled"));
}
//disabled "add to wishlist" button
if (shoppingCartType == ShoppingCartType.Wishlist && product.DisableWishlistButton)
{
warnings.Add(_localizationService.GetResource("ShoppingCart.WishlistDisabled"));
}
//call for price
if (shoppingCartType == ShoppingCartType.ShoppingCart && product.CallForPrice)
{
warnings.Add(_localizationService.GetResource("Products.CallForPrice"));
}
//customer entered price
if (product.CustomerEntersPrice)
{
if (customerEnteredPrice < product.MinimumCustomerEnteredPrice ||
customerEnteredPrice > product.MaximumCustomerEnteredPrice)
{
decimal minimumCustomerEnteredPrice = _currencyService.ConvertFromPrimaryStoreCurrency(product.MinimumCustomerEnteredPrice, _workContext.WorkingCurrency);
decimal maximumCustomerEnteredPrice = _currencyService.ConvertFromPrimaryStoreCurrency(product.MaximumCustomerEnteredPrice, _workContext.WorkingCurrency);
warnings.Add(string.Format(_localizationService.GetResource("ShoppingCart.CustomerEnteredPrice.RangeError"),
_priceFormatter.FormatPrice(minimumCustomerEnteredPrice, false, false),
_priceFormatter.FormatPrice(maximumCustomerEnteredPrice, false, false)));
}
}
//quantity validation
var hasQtyWarnings = false;
if (quantity < product.OrderMinimumQuantity)
{
warnings.Add(string.Format(_localizationService.GetResource("ShoppingCart.MinimumQuantity"), product.OrderMinimumQuantity));
hasQtyWarnings = true;
}
if (quantity > product.OrderMaximumQuantity)
{
warnings.Add(string.Format(_localizationService.GetResource("ShoppingCart.MaximumQuantity"), product.OrderMaximumQuantity));
hasQtyWarnings = true;
}
var allowedQuantities = product.ParseAllowedQuantities();
if (allowedQuantities.Length > 0 && !allowedQuantities.Contains(quantity))
{
//.........这里部分代码省略.........