Exemplo n.º 1
0
		/// <param name="searchVmFactory"></param>
		/// <param name="item"></param>
		/// <param name="preloadedItems">preloaded prices against which the validation will be done.</param>
		/// <param name="isAllFieldsVisible"></param>
		/// <param name="repositoryFactory"></param>
		public PriceViewModel(Price item,
			bool isAllFieldsVisible,
			IEnumerable preloadedItems,
			IViewModelsFactory<ISearchItemViewModel> searchVmFactory,
			IRepositoryFactory<IPricelistRepository> repositoryFactory)
		{
			_innerItem = item;
			_preloadedItems = preloadedItems;
			IsAllFieldsVisible = isAllFieldsVisible;
			_searchVmFactory = searchVmFactory;
			_repositoryFactory = repositoryFactory;

			IsItemChangeable = string.IsNullOrEmpty(item.ItemId);

			ItemPickCommand = new DelegateCommand(RaiseItemPickInteractionRequest);
			CommonConfirmRequest = new InteractionRequest<Confirmation>();
		}
		public void Can_double_add_pricelist_item()
		{
			CreateCatalogGraf();
			var item = GetCatalogItems();

			var pricelistId = CreatePriceList("Test pricelist");

			var client = GetRepository();

			// load to detail view
			var innerItem = client.Pricelists.Where(x => x.PricelistId == pricelistId)
						.Expand("Prices/CatalogItem")
						.SingleOrDefault();
			Assert.NotNull(innerItem);

			//add a price
			var price = new Price { List = 10, MinQuantity = 1, /*CatalogItem = item,*/ ItemId = item.ItemId, PricelistId = pricelistId };
			innerItem.Prices.Add(price);

			// remove just added price
			innerItem.Prices.Remove(price);

			//add a price again with the same CatalogItem
			price = new Price { List = 20, MinQuantity = 1, /*CatalogItem = item,*/ ItemId = item.ItemId, PricelistId = pricelistId };
			var priceId = price.PriceId;
			innerItem.Prices.Add(price);

			client.UnitOfWork.Commit();

			// check 
			client = GetRepository();
			innerItem = client.Pricelists.Where(x => x.PricelistId == pricelistId)
						.Expand("Prices/CatalogItem")
						.SingleOrDefault();

			Assert.NotNull(innerItem);
			Assert.True(innerItem.Prices.Any());
			Assert.True(innerItem.Prices[0].PriceId == priceId);

		}
Exemplo n.º 3
0
		private static Price InitializeItem(Price item, IEnumerable<ImportItem> systemValues)
		{
			if (item == null)
				item = new CatalogEntityFactory().CreateEntity<Price>();
			var priceId = systemValues.FirstOrDefault(price => price.Name == "PriceId");
			if (priceId != null)
				systemValues.FirstOrDefault(price => price.Name == "PriceId").Value = priceId.Value ?? item.PriceId;
			var itemProperties = item.GetType().GetProperties();
			systemValues.ToList().ForEach(x => SetPropertyValue(item, itemProperties.FirstOrDefault(y => y.Name == x.Name), x.Value));

			return item;
		}
