本文整理汇总了C#中Nop.Core.Domain.Catalog.ProductVariant类的典型用法代码示例。如果您正苦于以下问题:C# ProductVariant类的具体用法?C# ProductVariant怎么用?C# ProductVariant使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProductVariant类属于Nop.Core.Domain.Catalog命名空间,在下文中一共展示了ProductVariant类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDiscountAmount
/// <summary>
/// Gets discount amount
/// </summary>
/// <param name="productVariant">Product variant</param>
/// <param name="customer">The customer</param>
/// <param name="additionalCharge">Additional charge</param>
/// <returns>Discount amount</returns>
public virtual decimal GetDiscountAmount(ProductVariant productVariant,
Customer customer,
decimal additionalCharge)
{
Discount appliedDiscount = null;
return GetDiscountAmount(productVariant, customer, additionalCharge, out appliedDiscount);
}
示例2: Can_check_taxExempt_productVariant
public void Can_check_taxExempt_productVariant()
{
var productVariant = new ProductVariant();
productVariant.IsTaxExempt = true;
_taxService.IsTaxExempt(productVariant, null).ShouldEqual(true);
productVariant.IsTaxExempt = false;
_taxService.IsTaxExempt(productVariant, null).ShouldEqual(false);
}
示例3: Can_parse_required_productvariant_ids
public void Can_parse_required_productvariant_ids()
{
var productVariant = new ProductVariant
{
RequiredProductVariantIds = "1, 4,7 ,a,"
};
var ids = productVariant.ParseRequiredProductVariantIds();
ids.Length.ShouldEqual(3);
ids[0].ShouldEqual(1);
ids[1].ShouldEqual(4);
ids[2].ShouldEqual(7);
}
示例4: Can_parse_allowed_quantities
public void Can_parse_allowed_quantities()
{
var pv = new ProductVariant()
{
AllowedQuantities = "1, 5,4,10,sdf"
};
var result = pv.ParseAllowedQuatities();
result.Length.ShouldEqual(4);
result[0].ShouldEqual(1);
result[1].ShouldEqual(5);
result[2].ShouldEqual(4);
result[3].ShouldEqual(10);
}
示例5: Can_get_final_product_price_with_additionalFee
public void Can_get_final_product_price_with_additionalFee()
{
var productVariant = new ProductVariant
{
Id = 1,
Name = "Product variant name 1",
Price = 12.34M,
CustomerEntersPrice = false,
Published = true,
Product = new Product()
{
Id = 1,
Name = "Product name 1",
Published = true
}
};
//customer
Customer customer = null;
_priceCalcService.GetFinalPrice(productVariant, customer, 5, false, 1).ShouldEqual(17.34M);
}
示例6: Can_get_shopping_cart_subTotal_discount_including_tax
public void Can_get_shopping_cart_subTotal_discount_including_tax()
{
//customer
Customer customer = new Customer();
//shopping cart
var productVariant1 = new ProductVariant
{
Id = 1,
Name = "Product variant name 1",
Price = 12.34M,
CustomerEntersPrice = false,
Published = true,
Product = new Product()
{
Id = 1,
Name = "Product name 1",
Published = true
}
};
var sci1 = new ShoppingCartItem()
{
ProductVariant = productVariant1,
ProductVariantId = productVariant1.Id,
Quantity = 2,
};
var productVariant2 = new ProductVariant
{
Id = 2,
Name = "Product variant name 2",
Price = 21.57M,
CustomerEntersPrice = false,
Published = true,
Product = new Product()
{
Id = 2,
Name = "Product name 2",
Published = true
}
};
var sci2 = new ShoppingCartItem()
{
ProductVariant = productVariant2,
ProductVariantId = productVariant2.Id,
Quantity = 3
};
var cart = new List<ShoppingCartItem>() { sci1, sci2 };
cart.ForEach(sci => sci.Customer = customer);
cart.ForEach(sci => sci.CustomerId = customer.Id);
//discounts
var discount1 = new Discount()
{
Id = 1,
Name = "Discount 1",
DiscountType = DiscountType.AssignedToOrderSubTotal,
DiscountAmount = 3,
DiscountLimitation = DiscountLimitationType.Unlimited,
};
_discountService.Expect(ds => ds.IsDiscountValid(discount1, customer)).Return(true);
_discountService.Expect(ds => ds.GetAllDiscounts(DiscountType.AssignedToOrderSubTotal)).Return(new List<Discount>() { discount1 });
_discountService.Expect(ds => ds.GetAllDiscounts(DiscountType.AssignedToCategories)).Return(new List<Discount>());
decimal discountAmount;
Discount appliedDiscount;
decimal subTotalWithoutDiscount;
decimal subTotalWithDiscount;
SortedDictionary<decimal, decimal> taxRates;
_orderTotalCalcService.GetShoppingCartSubTotal(cart, true,
out discountAmount, out appliedDiscount,
out subTotalWithoutDiscount, out subTotalWithDiscount, out taxRates);
//TODO strange. Why does the commented test fail? discountAmount.ShouldEqual(3.3);
//discountAmount.ShouldEqual(3.3);
appliedDiscount.ShouldNotBeNull();
appliedDiscount.Name.ShouldEqual("Discount 1");
subTotalWithoutDiscount.ShouldEqual(98.329);
subTotalWithDiscount.ShouldEqual(95.029);
taxRates.Count.ShouldEqual(1);
taxRates.ContainsKey(10).ShouldBeTrue();
taxRates[10].ShouldEqual(8.639);
}
示例7: Can_get_tax_total
public void Can_get_tax_total()
{
//customer
var customer = new Customer()
{
Id = 10,
};
//shopping cart
var productVariant1 = new ProductVariant
{
Id = 1,
Name = "Product variant name 1",
Price = 10M,
Published = true,
IsShipEnabled = true,
Product = new Product()
{
Id = 1,
Name = "Product name 1",
Published = true
}
};
var sci1 = new ShoppingCartItem()
{
ProductVariant = productVariant1,
ProductVariantId = productVariant1.Id,
Quantity = 2,
};
var productVariant2 = new ProductVariant
{
Id = 2,
Name = "Product variant name 2",
Price = 12M,
Published = true,
IsShipEnabled = true,
Product = new Product()
{
Id = 2,
Name = "Product name 2",
Published = true
}
};
var sci2 = new ShoppingCartItem()
{
ProductVariant = productVariant2,
ProductVariantId = productVariant2.Id,
Quantity = 3
};
var cart = new List<ShoppingCartItem>() { sci1, sci2 };
cart.ForEach(sci => sci.Customer = customer);
cart.ForEach(sci => sci.CustomerId = customer.Id);
_genericAttributeService.Expect(x => x.GetAttributesForEntity(customer.Id, "Customer"))
.Return(new List<GenericAttribute>()
{
new GenericAttribute()
{
StoreId = _store.Id,
EntityId = customer.Id,
Key = SystemCustomerAttributeNames.SelectedPaymentMethod,
KeyGroup = "Customer",
Value = "test1"
}
});
_paymentService.Expect(ps => ps.GetAdditionalHandlingFee(cart, "test1")).Return(20);
_discountService.Expect(ds => ds.GetAllDiscounts(DiscountType.AssignedToCategories)).Return(new List<Discount>());
//56 - items, 10 - shipping (fixed), 20 - payment fee
//1. shipping is taxable, payment fee is taxable
_taxSettings.ShippingIsTaxable = true;
_taxSettings.PaymentMethodAdditionalFeeIsTaxable = true;
SortedDictionary<decimal, decimal> taxRates;
_orderTotalCalcService.GetTaxTotal(cart, out taxRates).ShouldEqual(8.6);
taxRates.ShouldNotBeNull();
taxRates.Count.ShouldEqual(1);
taxRates.ContainsKey(10).ShouldBeTrue();
taxRates[10].ShouldEqual(8.6);
//2. shipping is taxable, payment fee is not taxable
_taxSettings.ShippingIsTaxable = true;
_taxSettings.PaymentMethodAdditionalFeeIsTaxable = false;
_orderTotalCalcService.GetTaxTotal(cart, out taxRates).ShouldEqual(6.6);
taxRates.ShouldNotBeNull();
taxRates.Count.ShouldEqual(1);
taxRates.ContainsKey(10).ShouldBeTrue();
taxRates[10].ShouldEqual(6.6);
//3. shipping is not taxable, payment fee is taxable
_taxSettings.ShippingIsTaxable = false;
_taxSettings.PaymentMethodAdditionalFeeIsTaxable = true;
_orderTotalCalcService.GetTaxTotal(cart, out taxRates).ShouldEqual(7.6);
taxRates.ShouldNotBeNull();
taxRates.Count.ShouldEqual(1);
taxRates.ContainsKey(10).ShouldBeTrue();
taxRates[10].ShouldEqual(7.6);
//3. shipping is not taxable, payment fee is not taxable
//.........这里部分代码省略.........
示例8: SendQuantityBelowStoreOwnerNotification
/// <summary>
/// Sends a "quantity below" notification to a store owner
/// </summary>
/// <param name="productVariant">Product variant</param>
/// <param name="languageId">Message language identifier</param>
/// <returns>Queued email identifier</returns>
public virtual int SendQuantityBelowStoreOwnerNotification(ProductVariant productVariant, int languageId)
{
if (productVariant == null)
throw new ArgumentNullException("productVariant");
languageId = EnsureLanguageIsActive(languageId);
var messageTemplate = GetLocalizedActiveMessageTemplate("QuantityBelow.StoreOwnerNotification", languageId);
if (messageTemplate == null)
return 0;
var productVariantTokens = GenerateTokens(productVariant);
//event notification
_eventPublisher.MessageTokensAdded(messageTemplate, productVariantTokens);
var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);
var toEmail = emailAccount.Email;
var toName = emailAccount.DisplayName;
return SendNotification(messageTemplate, emailAccount,
languageId, productVariantTokens,
toEmail, toName);
}
示例9: GetFinalPrice
/// <summary>
/// Gets the final price
/// </summary>
/// <param name="productVariant">Product variant</param>
/// <param name="includeDiscounts">A value indicating whether include discounts or not for final price computation</param>
/// <returns>Final price</returns>
public virtual decimal GetFinalPrice(ProductVariant productVariant,
bool includeDiscounts)
{
var customer = _workContext.CurrentCustomer;
return GetFinalPrice(productVariant, customer, includeDiscounts);
}
示例10: GetShoppingCartItemAttributeWarnings
/// <summary>
/// Validates shopping cart item attributes
/// </summary>
/// <param name="shoppingCartType">Shopping cart type</param>
/// <param name="productVariant">Product variant</param>
/// <param name="selectedAttributes">Selected attributes</param>
/// <returns>Warnings</returns>
public virtual IList<string> GetShoppingCartItemAttributeWarnings(ShoppingCartType shoppingCartType,
ProductVariant productVariant, string selectedAttributes)
{
if (productVariant == null)
throw new ArgumentNullException("productVariant");
var warnings = new List<string>();
//selected attributes
var pva1Collection = _productAttributeParser.ParseProductVariantAttributes(selectedAttributes);
foreach (var pva1 in pva1Collection)
{
var pv1 = pva1.ProductVariant;
if (pv1 != null)
{
if (pv1.Id != productVariant.Id)
{
warnings.Add("Attribute error");
}
}
else
{
warnings.Add("Attribute error");
return warnings;
}
}
//existing product attributes
var pva2Collection = productVariant.ProductVariantAttributes;
foreach (var pva2 in pva2Collection)
{
if (pva2.IsRequired)
{
bool found = false;
//selected product attributes
foreach (var pva1 in pva1Collection)
{
if (pva1.Id == pva2.Id)
{
var pvaValuesStr = _productAttributeParser.ParseValues(selectedAttributes, pva1.Id);
foreach (string str1 in pvaValuesStr)
{
if (!String.IsNullOrEmpty(str1.Trim()))
{
found = true;
break;
}
}
}
}
//if not found
if (!found)
{
if (!string.IsNullOrEmpty(pva2.TextPrompt))
{
warnings.Add(pva2.TextPrompt);
}
else
{
warnings.Add(string.Format(_localizationService.GetResource("ShoppingCart.SelectAttribute"), pva2.ProductAttribute.GetLocalized(a => a.Name)));
}
}
}
}
return warnings;
}
示例11: FindShoppingCartItemInTheCart
/// <summary>
/// Finds a shopping cart item in the cart
/// </summary>
/// <param name="shoppingCart">Shopping cart</param>
/// <param name="shoppingCartType">Shopping cart type</param>
/// <param name="productVariant">Product variant</param>
/// <param name="selectedAttributes">Selected attributes</param>
/// <param name="customerEnteredPrice">Price entered by a customer</param>
/// <returns>Found shopping cart item</returns>
public virtual ShoppingCartItem FindShoppingCartItemInTheCart(IList<ShoppingCartItem> shoppingCart,
ShoppingCartType shoppingCartType,
ProductVariant productVariant,
string selectedAttributes = "",
decimal customerEnteredPrice = decimal.Zero)
{
if (shoppingCart == null)
throw new ArgumentNullException("shoppingCart");
if (productVariant == null)
throw new ArgumentNullException("productVariant");
foreach (var sci in shoppingCart.Where(a => a.ShoppingCartType == shoppingCartType))
{
if (sci.ProductVariantId == productVariant.Id)
{
//attributes
bool attributesEqual = _productAttributeParser.AreProductAttributesEqual(sci.AttributesXml, selectedAttributes);
//gift cards
bool giftCardInfoSame = true;
if (sci.ProductVariant.IsGiftCard)
{
string giftCardRecipientName1 = string.Empty;
string giftCardRecipientEmail1 = string.Empty;
string giftCardSenderName1 = string.Empty;
string giftCardSenderEmail1 = string.Empty;
string giftCardMessage1 = string.Empty;
_productAttributeParser.GetGiftCardAttribute(selectedAttributes,
out giftCardRecipientName1, out giftCardRecipientEmail1,
out giftCardSenderName1, out giftCardSenderEmail1, out giftCardMessage1);
string giftCardRecipientName2 = string.Empty;
string giftCardRecipientEmail2 = string.Empty;
string giftCardSenderName2 = string.Empty;
string giftCardSenderEmail2 = string.Empty;
string giftCardMessage2 = string.Empty;
_productAttributeParser.GetGiftCardAttribute(sci.AttributesXml,
out giftCardRecipientName2, out giftCardRecipientEmail2,
out giftCardSenderName2, out giftCardSenderEmail2, out giftCardMessage2);
if (giftCardRecipientName1.ToLowerInvariant() != giftCardRecipientName2.ToLowerInvariant() ||
giftCardSenderName1.ToLowerInvariant() != giftCardSenderName2.ToLowerInvariant())
giftCardInfoSame = false;
}
//price is the same (for products which require customers to enter a price)
bool customerEnteredPricesEqual = true;
if (sci.ProductVariant.CustomerEntersPrice)
customerEnteredPricesEqual = Math.Round(sci.CustomerEnteredPrice, 2) == Math.Round(customerEnteredPrice, 2);
//found?
if (attributesEqual && giftCardInfoSame && customerEnteredPricesEqual)
return sci;
}
}
return null;
}
示例12: Can_get_shopping_cart_total_with_applied_reward_points
public void Can_get_shopping_cart_total_with_applied_reward_points()
{
//customer
var customer = new Customer()
{
Id = 10,
};
//shopping cart
var productVariant1 = new ProductVariant
{
Id = 1,
Name = "Product variant name 1",
Price = 10M,
Published = true,
IsShipEnabled = true,
Product = new Product()
{
Id = 1,
Name = "Product name 1",
Published = true
}
};
var sci1 = new ShoppingCartItem()
{
ProductVariant = productVariant1,
ProductVariantId = productVariant1.Id,
Quantity = 2,
};
var productVariant2 = new ProductVariant
{
Id = 2,
Name = "Product variant name 2",
Price = 12M,
Published = true,
IsShipEnabled = true,
Product = new Product()
{
Id = 2,
Name = "Product name 2",
Published = true
}
};
var sci2 = new ShoppingCartItem()
{
ProductVariant = productVariant2,
ProductVariantId = productVariant2.Id,
Quantity = 3
};
var cart = new List<ShoppingCartItem>() { sci1, sci2 };
cart.ForEach(sci => sci.Customer = customer);
cart.ForEach(sci => sci.CustomerId = customer.Id);
_genericAttributeService.Expect(x => x.GetAttributesForEntity(customer.Id, "Customer"))
.Return(new List<GenericAttribute>()
{
new GenericAttribute()
{
StoreId = _store.Id,
EntityId = customer.Id,
Key = SystemCustomerAttributeNames.SelectedPaymentMethod,
KeyGroup = "Customer",
Value = "test1"
},
new GenericAttribute()
{
StoreId = 1,
EntityId = customer.Id,
Key = SystemCustomerAttributeNames.UseRewardPointsDuringCheckout,
KeyGroup = "Customer",
Value = true.ToString()
}
});
_paymentService.Expect(ps => ps.GetAdditionalHandlingFee(cart, "test1")).Return(20);
_discountService.Expect(ds => ds.GetAllDiscounts(DiscountType.AssignedToCategories)).Return(new List<Discount>());
decimal discountAmount;
Discount appliedDiscount;
List<AppliedGiftCard> appliedGiftCards;
int redeemedRewardPoints;
decimal redeemedRewardPointsAmount;
//shipping is taxable, payment fee is taxable
_taxSettings.ShippingIsTaxable = true;
_taxSettings.PaymentMethodAdditionalFeeIsTaxable = true;
//reward points
_rewardPointsSettings.Enabled = true;
_rewardPointsSettings.ExchangeRate = 2; //1 reward point = 2
customer.AddRewardPointsHistoryEntry(15); //15*2=30
//56 - items, 10 - shipping (fixed), 20 - payment fee, 8.6 - tax, -30 (reward points)
_orderTotalCalcService.GetShoppingCartTotal(cart, out discountAmount, out appliedDiscount,
out appliedGiftCards, out redeemedRewardPoints, out redeemedRewardPointsAmount)
.ShouldEqual(64.6M);
}
示例13: GetPreferredDiscount
/// <summary>
/// Gets a preferred discount
/// </summary>
/// <param name="productVariant">Product variant</param>
/// <param name="customer">Customer</param>
/// <param name="additionalCharge">Additional charge</param>
/// <param name="quantity">Product quantity</param>
/// <returns>Preferred discount</returns>
protected virtual Discount GetPreferredDiscount(ProductVariant productVariant,
Customer customer, decimal additionalCharge = decimal.Zero, int quantity = 1)
{
if (_catalogSettings.IgnoreDiscounts)
return null;
var allowedDiscounts = GetAllowedDiscounts(productVariant, customer);
decimal finalPriceWithoutDiscount = GetFinalPrice(productVariant, customer, additionalCharge, false, quantity);
var preferredDiscount = allowedDiscounts.GetPreferredDiscount(finalPriceWithoutDiscount);
return preferredDiscount;
}
示例14: GetMinimumTierPrice
/// <summary>
/// Gets a tier price
/// </summary>
/// <param name="productVariant">Product variant</param>
/// <param name="customer">Customer</param>
/// <param name="quantity">Quantity</param>
/// <returns>Price</returns>
protected virtual decimal? GetMinimumTierPrice(ProductVariant productVariant, Customer customer, int quantity)
{
if (!productVariant.HasTierPrices)
return decimal.Zero;
var tierPrices = productVariant.TierPrices
.OrderBy(tp => tp.Quantity)
.ToList()
.FilterForCustomer(customer)
.RemoveDuplicatedQuantities();
int previousQty = 1;
decimal? previousPrice = null;
foreach (var tierPrice in tierPrices)
{
//check quantity
if (quantity < tierPrice.Quantity)
continue;
if (tierPrice.Quantity < previousQty)
continue;
//save new price
previousPrice = tierPrice.Price;
previousQty = tierPrice.Quantity;
}
return previousPrice;
}
示例15: GetAllowedDiscounts
/// <summary>
/// Gets allowed discounts
/// </summary>
/// <param name="productVariant">Product variant</param>
/// <param name="customer">Customer</param>
/// <returns>Discounts</returns>
protected virtual IList<Discount> GetAllowedDiscounts(ProductVariant productVariant,
Customer customer)
{
var allowedDiscounts = new List<Discount>();
if (_catalogSettings.IgnoreDiscounts)
return allowedDiscounts;
if (productVariant.HasDiscountsApplied)
{
//we use this property ("HasDiscountsApplied") for performance optimziation to avoid unnecessary database calls
foreach (var discount in productVariant.AppliedDiscounts)
{
if (_discountService.IsDiscountValid(discount, customer) &&
discount.DiscountType == DiscountType.AssignedToSkus &&
!allowedDiscounts.ContainsDiscount(discount))
allowedDiscounts.Add(discount);
}
}
var productCategories = _categoryService.GetProductCategoriesByProductId(productVariant.ProductId);
if (productCategories != null)
{
foreach (var productCategory in productCategories)
{
var category = productCategory.Category;
if (category.HasDiscountsApplied)
{
//we use this property ("HasDiscountsApplied") for performance optimziation to avoid unnecessary database calls
var categoryDiscounts = category.AppliedDiscounts;
foreach (var discount in categoryDiscounts)
{
if (_discountService.IsDiscountValid(discount, customer) &&
discount.DiscountType == DiscountType.AssignedToCategories &&
!allowedDiscounts.ContainsDiscount(discount))
allowedDiscounts.Add(discount);
}
}
}
}
return allowedDiscounts;
}