public void Setup()
		{
			_variant = new ProductVariantInfo();
			_variant.Ranges = new List<Range> {new Range {From = 0, To = 2, PriceInCents = 100}, new Range {From = 3, To = 999, PriceInCents = 50}};
			_variant.PriceInCents = 200;

			_product = new ProductInfo {ProductVariants = new List<ProductVariantInfo> {_variant}, ItemCount = 5};
			_variant.Product = _product;
		}
Ejemplo n.º 2
0
		public void GrandTotalWithVariants()
		{
			var productInfo = new ProductInfo {IsDiscounted = false, Vat = 6, OriginalPriceInCents = 1000, Ranges = new List<Range>()};
			productInfo.ProductVariants.Add(new ProductVariantInfo {PriceInCents = 100});

			var orderInfo = DefaultFactoriesAndSharedFunctionality.CreateOrderInfo(productInfo);

			Assert.IsTrue(orderInfo.PricesAreIncludingVAT);
			Assert.AreEqual(1100, orderInfo.GrandtotalInCents);
		}
		public void Setup()
		{
			IOC.UnitTest();
			_discountCalculationService = IOC.DiscountCalculationService.Actual().Resolve();

			_product = DefaultFactoriesAndSharedFunctionality.CreateProductInfo(1000, 1);
			_product.Tags = new [] { "schoen" };
			_order = DefaultFactoriesAndSharedFunctionality.CreateIncompleteOrderInfo(_product);

		}
		public void Setup()
		{
			IOC.UnitTest();
			IOC.OrderService.Mock(out _orderServiceMock);
			_discountCalculationService = IOC.DiscountCalculationService.Actual().Resolve();

			_discountMock = MockConstructors.CreateDiscountMock();

			_product1 = DefaultFactoriesAndSharedFunctionality.CreateProductInfo(1000, 7);
			_product2 = DefaultFactoriesAndSharedFunctionality.CreateProductInfo(1000, 4);
			_orderInfo = DefaultFactoriesAndSharedFunctionality.CreateOrderInfo(_product1, _product2);
			_orderServiceMock.Setup(m => m.GetApplicableOrderLines(_orderInfo, It.IsAny<List<int>>())).Returns(_orderInfo.OrderLines);
		}
Ejemplo n.º 5
0
		public void ThatVATAmountIsRoundedDown()
		{
			var productInfo = new ProductInfo {IsDiscounted = false, Vat = 19, ItemCount = 2, OriginalPriceInCents = 3500, Ranges = new List<Range>()};

			var orderInfo = DefaultFactoriesAndSharedFunctionality.CreateOrderInfo(productInfo);

			Assert.AreEqual(19, orderInfo.AverageOrderVatPercentage);
			Assert.AreEqual(559, productInfo.VatAmountInCents);
			Assert.AreEqual(2941, productInfo.PriceWithoutVatInCents);
			Assert.AreEqual(3500, productInfo.PriceWithVatInCents);
			Assert.AreEqual(7000, orderInfo.OrderTotalInCents);
			Assert.AreEqual(5882, orderInfo.SubtotalInCents);
			Assert.AreEqual(7000, orderInfo.GrandtotalInCents);
		}
		public void ThatPercentDiscountIsAppliedToCorrectNumberOfItemsPercentageDiscount(int setSize, int itemCount, int expectedNumberOfDiscountedItems)
		{
			var productInfo = new ProductInfo();
			productInfo.IsDiscounted = false;
			productInfo.OriginalPriceInCents = 1000;
			productInfo.Ranges = new List<Range>();
			productInfo.ItemCount = itemCount;

			var orderInfo = DefaultFactoriesAndSharedFunctionality.CreateIncompleteOrderInfo(productInfo);
			var discount = DefaultFactoriesAndSharedFunctionality.CreateDefaultOrderDiscountWithPercentageList(50, DiscountOrderCondition.PerSetOfXItems, setSize);
			DefaultFactoriesAndSharedFunctionality.SetDiscountsOnOrderInfo(orderInfo, discount.ToArray());

			Assert.AreEqual(expectedNumberOfDiscountedItems*500 + (itemCount - expectedNumberOfDiscountedItems)*1000, orderInfo.OrderTotalInCents);
		}
