本文整理汇总了C#中Nop.Core.Domain.Catalog.Product.ParseAllowedQuatities方法的典型用法代码示例。如果您正苦于以下问题:C# Product.ParseAllowedQuatities方法的具体用法?C# Product.ParseAllowedQuatities怎么用?C# Product.ParseAllowedQuatities使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nop.Core.Domain.Catalog.Product
的用法示例。
在下文中一共展示了Product.ParseAllowedQuatities方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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.ParseAllowedQuatities();
result.Length.ShouldEqual(4);
result[0].ShouldEqual(1);
result[1].ShouldEqual(5);
result[2].ShouldEqual(4);
result[3].ShouldEqual(10);
}
示例2: 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.ParseAllowedQuatities();
if (allowedQuantities.Length > 0 && !allowedQuantities.Contains(quantity))
{
//.........这里部分代码省略.........
示例3: PrepareProductDetailsPageModel
//.........这里部分代码省略.........
model.AddToCart.EnteredQuantity = updatecartitem != null ? updatecartitem.Quantity : 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;
//customer entered price
model.AddToCart.CustomerEntersPrice = product.CustomerEntersPrice;
if (model.AddToCart.CustomerEntersPrice)
{
decimal minimumCustomerEnteredPrice = _currencyService.ConvertFromPrimaryStoreCurrency(product.MinimumCustomerEnteredPrice, _workContext.WorkingCurrency);
decimal maximumCustomerEnteredPrice = _currencyService.ConvertFromPrimaryStoreCurrency(product.MaximumCustomerEnteredPrice, _workContext.WorkingCurrency);
model.AddToCart.CustomerEnteredPrice = updatecartitem != null ? updatecartitem.CustomerEnteredPrice : minimumCustomerEnteredPrice;
model.AddToCart.CustomerEnteredPriceRange = string.Format(_localizationService.GetResource("Products.EnterProductPrice.Range"),
_priceFormatter.FormatPrice(minimumCustomerEnteredPrice, false, false),
_priceFormatter.FormatPrice(maximumCustomerEnteredPrice, false, false));
}
//allowed quantities
var allowedQuantities = product.ParseAllowedQuatities();
foreach (var qty in allowedQuantities)
{
model.AddToCart.AllowedQuantities.Add(new SelectListItem
{
Text = qty.ToString(),
Value = qty.ToString(),
Selected = updatecartitem != null && updatecartitem.Quantity == qty
});
}
#endregion
#region Gift card
model.GiftCard.IsGiftCard = product.IsGiftCard;
if (model.GiftCard.IsGiftCard)
{
model.GiftCard.GiftCardType = product.GiftCardType;
if (updatecartitem == null)
{
model.GiftCard.SenderName = _workContext.CurrentCustomer.GetFullName();
model.GiftCard.SenderEmail = _workContext.CurrentCustomer.Email;
}
else
{
string giftCardRecipientName, giftCardRecipientEmail, giftCardSenderName, giftCardSenderEmail, giftCardMessage;
_productAttributeParser.GetGiftCardAttribute(updatecartitem.AttributesXml,
out giftCardRecipientName, out giftCardRecipientEmail,
out giftCardSenderName, out giftCardSenderEmail, out giftCardMessage);
model.GiftCard.RecipientName = giftCardRecipientName;
示例4: PrepareProductDetailsPageModel
//.........这里部分代码省略.........
#endregion
#region 'Add to cart' model
model.AddToCart.ProductId = product.Id;
//quantity
model.AddToCart.EnteredQuantity = 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
model.AddToCart.AvailableForPreOrder = product.AvailableForPreOrder;
//customer entered price
model.AddToCart.CustomerEntersPrice = product.CustomerEntersPrice;
if (model.AddToCart.CustomerEntersPrice)
{
decimal minimumCustomerEnteredPrice = _currencyService.ConvertFromPrimaryStoreCurrency(product.MinimumCustomerEnteredPrice, _workContext.WorkingCurrency);
decimal maximumCustomerEnteredPrice = _currencyService.ConvertFromPrimaryStoreCurrency(product.MaximumCustomerEnteredPrice, _workContext.WorkingCurrency);
model.AddToCart.CustomerEnteredPrice = minimumCustomerEnteredPrice;
model.AddToCart.CustomerEnteredPriceRange = string.Format(_localizationService.GetResource("Products.EnterProductPrice.Range"),
_priceFormatter.FormatPrice(minimumCustomerEnteredPrice, false, false),
_priceFormatter.FormatPrice(maximumCustomerEnteredPrice, false, false));
}
//allowed quantities
var allowedQuantities = product.ParseAllowedQuatities();
foreach (var qty in allowedQuantities)
{
model.AddToCart.AllowedQuantities.Add(new SelectListItem()
{
Text = qty.ToString(),
Value = qty.ToString()
});
}
#endregion
#region Gift card
model.GiftCard.IsGiftCard = product.IsGiftCard;
if (model.GiftCard.IsGiftCard)
{
model.GiftCard.GiftCardType = product.GiftCardType;
model.GiftCard.SenderName = _workContext.CurrentCustomer.GetFullName();
model.GiftCard.SenderEmail = _workContext.CurrentCustomer.Email;
}
#endregion
#region Product attributes
var productVariantAttributes = _productAttributeService.GetProductVariantAttributesByProductId(product.Id);
foreach (var attribute in productVariantAttributes)
{
var pvaModel = new ProductDetailsModel.ProductVariantAttributeModel()
{
Id = attribute.Id,
ProductId = product.Id,
示例5: PrepareProductDetailsPageModel
//.........这里部分代码省略.........
//quantity
model.AddToCart.EnteredQuantity = updatecartitem != null ? updatecartitem.Quantity : 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;
}
//customer entered price
model.AddToCart.CustomerEntersPrice = product.CustomerEntersPrice;
if (model.AddToCart.CustomerEntersPrice)
{
decimal minimumCustomerEnteredPrice = _currencyService.ConvertFromPrimaryStoreCurrency(product.MinimumCustomerEnteredPrice, _workContext.WorkingCurrency);
decimal maximumCustomerEnteredPrice = _currencyService.ConvertFromPrimaryStoreCurrency(product.MaximumCustomerEnteredPrice, _workContext.WorkingCurrency);
model.AddToCart.CustomerEnteredPrice = updatecartitem != null ? updatecartitem.CustomerEnteredPrice : minimumCustomerEnteredPrice;
model.AddToCart.CustomerEnteredPriceRange = string.Format(_localizationService.GetResource("Products.EnterProductPrice.Range"),
_priceFormatter.FormatPrice(minimumCustomerEnteredPrice, false, false),
_priceFormatter.FormatPrice(maximumCustomerEnteredPrice, false, false));
}
//allowed quantities
var allowedQuantities = product.ParseAllowedQuatities();
foreach (var qty in allowedQuantities)
{
model.AddToCart.AllowedQuantities.Add(new SelectListItem()
{
Text = qty.ToString(),
Value = qty.ToString(),
Selected = updatecartitem != null && updatecartitem.Quantity == qty
});
}
#endregion
#region Gift card
model.GiftCard.IsGiftCard = product.IsGiftCard;
if (model.GiftCard.IsGiftCard)
{
model.GiftCard.GiftCardType = product.GiftCardType;
if (updatecartitem == null)
{
model.GiftCard.SenderName = _workContext.CurrentCustomer.GetFullName();
model.GiftCard.SenderEmail = _workContext.CurrentCustomer.Email;
}
else
{
string giftCardRecipientName, giftCardRecipientEmail, giftCardSenderName, giftCardSenderEmail, giftCardMessage;
_productAttributeParser.GetGiftCardAttribute(updatecartitem.AttributesXml,
out giftCardRecipientName, out giftCardRecipientEmail,
out giftCardSenderName, out giftCardSenderEmail, out giftCardMessage);
model.GiftCard.RecipientName = giftCardRecipientName;