本文整理汇总了C#中ExtendedDataCollection.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# ExtendedDataCollection.SetValue方法的具体用法?C# ExtendedDataCollection.SetValue怎么用?C# ExtendedDataCollection.SetValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExtendedDataCollection
的用法示例。
在下文中一共展示了ExtendedDataCollection.SetValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProductTaxCalculationResult
/// <summary>
/// Initializes a new instance of the <see cref="ProductTaxCalculationResult"/> class.
/// </summary>
/// <param name="taxMethodName">
/// The tax method name
/// </param>
/// <param name="originalPrice">
/// The original price.
/// </param>
/// <param name="modifiedPrice">
/// The modified price.
/// </param>
/// <param name="originalSalePrice">
/// The original sale price.
/// </param>
/// <param name="modifiedSalePrice">
/// The modified sale price.
/// </param>
/// <param name="baseTaxRate">
/// The base tax rate
/// </param>
public ProductTaxCalculationResult(
string taxMethodName,
decimal originalPrice,
decimal modifiedPrice,
decimal originalSalePrice,
decimal modifiedSalePrice,
decimal? baseTaxRate = null)
{
var edprice = new ExtendedDataCollection();
var edsaleprice = new ExtendedDataCollection();
var taxRate = baseTaxRate != null ?
baseTaxRate > 1 ?
baseTaxRate.Value / 100M : baseTaxRate.Value :
0M;
if (baseTaxRate != null)
{
edprice.SetValue(Core.Constants.ExtendedDataKeys.BaseTaxRate, baseTaxRate.Value.ToString(CultureInfo.InvariantCulture));
edsaleprice.SetValue(Core.Constants.ExtendedDataKeys.BaseTaxRate, baseTaxRate.Value.ToString(CultureInfo.InvariantCulture));
}
edprice.SetValue(Constants.ExtendedDataKeys.ProductPriceNoTax, originalPrice.ToString(CultureInfo.InvariantCulture));
edprice.SetValue(Constants.ExtendedDataKeys.ProductPriceTaxAmount, modifiedPrice.ToString(CultureInfo.InvariantCulture));
edsaleprice.SetValue(Constants.ExtendedDataKeys.ProductSalePriceNoTax, originalSalePrice.ToString(CultureInfo.InvariantCulture));
edsaleprice.SetValue(Constants.ExtendedDataKeys.ProductSalePriceTaxAmount, modifiedSalePrice.ToString(CultureInfo.InvariantCulture));
PriceResult = new TaxCalculationResult(taxMethodName, taxRate, modifiedPrice, edprice);
SalePriceResult = new TaxCalculationResult(taxMethodName, taxRate, modifiedSalePrice, edsaleprice);
}
示例2: GetMockInvoiceForTaxation
public static IInvoice GetMockInvoiceForTaxation()
{
var origin = new Address()
{
Organization = "Mindfly Web Design Studios",
Address1 = "114 W. Magnolia St. Suite 300",
Locality = "Bellingham",
Region = "WA",
PostalCode = "98225",
CountryCode = "US",
Email = "[email protected]",
Phone = "555-555-5555"
};
var billToShipTo = new Address()
{
Name = "Space Needle",
Address1 = "400 Broad St",
Locality = "Seattle",
Region = "WA",
PostalCode = "98109",
CountryCode = "US",
};
var invoiceService = new InvoiceService();
var invoice = invoiceService.CreateInvoice(Core.Constants.DefaultKeys.InvoiceStatus.Unpaid);
invoice.SetBillingAddress(billToShipTo);
var extendedData = new ExtendedDataCollection();
// this is typically added automatically in the checkout workflow
extendedData.SetValue(Core.Constants.ExtendedDataKeys.CurrencyCode, "USD");
extendedData.SetValue(Core.Constants.ExtendedDataKeys.Taxable, true.ToString());
// make up some line items
var l1 = new InvoiceLineItem(LineItemType.Product, "Item 1", "I1", 10, 1, extendedData);
var l2 = new InvoiceLineItem(LineItemType.Product, "Item 2", "I2", 2, 40, extendedData);
invoice.Items.Add(l1);
invoice.Items.Add(l2);
var shipment = new ShipmentMock(origin, billToShipTo, invoice.Items);
var shipmethod = new ShipMethodMock();
var quote = new ShipmentRateQuote(shipment, shipmethod) { Rate = 16.22M };
invoice.Items.Add(quote.AsLineItemOf<InvoiceLineItem>());
invoice.Total = invoice.Items.Sum(x => x.TotalPrice);
return invoice;
}
示例3: MakeInvoice
private void MakeInvoice()
{
var origin = new Address()
{
Organization = "Mindfly Web Design Studios",
Address1 = "114 W. Magnolia St. Suite 300",
Locality = "Bellingham",
Region = "WA",
PostalCode = "98225",
CountryCode = "US",
Email = "[email protected]",
Phone = "555-555-5555"
};
var billToShipTo = new Address()
{
Name = "The President of the United States",
Address1 = "1600 Pennsylvania Ave NW",
Locality = "Washington",
Region = "DC",
PostalCode = "20500",
CountryCode = "US",
};
var invoiceService = new InvoiceService();
Invoice = invoiceService.CreateInvoice(Core.Constants.DefaultKeys.InvoiceStatus.Unpaid);
Invoice.SetBillingAddress(billToShipTo);
Invoice.Total = 120M;
var extendedData = new ExtendedDataCollection();
// this is typically added automatically in the checkout workflow
extendedData.SetValue(Core.Constants.ExtendedDataKeys.CurrencyCode, "USD");
extendedData.SetValue(Core.Constants.ExtendedDataKeys.Taxable, true.ToString());
// make up some line items
var l1 = new InvoiceLineItem(LineItemType.Product, "Item 1", "I1", 10, 1, extendedData);
var l2 = new InvoiceLineItem(LineItemType.Product, "Item 2", "I2", 2, 40, extendedData);
Invoice.Items.Add(l1);
Invoice.Items.Add(l2);
var shipment = new ShipmentMock(origin, billToShipTo, Invoice.Items);
var shipmethod = new ShipMethodMock();
var quote = new ShipmentRateQuote(shipment, shipmethod) { Rate = 16.22M };
Invoice.Items.Add(quote.AsLineItemOf<InvoiceLineItem>());
}
示例4: ContainsAny_Returns_False_When_Keys_DoNot_Exist
public void ContainsAny_Returns_False_When_Keys_DoNot_Exist()
{
//// Arrange
var ed = new ExtendedDataCollection();
ed.SetValue("one", "value");
ed.SetValue("two", "value");
ed.SetValue("three", "value");
//// Act
var found = ed.ContainsAny(new[] { "six", "five" });
//// Assert
Assert.IsFalse(found);
}
示例5: AddToBasket
public ActionResult AddToBasket(AddItemModel model)
{
// This is an example of using the ExtendedDataCollection to add some custom functionality.
// In this case, we are creating a direct reference to the content (Product Detail Page) so
// that we can provide a link, thumbnail and description in the cart per this design. In other
// designs, there may not be thumbnails or descriptions and the link could be to a completely
// different website.
var extendedData = new ExtendedDataCollection();
extendedData.SetValue("umbracoContentId", model.ContentId.ToString(CultureInfo.InvariantCulture));
var product = Services.ProductService.GetByKey(model.ProductKey);
// In the event the product has options we want to add the "variant" to the basket.
// -- If a product that has variants is defined, the FIRST variant will be added to the cart.
// -- This was done so that we did not have to throw an error since the Master variant is no
// -- longer valid for sale.
if (model.OptionChoices != null && model.OptionChoices.Any())
{
var variant = Services.ProductVariantService.GetProductVariantWithAttributes(product, model.OptionChoices);
Basket.AddItem(variant, variant.Name, 1, extendedData);
}
else
{
Basket.AddItem(product, product.Name, 1, extendedData);
}
Basket.Save();
return RedirectToUmbracoPage(GetContentIdByContentName(BasketPage));
}
示例6: CalculateTaxesForInvoice
/// <summary>
/// Computes the invoice tax result
/// </summary>
/// <returns>
/// The <see cref="ITaxCalculationResult"/>
/// </returns>
public override Attempt<ITaxCalculationResult> CalculateTaxesForInvoice()
{
var extendedData = new ExtendedDataCollection();
try
{
var baseTaxRate = _taxMethod.PercentageTaxRate;
extendedData.SetValue(Core.Constants.ExtendedDataKeys.BaseTaxRate, baseTaxRate.ToString(CultureInfo.InvariantCulture));
if (_taxMethod.HasProvinces)
{
baseTaxRate = AdjustedRate(baseTaxRate, _taxMethod.Provinces.FirstOrDefault(x => x.Code == TaxAddress.Region), extendedData);
}
var visitor = new TaxableLineItemVisitor(baseTaxRate / 100);
Invoice.Items.Accept(visitor);
var totalTax = visitor.TaxableLineItems.Sum(x => decimal.Parse(x.ExtendedData.GetValue(Core.Constants.ExtendedDataKeys.LineItemTaxAmount)));
return Attempt<ITaxCalculationResult>.Succeed(
new TaxCalculationResult(_taxMethod.Name, baseTaxRate, totalTax, extendedData));
}
catch (Exception ex)
{
return Attempt<ITaxCalculationResult>.Fail(ex);
}
}
示例7: CalculateTaxForInvoice
/// <summary>
/// Calculates tax for invoice.
/// </summary>
/// <param name="invoice">
/// The invoice.
/// </param>
/// <param name="taxAddress">
/// The tax address.
/// </param>
/// <returns>
/// The <see cref="ITaxCalculationResult"/>.
/// </returns>
public override ITaxCalculationResult CalculateTaxForInvoice(IInvoice invoice, IAddress taxAddress)
{
decimal amount = 0m;
foreach (var item in invoice.Items)
{
// can I use?: https://github.com/Merchello/Merchello/blob/5706b8c9466f7417c41fdd29de7930b3e8c4dd2d/src/Merchello.Core/Models/ExtendedDataExtensions.cs#L287-L295
if (item.ExtendedData.GetTaxableValue())
amount = amount + item.TotalPrice;
}
TaxRequest taxRequest = new TaxRequest();
taxRequest.Amount = amount;
taxRequest.Shipping = invoice.TotalShipping();
taxRequest.ToCity = taxAddress.Locality;
taxRequest.ToCountry = taxAddress.CountryCode;
taxRequest.ToState = taxAddress.Region;
taxRequest.ToZip = taxAddress.PostalCode;
Models.TaxResult taxResult = _taxjarService.GetTax(taxRequest);
if (taxResult.Success)
{
var extendedData = new ExtendedDataCollection();
extendedData.SetValue(Core.Constants.ExtendedDataKeys.TaxTransactionResults, JsonConvert.SerializeObject(taxResult));
return new TaxCalculationResult(TaxMethod.Name, taxResult.Rate, taxResult.TotalTax, extendedData);
}
throw new Exception("TaxJar.com error");
}
示例8: AddToBasket
public ActionResult AddToBasket(AddToBasket model)
{
// Disable VAT in initial lookup so we don't double tax
var merchello = new MerchelloHelper(false);
// we want to include VAT
Basket.EnableDataModifiers = true;
var product = merchello.Query.Product.GetByKey(model.ProductKey);
if (model.OptionChoice != Guid.Empty)
{
var extendedData = new ExtendedDataCollection();
var variant = product.GetProductVariantDisplayWithAttributes(new[] { model.OptionChoice });
//// serialize the attributes here as they are need in the design
extendedData.SetValue(Constants.ExtendedDataKeys.BasketItemAttributes, JsonConvert.SerializeObject(variant.Attributes));
Basket.AddItem(variant, variant.Name, 1, extendedData);
}
else
{
Basket.AddItem(product, product.Name, 1);
}
Basket.Save();
if (Request.IsAjaxRequest())
{
// this would be the partial for the pop window
return Content("Form submitted");
}
return RedirectToUmbracoPage(ContentResolver.Instance.GetBasketContent());
}
示例9: Init
public void Init()
{
var billTo = new Address()
{
Organization = "Mindfly Web Design Studios",
Address1 = "114 W. Magnolia St. Suite 504",
Locality = "Bellingham",
Region = "WA",
PostalCode = "98225",
CountryCode = "US",
Email = "[email protected]",
Phone = "555-555-5555"
};
// create an invoice
var invoiceService = new InvoiceService();
_invoice = invoiceService.CreateInvoice(Core.Constants.DefaultKeys.InvoiceStatus.Unpaid);
_invoice.SetBillingAddress(billTo);
_invoice.Total = 120M;
var extendedData = new ExtendedDataCollection();
// this is typically added automatically in the checkout workflow
extendedData.SetValue(Core.Constants.ExtendedDataKeys.CurrencyCode, "USD");
// make up some line items
var l1 = new InvoiceLineItem(LineItemType.Product, "Item 1", "I1", 10, 1, extendedData);
var l2 = new InvoiceLineItem(LineItemType.Product, "Item 2", "I2", 2, 40, extendedData);
var l3 = new InvoiceLineItem(LineItemType.Shipping, "Shipping", "shipping", 1, 10M, extendedData);
var l4 = new InvoiceLineItem(LineItemType.Tax, "Tax", "tax", 1, 10M, extendedData);
_invoice.Items.Add(l1);
_invoice.Items.Add(l2);
_invoice.Items.Add(l3);
_invoice.Items.Add(l4);
var processorSettings = new AuthorizeNetProcessorSettings
{
LoginId = ConfigurationManager.AppSettings["xlogin"],
TransactionKey = ConfigurationManager.AppSettings["xtrankey"],
UseSandbox = true
};
Provider.GatewayProviderSettings.ExtendedData.SaveProcessorSettings(processorSettings);
if (Provider.PaymentMethods.Any()) return;
var resource = Provider.ListResourcesOffered().ToArray();
Provider.CreatePaymentMethod(resource.First(), "Credit Card", "Credit Card");
}
示例10: Init
public void Init()
{
_origin = new Address()
{
Name = "Mindfly Web Design Studio",
Address1 = "114 W. Magnolia St. Suite 504",
Locality = "Bellingham",
Region = "WA",
PostalCode = "98225",
CountryCode = "US",
IsCommercial = true
};
_destination = new Address()
{
Name = "Stratosphere Casino, Hotel & Tower",
Address1 = "2000 S Las Vegas Blvd",
Locality = "Las Vegas",
Region = "NV",
PostalCode = "89104",
CountryCode = "US",
IsCommercial = true
};
var extendedData = new ExtendedDataCollection();
extendedData.SetValue("merchProductKey", Guid.NewGuid().ToString());
extendedData.SetValue("merchProductVariantKey", Guid.NewGuid().ToString());
extendedData.SetValue("merchWeight", "12");
var lineItemCollection = new LineItemCollection()
{
{new ItemCacheLineItem(LineItemType.Product, "Product1", "Sku1", 1, 10, extendedData)},
{new ItemCacheLineItem(LineItemType.Product, "Product2", "Sku2", 2, 12, extendedData)},
{new ItemCacheLineItem(LineItemType.Product, "Product3", "Sku3", 3, 14, extendedData)},
};
_shipment = new Shipment(_origin, _destination, lineItemCollection);
}
示例11: Init
public void Init()
{
var billTo = new Address()
{
Organization = "Flightpath",
Address1 = "36 West 25th Street",
Locality = "New York",
Region = "NY",
PostalCode = "10010",
CountryCode = "US",
Email = "[email protected]",
Phone = "212-555-5555"
};
// create an invoice
var invoiceService = new InvoiceService();
_invoice = invoiceService.CreateInvoice(Core.Constants.DefaultKeys.InvoiceStatus.Unpaid);
_invoice.SetBillingAddress(billTo);
_invoice.Total = 120M;
var extendedData = new ExtendedDataCollection();
// this is typically added automatically in the checkout workflow
extendedData.SetValue(Core.Constants.ExtendedDataKeys.CurrencyCode, "USD");
// make up some line items
var l1 = new InvoiceLineItem(LineItemType.Product, "Item 1", "I1", 10, 1, extendedData);
var l2 = new InvoiceLineItem(LineItemType.Product, "Item 2", "I2", 2, 40, extendedData);
var l3 = new InvoiceLineItem(LineItemType.Shipping, "Shipping", "shipping", 1, 10M, extendedData);
var l4 = new InvoiceLineItem(LineItemType.Tax, "Tax", "tax", 1, 10M, extendedData);
_invoice.Items.Add(l1);
_invoice.Items.Add(l2);
_invoice.Items.Add(l3);
_invoice.Items.Add(l4);
var processorSettings = new StripeProcessorSettings
{
ApiKey = ConfigurationManager.AppSettings["stripeApiKey"]
};
Provider.GatewayProviderSettings.ExtendedData.SaveProcessorSettings(processorSettings);
if (Provider.PaymentMethods.Any()) return;
var resource = Provider.ListResourcesOffered().ToArray();
Provider.CreatePaymentMethod(resource.First(), "Credit Card", "Credit Card");
}
示例12: AddToBasket
public ActionResult AddToBasket(AddItemModel model)
{
// This is an example of using the ExtendedDataCollection to add some custom functionality.
// In this case, we are creating a direct reference to the content (Product Detail Page) so
// that we can provide a link, thumbnail and description in the cart per this design. In other
// designs, there may not be thumbnails or descriptions and the link could be to a completely
// different website.
var extendedData = new ExtendedDataCollection();
extendedData.SetValue("umbracoContentId", model.ContentId.ToString(CultureInfo.InvariantCulture));
// NEW IN 1.9.1
// We've added some data modifiers that can handle such things as including taxes in product
// pricing. The data modifiers can either get executed when the item is added to the basket or
// as a result from a MerchelloHelper query - you just don't want them to execute twice.
// Calls directly to the ProductService are not modified
// var product = this.MerchelloServices.ProductService.GetByKey(model.Product.Key);
// Calls to using the MerchelloHelper WILL be modified
// var merchello = new MerchelloHelper();
//
// if you want to do this you should tell the basket not to modify the data again when adding the item
//this.Basket.EnableDataModifiers = false;
// In this case we want to get the product without any data modification
var merchello = new MerchelloHelper(false);
var product = merchello.Query.Product.GetByKey(model.Product.Key);
// In the event the product has options we want to add the "variant" to the basket.
// -- If a product that has variants is defined, the FIRST variant will be added to the cart.
// -- This was done so that we did not have to throw an error since the Master variant is no
// -- longer valid for sale.
if (model.OptionChoices != null && model.OptionChoices.Any())
{
// NEW in 1.9.1
// ProductDisplay and ProductVariantDisplay classes can be added directly to the Basket
// so you don't have to query the service.
var variant = product.GetProductVariantDisplayWithAttributes(model.OptionChoices);
this.Basket.AddItem(variant, variant.Name, 1, extendedData);
}
else
{
this.Basket.AddItem(product, product.Name, 1, extendedData);
}
this.Basket.Save();
return this.RedirectToUmbracoPage(model.BasketPageId);
}
示例13: AddToBasket
public ActionResult AddToBasket(AddItemModel model)
{
// This is an example of using the ExtendedDataCollection to add some custom functionality.
// In this case, we are creating a direct reference to the content (Product Detail Page) so
// that we can provide a link, thumbnail and description in the cart per this design. In other
// designs, there may not be thumbnails or descriptions and the link could be to a completely
// different website.
var extendedData = new ExtendedDataCollection();
extendedData.SetValue("umbracoContentId", model.ContentId.ToString(CultureInfo.InvariantCulture));
var product = _merchelloContext.Services.ProductService.GetByKey(model.ProductKey);
// In the event the product has options we want to add the "variant" to the basket.
// -- If a product that has variants is defined, the FIRST variant will be added to the cart.
// -- This was done so that we did not have to throw an error since the Master variant is no
// -- longer valid for sale.
if (model.OptionChoices != null && model.OptionChoices.Any())
{
var variant = _merchelloContext.Services.ProductVariantService.GetProductVariantWithAttributes(product, model.OptionChoices);
// TODO : This is an error in the back office ... name should already include the variant info
// Begin fix -------------------------------------------------------------------------------------------
// We need to save the variant name (T-Shirt - blue, large) instead of (T-Shirt). This is done in the
// ProductVariantService CreateProductVariantWithKey ... but obviously we're not using that method
// and must be doing it himself in the Back Office before he sends it to the server - likely just
// calling save. http://issues.merchello.com/youtrack/issue/M-153
var name = product.Name;
foreach (var att in variant.Attributes)
{
if (name == product.Name) name += " - ";
else
name += ", ";
name += " " + att.Name;
}
// end fix ----------------------------------------------------------------------------------------------
_basket.AddItem(variant, name, 1, extendedData);
}
else
{
_basket.AddItem(product, product.Name, 1, extendedData);
}
_basket.Save();
// redirect to the cart page - this is a quick and dirty and should be done differently in
// practice
return RedirectToUmbracoPage(BasketContentId);
}
示例14: AddToBasket
public ActionResult AddToBasket(AddItemModel model)
{
// Add to Logical Basket
// add Umbraco content id to Merchello Product extended properties
var extendedData = new ExtendedDataCollection();
extendedData.SetValue("umbracoContentId", model.ContentId.ToString(CultureInfo.InvariantCulture));
// get Merchello product
var product = Services.ProductService.GetByKey(model.ProductKey);
// add a single item of the Product to the logical Basket
Basket.AddItem(product, product.Name, 1, extendedData);
// Save to Database tables: merchItemCache, merchItemCacheItem
Basket.Save();
return RedirectToUmbracoPage(BasketContentId);
}
示例15: AddToWishList
public ActionResult AddToWishList(AddItemModel model)
{
var extendedData = new ExtendedDataCollection();
extendedData.SetValue("umbracoContentId", model.ContentId.ToString(CultureInfo.InvariantCulture));
var product = this.MerchelloServices.ProductService.GetByKey(model.Product.Key);
if (model.OptionChoices != null && model.OptionChoices.Any())
{
var variant = this.MerchelloServices.ProductVariantService.GetProductVariantWithAttributes(product, model.OptionChoices);
_wishList.AddItem(variant, variant.Name, 1, extendedData);
}
else
{
_wishList.AddItem(product, product.Name, 1, extendedData);
}
_wishList.Save();
return this.RedirectToUmbracoPage(model.WishListPageId);
}