Ejemplo n.º 7
0
		public void GrandTotalWithOrderDiscount()
		{
			var productInfo = new ProductInfo {IsDiscounted = false, Vat = 6, OriginalPriceInCents = 1000, Ranges = new List<Range>()};

			productInfo.ProductVariants.Add(new ProductVariantInfo {PriceInCents = 100});

			var orderInfo = DefaultFactoriesAndSharedFunctionality.CreateIncompleteOrderInfo(productInfo);
			var discount = DefaultFactoriesAndSharedFunctionality.CreateDefaultOrderDiscountWithPercentage(50);
			DefaultFactoriesAndSharedFunctionality.SetDiscountsOnOrderInfo(orderInfo, discount);

			Assert.AreEqual(550, orderInfo.OrderTotalInCents);
			Assert.AreEqual(6, orderInfo.AverageOrderVatPercentage);
			Assert.AreEqual(519, orderInfo.SubtotalInCents);
			Assert.AreEqual(550, orderInfo.GrandtotalInCents);

			Assert.AreEqual(1100, orderInfo.OrderLines.First().GrandTotalInCents);
		}
		public void Setup()
		{
			IOC.UnitTest();
			IOC.OrderService.Actual();

			_discountCalculationService = IOC.DiscountCalculationService.Actual().Resolve();

			_discountMock = MockConstructors.CreateDiscountMock();

			_product1 = DefaultFactoriesAndSharedFunctionality.CreateProductInfo(1000, 7);
			_product1.Id = 156;
			_product2 = DefaultFactoriesAndSharedFunctionality.CreateProductInfo(1000, 4);
			_product2.Id = 289;

			IOC.CMSEntityRepository.SetupFake(new UwbsNode {Id = _product1.Id, NodeTypeAlias = "uwbsProduct"}, new UwbsNode {Id = _product2.Id, NodeTypeAlias = "uwbsProduct"});

			_orderInfo = DefaultFactoriesAndSharedFunctionality.CreateIncompleteOrderInfo(_product1, _product2);
		}
		public static ProductInfo CreateProductInfo(int productPriceInCents, int itemCount, decimal vat = 19, DiscountProduct discount = null, IOrderInfo order = null)
		{
			var productInfo = new ProductInfo();
			productInfo.IsDiscounted = discount == null;
			productInfo.OriginalPriceInCents = productPriceInCents;
			productInfo.Ranges = new List<Range>();
			productInfo.Vat = vat;
			productInfo.ItemCount = itemCount;
			productInfo.Tags = new string[0];
			if (order != null)
			{
				order.OrderLines = new List<OrderLine> {new OrderLine(productInfo, order)};
			}
			productInfo.Order = order ?? CreateOrderInfo(productInfo);
			if (discount != null)
			{
				SetProductDiscountOnProductInfo(productInfo, discount);
			}
			return productInfo;
		}
		/// <summary>
		/// Set product variant info based on the variant already in the order
		/// </summary>
		/// <param name="productVariant">The product variant.</param>
		/// <param name="product">The product.</param>
		/// <param name="productVat">The product vat.</param>
		public ProductVariantInfo(OrderedProductVariant productVariant, ProductInfo product, decimal productVat)
		{
			Product = product;
			
			Id = productVariant.VariantId;
			Title = productVariant.Title;
			SKU = productVariant.SKU;
			Group = productVariant.Group;
			Weight = productVariant.Weight;
			Length = productVariant.Length;
			Height = productVariant.Height;
			Width = productVariant.Width;
			PriceInCents = productVariant.PriceInCents;
			RangesString = productVariant.RangesString;
			ChangedOn = DateTime.Now;
			Vat = productVat;
			DiscountAmountInCents = productVariant.DiscountAmount;
			DiscountPercentage = productVariant.DiscountPercentage;

			DocTypeAlias = productVariant.TypeAlias ?? productVariant.DocTypeAlias;
		}
Ejemplo n.º 11
0
 private OrderLine()
 {
     ProductInfo = new ProductInfo();            // { ItemCount = 0 }; evt of 1?
 }
