private string CreatePriceList(string name)
		{
			using (var client = GetRepository())
			{
				var pricelist = new Pricelist { Name = name, Currency = "USD" };
				client.Add(pricelist);
				client.UnitOfWork.Commit();
				return pricelist.PricelistId;
			}
		}
예제 #2
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;
		}
 public PriceListOverviewStepViewModel(IRepositoryFactory<IPricelistRepository> repositoryFactory,
     IRepositoryFactory<IAppConfigRepository> appConfigRepositoryFactory, 
     ICatalogEntityFactory entityFactory, IAuthenticationContext authContext, Pricelist item)
     : base(repositoryFactory, appConfigRepositoryFactory,  entityFactory, authContext, item)
 {
 }
 public CreatePriceListViewModel(IViewModelsFactory<IPriceListOverviewStepViewModel> vmFactory, Pricelist item)
 {
     RegisterStep(vmFactory.GetViewModelInstance(new KeyValuePair<string, object>("item", item)));
 }
		public void Can_run_activity_validatelineitems()
		{
			var orderGroup = CreateCart();

			orderGroup.OrderForms[0].LineItems[0].Catalog = "default";
			orderGroup.OrderForms[0].LineItems[0].CatalogItemId = "v-9948444183";
			orderGroup.OrderForms[0].LineItems[0].FulfillmentCenterId = "default";
			orderGroup.OrderForms[0].LineItems[0].Quantity = 4;
			orderGroup.OrderForms[0].LineItems[1].Catalog = "default";
			orderGroup.OrderForms[0].LineItems[1].CatalogItemId = "v-b000068ilf";
			orderGroup.OrderForms[0].LineItems[1].FulfillmentCenterId = "default";
			orderGroup.OrderForms[0].LineItems[1].Quantity = 10;


			var invAvailable = new Inventory
				{
					AllowBackorder = true,
					AllowPreorder = true,
					FulfillmentCenterId = "default",
					InStockQuantity = 10,
					Sku = "v-9948444183",
					ReservedQuantity = 1,
					Status = InventoryStatus.Enabled.GetHashCode(),
					BackorderQuantity = 5,
					PreorderQuantity = 3
				};

			var invNotAvailable = new Inventory
				{
					AllowBackorder = true,
					AllowPreorder = true,
					FulfillmentCenterId = "default",
					InStockQuantity = 14,
					Sku = "v-b000068ilf",
					ReservedQuantity = 10,
					BackorderQuantity = 10,
					Status = InventoryStatus.Enabled.GetHashCode(),
					PreorderQuantity = 4
				};

			var mockUnitOfWork = new Mock<IUnitOfWork>();
			var repository = new Mock<IInventoryRepository>();
			repository.Setup(x => x.Inventories).Returns(() => new[] { invAvailable, invNotAvailable }.AsQueryable());
			repository.Setup(x => x.UnitOfWork).Returns(mockUnitOfWork.Object);
			repository.SetupAllProperties();

			var item1 = new Product
				{
					ItemId = "v-9948444183",
					TrackInventory = true,
					IsActive = true,
					IsBuyable = true,
					StartDate = DateTime.UtcNow.AddDays(-1),
					EndDate = DateTime.UtcNow.AddDays(1)
				};

			var item2 = new Product
				{
					ItemId = "v-b000068ilf",
					IsActive = true,
					IsBuyable = true,
					TrackInventory = true,
					StartDate = DateTime.UtcNow.AddDays(-1),
					EndDate = DateTime.UtcNow.AddDays(1)
				};

			var catrepository = new Mock<ICatalogRepository>();
			catrepository.Setup(x => x.Items).Returns(() => new Item[] { item1, item2 }.AsQueryable());
			catrepository.Setup(x => x.UnitOfWork).Returns(mockUnitOfWork.Object);
			catrepository.SetupAllProperties();

			var store = new Store { StoreId = orderGroup.StoreId, Catalog = orderGroup.OrderForms[0].LineItems[0].Catalog };
			var storeRepository = new Mock<IStoreRepository>();
			storeRepository.Setup(x => x.Stores).Returns(() => new[] { store }.AsQueryable());

			var priceList = new Pricelist { PricelistId = "default", Currency = "USD" };
			var priceList2 = new Pricelist { PricelistId = "sale", Currency = "USD" };
			var prices = new[] 
            {
                new Price { List = 100, Sale = 90, MinQuantity = 1, ItemId = "v-9948444183" , PricelistId = "default"},
                new Price { List = 95, Sale = 85, MinQuantity = 5, ItemId = "v-9948444183", PricelistId = "default"},
                new Price { List = 98, Sale = 88, MinQuantity = 1, ItemId = "v-9948444183" , PricelistId = "sale"},
                new Price { List = 93, Sale = 83, MinQuantity = 5, ItemId = "v-9948444183", PricelistId = "sale"},
                new Price { List = 60, Sale = 50, MinQuantity = 1, ItemId = "v-b000068ilf" , PricelistId = "default"},
                new Price { List = 55, Sale = 45, MinQuantity = 5, ItemId = "v-b000068ilf", PricelistId = "default"},
                new Price { List = 58, Sale = 48, MinQuantity = 1, ItemId = "v-b000068ilf" , PricelistId = "sale"},
                new Price { List = 53, Sale = 43, MinQuantity = 5, ItemId = "v-b000068ilf", PricelistId = "sale"}

            };

			var priceRepository = new Mock<IPricelistRepository>();
			priceRepository.Setup(x => x.Pricelists).Returns(() => new[] { priceList2, priceList }.AsQueryable());
			priceRepository.Setup(x => x.Prices).Returns(prices.AsQueryable);

			var customerService = new CustomerSessionService();
			var session = customerService.CustomerSession;
			session.Currency = "USD";
			session.Pricelists = new[] { "Sale", "Default" };

			var currencyService = new CurrencyService();

			var cacheRepository = new Mock<ICacheRepository>();
			cacheRepository.SetupAllProperties();

			var activity = new ValidateLineItemsActivity(repository.Object, catrepository.Object, storeRepository.Object, customerService, priceRepository.Object, currencyService, null, null, cacheRepository.Object);

			var result = InvokeActivity(activity, orderGroup);

			var order = result.OrderGroup;
			// now check totals            

			// Order totals
			// Order form totals
			var form = order.OrderForms[0];

			Assert.True(form.LineItems.Count == 2);
			Assert.True(form.LineItems[0].InStockQuantity == 9);
			Assert.True(form.LineItems[0].PreorderQuantity == 3);
			Assert.True(form.LineItems[0].ListPrice == 88);
			Assert.True(form.LineItems[1].ListPrice == 43);
		}