コード例 #1
0
        public override ValidationResult Validate(ValidateCartContextArgs entity, ValidationMode validationMode)
        {
            var result = new ValidationResult();
            var order  = entity.Cart.Order;

            if (order.Rows.Count > 0)
            {
                var personId  = order.CustomerInfo?.PersonSystemId ?? _securityContextService.GetIdentityUserSystemId() ?? Guid.Empty;
                var orderRows = order.Rows.Where(x => x.OrderRowType == OrderRowType.Product)
                                .Select(orderRow => _salesOrderRowFactory.Create(new CreateSalesOrderRowArgs
                {
                    ArticleNumber    = orderRow.ArticleNumber,
                    Quantity         = orderRow.Quantity,
                    PersonSystemId   = personId,
                    ChannelSystemId  = order.ChannelSystemId ?? Guid.Empty,
                    CountrySystemId  = _countryService.Get(order.CountryCode)?.SystemId ?? Guid.Empty,
                    CurrencySystemId = _currencyService.Get(order.CurrencyCode)?.SystemId ?? Guid.Empty
                }));

                if (orderRows.Any(result => result == null))
                {
                    result.AddError("Cart", "sales.validation.product.nolongeravailableforsale".AsWebsiteText());
                }
            }

            return(result);
        }
コード例 #2
0
        public override ValidationResult Validate(ValidateCartContextArgs entity, ValidationMode validationMode)
        {
            var result = new ValidationResult();
            var order  = entity.Cart.Order;

            if (order.Rows.Count > 0)
            {
                var personId  = order.CustomerInfo?.PersonSystemId ?? _securityContextService.GetIdentityUserSystemId() ?? Guid.Empty;
                var orderRows = from orderRow in order.Rows.Where(x => x.OrderRowType == OrderRowType.Product)
                                let createdRow = _salesOrderRowFactory.Create(new CreateSalesOrderRowArgs
                {
                    ArticleNumber    = orderRow.ArticleNumber,
                    Quantity         = orderRow.Quantity,
                    PersonSystemId   = personId,
                    ChannelSystemId  = order.ChannelSystemId ?? Guid.Empty,
                    CountrySystemId  = _countryService.Get(order.CountryCode)?.SystemId ?? Guid.Empty,
                    CurrencySystemId = _currencyService.Get(order.CurrencyCode)?.SystemId ?? Guid.Empty
                })
                                                 where createdRow != null
                                                 where orderRow.UnitPriceExcludingVat != createdRow.UnitPriceExcludingVat ||
                                                 orderRow.VatRate != createdRow.VatRate
                                                 select orderRow;

                if (orderRows.Any())
                {
                    result.AddError("Cart", "sales.validation.productprices.haschanged".AsWebsiteText());
                }
            }

            return(result);
        }