Ejemplo n.º 12
0
		public void GrandTotalWithOrderDiscoun214t()
		{
			IOC.OrderService.Actual();

			var productInfo = new ProductInfo { Id = 1234, IsDiscounted = false, Vat = 0, OriginalPriceInCents = 1000, Ranges = new List<Range>() };
			IOC.CMSEntityRepository.SetupNewMock().Setup(m => m.GetByGlobalId(1234)).Returns(new UwbsNode {Id = 1234, NodeTypeAlias = Product.NodeAlias});

			var orderInfo = DefaultFactoriesAndSharedFunctionality.CreateIncompleteOrderInfo(productInfo);
			var discount = DefaultFactoriesAndSharedFunctionality.CreateDefaultOrderDiscountWithAmount(10, DiscountOrderCondition.None, 0);
			discount.AffectedOrderlines = new List<int>{1234};
			DefaultFactoriesAndSharedFunctionality.SetDiscountsOnOrderInfo(orderInfo, discount);

			Assert.AreEqual(10, orderInfo.DiscountAmountInCents);

			Assert.AreEqual(990, orderInfo.GrandtotalInCents);
			Assert.AreEqual(990, orderInfo.OrderTotalInCents);
			Assert.AreEqual(0, orderInfo.AverageOrderVatPercentage);
			Assert.AreEqual(990, orderInfo.SubtotalInCents);
		}
		public OrderedProductInfoAdaptor(ProductInfo source)
		{
			_source = source;
		}
Ejemplo n.º 14
0
		/// <summary>
		/// Initializes a new instance of the <see cref="OrderLine"/> class.
		/// </summary>
		/// <param name="productInfo">The product information.</param>
		/// <param name="order">The order.</param>
		public OrderLine(ProductInfo productInfo, IOrderInfo order)
		{
			Order = order;
			productInfo.Order = order;
			ProductInfo = productInfo;
		}
Ejemplo n.º 15
0
		private OrderLine()
		{
			ProductInfo = new ProductInfo();// { ItemCount = 0 }; evt of 1?
		}
Ejemplo n.º 16
0
		public void SomeRegressionTest()
		{
			var productInfo = new ProductInfo {IsDiscounted = false, Vat = 6, OriginalPriceInCents = 1000, Ranges = new List<Range>()};

			productInfo.ProductVariants.Add(new ProductVariantInfo {PriceInCents = -100});

			var orderInfo = DefaultFactoriesAndSharedFunctionality.CreateIncompleteOrderInfo(productInfo);
			var discount = DefaultFactoriesAndSharedFunctionality.CreateDefaultOrderDiscountWithPercentage(50);
			DefaultFactoriesAndSharedFunctionality.SetDiscountsOnOrderInfo(orderInfo, discount);

			var line = orderInfo.OrderLines.Single();
			var sellableUnit = orderInfo.OrderLines.Single().SellableUnits.Single();

			Assert.AreEqual(900, sellableUnit.PriceInCents);
			Assert.AreEqual(51, line.VatAmountInCents);
			Assert.AreEqual(849, line.SubTotalInCents);

			Assert.AreEqual(425, orderInfo.SubtotalInCents);
			
			Assert.AreEqual(450, orderInfo.OrderTotalInCents);
			Assert.AreEqual(6, orderInfo.AverageOrderVatPercentage);
			Assert.AreEqual(450, orderInfo.GrandtotalInCents);

			Assert.AreEqual(900, orderInfo.OrderLines.First().GrandTotalInCents);
			Assert.AreEqual(900, productInfo.PriceWithVatInCents);

		}
Ejemplo n.º 17
0
		public SellableUnit(ProductInfo product)
		{
			Product = product;
			SellableUnitDiscountEffects = new DiscountEffects();
		}
Ejemplo n.º 18
0
		public void ProductInfo_PriceCalculationRegressionTest()
		{
			IOC.IntegrationTest();
			var product = new ProductInfo { OriginalPriceInCents = 990000, DiscountAmountInCents = 990000 - 100000 };
			var order = DefaultFactoriesAndSharedFunctionality.CreateIncompleteOrderInfo(product);

			Assert.AreEqual(990000, product.Price.BeforeDiscount.ValueInCents());
			Assert.AreEqual(100000, product.Price.ValueInCents());
			Assert.AreEqual(890000, product.Price.Discount.WithVat.ValueInCents);
		}
		public OrderedProductVariantInfoAdapter(ProductVariantInfo source, ProductInfo product)
		{
			_source = source;
			_source.Product = product;
		}
		public static void SetVariantsOnProductInfo(ProductInfo productInfo, params ProductVariantInfo[] variants)
		{
			productInfo.ProductVariants = variants.ToList();
			foreach (var variant in variants)
				variant.Product = productInfo;
		}
		public static void SetProductDiscountOnProductInfo(ProductInfo productInfo, DiscountProduct discount)
		{
			// todo: NewPrice. Maybe move this functionality elsewhere? (duplicate logic)
			if (discount.DiscountType == DiscountType.Amount)
				productInfo.DiscountAmountInCents = discount.RangedDiscountValue(productInfo.ItemCount.GetValueOrDefault(1));
			else
				productInfo.DiscountPercentage = discount.RangedDiscountValue(productInfo.ItemCount.GetValueOrDefault(1))/100m;
		}