Exemplo n.º 4
0
		protected PricelistAssignment GeneratePrices(IEnumerable<Item> items, string catalogId)
		{
			var pricelist = new Pricelist
			{
				Currency = CustomerSessionService.CustomerSession.Currency,
				Name = "TestPrice",
			};

			foreach (var item in items)
			{
				var price = new Price
				{
					Sale = 100,
					List = 120,
					ItemId = item.ItemId,
					MinQuantity = 1,
					PricelistId = pricelist.PricelistId,
				};

				pricelist.Prices.Add(price);
			}

			var priceListAssignment = new PricelistAssignment
			{
				CatalogId = catalogId,
				Name = "testAssigment",
				Pricelist = pricelist,
				PricelistId = pricelist.PricelistId
			};

			PricelistRepository.Add(priceListAssignment);
			PricelistRepository.UnitOfWork.Commit();

			return priceListAssignment;
		}
		//[RepositoryTheory]
		public void Can_and_price_with_the_same_ItemId_and_different_Quantity_Method2()
		{

			CreateCatalogGraf();
			var item = GetCatalogItems();

			var pricelistId = CreatePriceList("Test pricelist");

			var client1 = GetRepository();

			// load to detail view
			var pricelist = client1.Pricelists.Where(x => x.PricelistId == pricelistId)
				.Expand("Prices/CatalogItem")
				.SingleOrDefault();
			Assert.NotNull(pricelist);

			//add a price
			var price = new Price
			{
				List = 10,
				MinQuantity = 3,
				/*CatalogItem = item,*/
				ItemId = item.ItemId,
				PricelistId = pricelistId
			};
			var priceId = price.PriceId;
			pricelist.Prices.Add(price);

			client1.UnitOfWork.Commit();

			// we have one price list in DB now

			var client2 = GetRepository();

			// load to detail view
			pricelist = client2.Pricelists.Where(x => x.PricelistId == pricelistId)
				.Expand("Prices/CatalogItem")
				.SingleOrDefault();
			Assert.NotNull(pricelist);
			Assert.True(pricelist.Prices.Any());
			price = pricelist.Prices[0];
			Assert.True(price.PriceId == priceId && price.MinQuantity == 3 && price.ItemId == item.ItemId);

			//add a price again with different Quantity
			price = new Price
			{
				List = 10,
				MinQuantity = 2,
				/*CatalogItem = item,*/
				ItemId = item.ItemId,
				PricelistId = pricelistId
			};

			// this is the difference with Can_and_price_with_the_same_ItemId_and_different_Quantity_Method1
			price.CatalogItem = item;
			pricelist.Prices.Add(price);

			client2.UnitOfWork.Commit();
		}
		public void Can_modify_pricelist_price()
		{
			CreateCatalogGraf();
			var item = GetCatalogItems();

			var pricelistId = CreatePriceList("Test pricelist2");

			var client = GetRepository();

			// load to detail view
			var innerItem = client.Pricelists.Where(x => x.PricelistId == pricelistId)
						.Expand("Prices/CatalogItem")
						.SingleOrDefault();
			Assert.NotNull(innerItem);

			//add a price
			var price = new Price { List = 10, MinQuantity = 1, /*CatalogItem = item,*/ ItemId = item.ItemId, PricelistId = pricelistId };
			innerItem.Prices.Add(price);

			client.UnitOfWork.Commit();

			innerItem = client.Pricelists.Where(x => x.PricelistId == pricelistId)
						.Expand("Prices/CatalogItem")
						.SingleOrDefault();
			Assert.NotNull(innerItem);
			price = innerItem.Prices[0];
			//price.Pricelist = innerItem;
			price.Sale = 1;
			client.Update(innerItem);
			client.UnitOfWork.Commit();

			price.Sale = 2;
			client.UnitOfWork.Commit();

			// check 
			client = GetRepository();
			innerItem = client.Pricelists.Where(x => x.PricelistId == pricelistId)
						.Expand("Prices/CatalogItem")
						.SingleOrDefault();

			Assert.NotNull(innerItem);
			Assert.True(innerItem.Prices.Any());
			//Assert.True(innerItem.Prices[0].PriceId == priceId);

		}
Exemplo n.º 7
0
		public static Price Clone(Price price)
		{
			var value = new Price
			{
				_List = price._List,
				_Sale = price._Sale,
				_MinQuantity = price._MinQuantity,
				_ItemId = price._ItemId,
				_PricelistId = price._PricelistId,
				_PriceId = price._PriceId,
				CatalogItem = price.CatalogItem
			};
			return value;
		}
		public decimal GetItemDiscountPrice(Item item, Price lowestPrice, Hashtable tags = null)
		{
			var price = lowestPrice.Sale ?? lowestPrice.List;

			var session = _customerSession.CustomerSession;

			// apply discounts
			// create context 
			var ctx = new Dictionary<string, object>();
			var set = GetPromotionEntrySetFromItem(item, price, tags);
			ctx.Add(PromotionEvaluationContext.TargetSet, set);

			var evaluationContext = new PromotionEvaluationContext
				{
					ContextObject = ctx,
					CustomerId = session.CustomerId,
					CouponCode = null,
					Currency = session.Currency,
					PromotionType = PromotionType.CatalogPromotion,
					Store = session.StoreId,
					IsRegisteredUser = session.IsRegistered,
					IsFirstTimeBuyer = session.IsFirstTimeBuyer
				};

			var promotions = _evaluator.EvaluatePromotion(evaluationContext);
            var rewards = promotions.SelectMany(x => x.Rewards).ToArray();
            var records = new List<PromotionRecord>();

            records.AddRange(rewards.Select(reward => new PromotionRecord
            {
                AffectedEntriesSet = set,
                TargetEntriesSet = set,
                Reward = reward,
                PromotionType = PromotionType.CatalogPromotion
            }));

            //Filter by policies
		    var allRecords = _evaluator.EvaluatePolicies(records.ToArray());

            var lineItemRewards = allRecords.Select(x=>x.Reward).OfType<CatalogItemReward>().ToArray();

			var discountTotal = 0m;
			foreach (var reward in lineItemRewards)
			{
				if (reward.QuantityLimit > 1) // skip everything for higher quantity
				{
					continue;
				}

				if (!String.IsNullOrEmpty(reward.SkuId)) // filter out free item rewards
				{
					if (!item.ItemId.Equals(reward.SkuId, StringComparison.OrdinalIgnoreCase))
					{
						continue;
					}
				}

				var discountAmount = 0m;
				const int quantity = 1;
				if (reward.AmountTypeId == (int)RewardAmountType.Relative)
				{
					discountAmount = Math.Round(quantity*price*reward.Amount*0.01m,2);
				}
				else if (reward.AmountTypeId == (int)RewardAmountType.Absolute)
				{
					discountAmount =  Math.Round(quantity*reward.Amount,2);
				}
				discountTotal += discountAmount;
			}

			return discountTotal;
		}