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);
        }
        private void FillPricelistAssignmentConditions(PricelistAssignment assignment)
        {
            var defaultExpressionTree = _extensionManager.PriceConditionTree;

            //Set default expression tree first
            assignment.DynamicExpression = defaultExpressionTree;
            if (!string.IsNullOrEmpty(assignment.PredicateVisualTreeSerialized))
            {
                assignment.DynamicExpression = JsonConvert.DeserializeObject <IConditionTree>(assignment.PredicateVisualTreeSerialized, new ConditionJsonConverter());
                if (defaultExpressionTree != null)
                {
                    //Copy available elements from default tree because they not persisted
                    var sourceBlocks = defaultExpressionTree.Traverse(x => x.Children);
                    var targetBlocks = assignment.DynamicExpression.Traverse(x => x.Children).ToList();

                    foreach (var sourceBlock in sourceBlocks)
                    {
                        foreach (var targetBlock in targetBlocks.Where(x => x.Id == sourceBlock.Id))
                        {
                            targetBlock.AvailableChildren = sourceBlock.AvailableChildren;
                        }
                    }
                    //copy available elements from default expression tree
                    assignment.DynamicExpression.AvailableChildren = defaultExpressionTree.AvailableChildren;
                }
            }
        }
Exemplo n.º 3
0
        public async Task GetByIdsAsync_GetThenSavePricelistAssignment_ReturnCachedPricelistAssignment()
        {
            //Arrange
            var id = Guid.NewGuid().ToString();
            var newPricelistAssignment = new PricelistAssignment {
                Id = id
            };
            var newPricelistAssignmentEntity = AbstractTypeFactory <PricelistAssignmentEntity> .TryCreateInstance().FromModel(newPricelistAssignment, new PrimaryKeyResolvingMap());

            var service = GetPricingServiceImplWithPlatformMemoryCache();

            _repositoryMock.Setup(x => x.Add(newPricelistAssignmentEntity))
            .Callback(() =>
            {
                _repositoryMock.Setup(o => o.GetPricelistAssignmentsByIdAsync(new[] { id }))
                .ReturnsAsync(new[] { newPricelistAssignmentEntity });
            });

            //Act
            var nullPricelistAssignment = await service.GetPricelistAssignmentsByIdAsync(new[] { id });

            await service.SavePricelistAssignmentsAsync(new[] { newPricelistAssignment });

            var PricelistAssignment = await service.GetPricelistAssignmentsByIdAsync(new[] { id });

            //Assert
            Assert.NotEqual(nullPricelistAssignment, PricelistAssignment);
        }
 public PriceListAssignmentOverviewStepViewModel(
     IRepositoryFactory <IPricelistRepository> repositoryFactory,
     IRepositoryFactory <ICatalogRepository> catalogRepositoryFactory,
     ICatalogEntityFactory entityFactory,
     IAuthenticationContext authContext,
     PricelistAssignment item)
     : base(null, repositoryFactory, catalogRepositoryFactory, entityFactory, authContext, item)
 {
 }
 public PriceListAssignmentSetConditionsStepViewModel(
     IRepositoryFactory <ICountryRepository> countryRepositoryFactory,
     IRepositoryFactory <IPricelistRepository> repositoryFactory,
     IRepositoryFactory <ICatalogRepository> catalogRepositoryFactory,
     ICatalogEntityFactory entityFactory,
     IAuthenticationContext authContext,
     PricelistAssignment item)
     : base(countryRepositoryFactory, repositoryFactory, catalogRepositoryFactory, entityFactory, authContext, item)
 {
 }
 public CreatePriceListAssignmentViewModel(
     IViewModelsFactory <IPriceListAssignmentOverviewStepViewModel> overviewVmFactory,
     IViewModelsFactory <IPriceListAssignmentSetConditionsStepViewModel> conditionsVmFactory,
     IViewModelsFactory <IPriceListAssignmentSetDatesStepViewModel> datesVmFactory,
     PricelistAssignment item)
 {
     RegisterStep(overviewVmFactory.GetViewModelInstance(
                      new KeyValuePair <string, object>("item", item)));
     RegisterStep(conditionsVmFactory.GetViewModelInstance(
                      new KeyValuePair <string, object>("item", item)));
     RegisterStep(datesVmFactory.GetViewModelInstance(
                      new KeyValuePair <string, object>("item", item)));
 }
Exemplo n.º 7
0
        public virtual ExportablePricelistAssignment FromModel(PricelistAssignment source)
        {
            Type        = nameof(PricelistAssignment);
            CatalogId   = source.CatalogId;
            EndDate     = source.EndDate;
            Id          = source.Id;
            PricelistId = source.PricelistId;
            Description = source.Description;
            Priority    = source.Priority;
            StartDate   = source.StartDate;
            Name        = source.Name;
            Code        = null;
            ImageUrl    = null;
            Parent      = null;

            return(this);
        }
        private void SerializePricelistAssigmentConditions(PricelistAssignment assignment)
        {
            //Serialize condition expression
            if (assignment.DynamicExpression?.Children != null)
            {
                var conditionExpression = ((PriceConditionTree)assignment.DynamicExpression).GetConditions();
                assignment.ConditionExpression = JsonConvert.SerializeObject(conditionExpression);

                //Clear availableElements in expression (for decrease size)
                assignment.DynamicExpression.AvailableChildren = null;
                var allBlocks = assignment.DynamicExpression.Traverse(x => x.Children);
                foreach (var block in allBlocks)
                {
                    block.AvailableChildren = null;
                }
                assignment.PredicateVisualTreeSerialized = JsonConvert.SerializeObject(assignment.DynamicExpression);
            }
        }
Exemplo n.º 9
0
 public IHttpActionResult UpdatePriceListAssignment(PricelistAssignment assignment)
 {
     _pricingService.SavePricelistAssignments(new[] { assignment });
     return(StatusCode(HttpStatusCode.NoContent));
 }
Exemplo n.º 10
0
 public IHttpActionResult CreatePricelistAssignment(PricelistAssignment assignment)
 {
     _pricingService.SavePricelistAssignments(new[] { assignment });
     return(Ok(assignment));
 }
Exemplo n.º 11
0
        public async Task <IActionResult> UpdatePriceListAssignment([FromBody] PricelistAssignment assignment)
        {
            await _pricingService.SavePricelistAssignmentsAsync(new[] { assignment });

            return(NoContent());
        }
Exemplo n.º 12
0
        public async Task <IActionResult> CreatePricelistAssignment([FromBody] PricelistAssignment assignment)
        {
            await _pricingService.SavePricelistAssignmentsAsync(new[] { assignment });

            return(Ok(assignment));
        }