Ejemplo n.º 22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OrderLine"/> class.
 /// </summary>
 /// <param name="productInfo">The product information.</param>
 /// <param name="order">The order.</param>
 public OrderLine(ProductInfo productInfo, IOrderInfo order)
 {
     Order             = order;
     productInfo.Order = order;
     ProductInfo       = productInfo;
 }
		/// <summary>
		/// Set product variant info based on a product variant in the catalog
		/// </summary>
		/// <param name="productVariant">The product variant.</param>
		/// <param name="product">The product.</param>
		/// <param name="itemCount">The item count.</param>
		public ProductVariantInfo(ProductVariant productVariant, ProductInfo product, int itemCount)
		{
			Product = product;

			Id = productVariant.Id;
			Title = productVariant.Title;
			SKU = productVariant.SKU;

			var groupname = string.Empty;
			if (string.IsNullOrEmpty(productVariant.Group))
			{
				var productVariantGroup = DomainHelper.GetProductVariantGroupById(productVariant.ParentId);

				if (productVariantGroup != null)
				{
					groupname = productVariantGroup.Title;
				}
			}
			else
			{
				groupname = productVariant.Group;
			}

			Group = groupname;

			Weight = productVariant.Weight;
			Length = productVariant.Length;
			Height = productVariant.Height;
			Width = productVariant.Width;

			PriceInCents = productVariant.OriginalPriceInCents;
			Ranges = productVariant.Ranges; // = localized

			ChangedOn = DateTime.Now;
			Vat = productVariant.Vat;

			if (productVariant.IsDiscounted)
			{
				DiscountId = productVariant.ProductVariantDiscount.Id;
				if (productVariant.ProductVariantDiscount.DiscountType == DiscountType.Amount)
					DiscountAmountInCents = productVariant.ProductVariantDiscount.RangedDiscountValue(itemCount);
				else if (productVariant.ProductVariantDiscount.DiscountType == DiscountType.Percentage)
					DiscountPercentage = productVariant.ProductVariantDiscount.RangedDiscountValue(itemCount)/100m;
				else if (productVariant.ProductVariantDiscount.DiscountType == DiscountType.NewPrice)
					PriceInCents = productVariant.ProductVariantDiscount.RangedDiscountValue(itemCount);
			}

			DocTypeAlias = productVariant.NodeTypeAlias;
		}
		protected void DocumentAfterPublish(Document sender, PublishEventArgs e)
		{
			// when thinking about adding something here, consider ContentOnAfterUpdateDocumentCache!

			if (sender.Level > 2)
			{
				if (sender.ContentType.Alias == Order.NodeAlias || sender.Parent != null && (OrderedProduct.IsAlias(sender.ContentType.Alias) || sender.Parent.Parent != null && OrderedProductVariant.IsAlias(sender.ContentType.Alias)))
				{
					var orderDoc = sender.ContentType.Alias == Order.NodeAlias ? sender : (OrderedProduct.IsAlias(sender.ContentType.Alias) && !OrderedProductVariant.IsAlias(sender.ContentType.Alias) ? new Document(sender.Parent.Id) : new Document(sender.Parent.Parent.Id));

					if (orderDoc.ContentType.Alias != Order.NodeAlias)
						throw new Exception("There was an error in the structure of the order documents");

					// load existing orderInfo (why..? => possibly to preserve information not represented in the umbraco documents)

					if (string.IsNullOrEmpty(orderDoc.getProperty("orderGuid").Value.ToString()))
					{
						Store store = null;
						var storeDoc = sender.GetAncestorDocuments().FirstOrDefault(x => x.ContentType.Alias == OrderStoreFolder.NodeAlias);

						if (storeDoc != null)
						{
							store = StoreHelper.GetAllStores().FirstOrDefault(x => x.Name == storeDoc.Text);
						}

						if (store == null)
						{
							store = StoreHelper.GetAllStores().FirstOrDefault();
						}

						var orderInfo = OrderHelper.CreateOrder(store);
						IO.Container.Resolve<IOrderNumberService>().GenerateAndPersistOrderNumber(orderInfo);
						orderInfo.Status = OrderStatus.Confirmed;
						orderInfo.Save();

						sender.SetProperty("orderGuid", orderInfo.UniqueOrderId.ToString());
						sender.Save();
					}
					else
					{
						var orderGuid = Guid.Parse(orderDoc.getProperty("orderGuid").Value.ToString());

						var orderInfo = OrderHelper.GetOrderInfo(orderGuid);

						var order = new Order(orderDoc.Id);
						orderInfo.CustomerEmail = order.CustomerEmail;
						orderInfo.CustomerFirstName = order.CustomerFirstName;
						orderInfo.CustomerLastName = order.CustomerLastName;

						var dictionaryCustomer = orderDoc.GenericProperties.Where(x => x.PropertyType.Alias.StartsWith("customer")).ToDictionary(customerProperty => customerProperty.PropertyType.Alias, customerProperty => customerProperty.Value.ToString());
						orderInfo.AddCustomerFields(dictionaryCustomer, CustomerDatatypes.Customer);

						var dictionaryShipping = orderDoc.GenericProperties.Where(x => x.PropertyType.Alias.StartsWith("shipping")).ToDictionary(property => property.PropertyType.Alias, property => property.Value.ToString());
						orderInfo.AddCustomerFields(dictionaryShipping, CustomerDatatypes.Shipping);

						var dictionarExtra = orderDoc.GenericProperties.Where(x => x.PropertyType.Alias.StartsWith("extra")).ToDictionary(property => property.PropertyType.Alias, property => property.Value.ToString());
						orderInfo.AddCustomerFields(dictionarExtra, CustomerDatatypes.Extra);

						//orderInfo.SetVATNumber(order.CustomerVATNumber); happens in AddCustomerFields
						var orderPaidProperty = order.Document.getProperty("orderPaid");
						if (orderPaidProperty != null && orderPaidProperty.Value != null)
							orderInfo.Paid = orderPaidProperty.Value == "1";

						// load data recursively from umbraco documents into order tree
						orderInfo.OrderLines = orderDoc.Children.Select(d =>
							{
								var fields = d.GenericProperties.Where(x => !OrderedProduct.DefaultProperties.Contains(x.PropertyType.Alias)).ToDictionary(s => s.PropertyType.Alias, s => d.GetProperty<string>(s.PropertyType.Alias));

								var xDoc = new XDocument(new XElement("Fields"));

								OrderUpdatingService.AddFieldsToXDocumentBasedOnCMSDocumentType(xDoc, fields, d.ContentType.Alias);

								var orderedProduct = new OrderedProduct(d.Id);

								var productInfo = new ProductInfo(orderedProduct, orderInfo);
								productInfo.ProductVariants = d.Children.Select(cd => new ProductVariantInfo(new OrderedProductVariant(cd.Id), productInfo, productInfo.Vat)).ToList();
								return new OrderLine(productInfo, orderInfo) {_customData = xDoc};
							}).ToList();

						// store order
						IO.Container.Resolve<IOrderRepository>().SaveOrderInfo(orderInfo);
					}
					// cancel does give a warning message balloon in Umbraco.
					//e.Cancel = true;

					//if (sender.ContentType.Alias != Order.NodeAlias)
					//{
					//	orderDoc.Publish(new User(0));
					//}

					//if (orderDoc.ParentId != 0)
					//{
					BasePage.Current.ClientTools.SyncTree(sender.Parent.Path, false);
					BasePage.Current.ClientTools.ChangeContentFrameUrl(string.Concat("editContent.aspx?id=", sender.Id));
					//}
					//orderDoc.delete();
					BasePage.Current.ClientTools.ShowSpeechBubble(BasePage.speechBubbleIcon.success, "Order Updated!", "This order has been updated!");
				}
			}
		}