Exemple #1
0
        protected virtual async Task <OrderLine> GenerateOrderLineAsync(CreateOrderDto input,
                                                                        CreateOrderLineDto inputOrderLine, Dictionary <Guid, ProductDto> productDict)
        {
            var product    = productDict[inputOrderLine.ProductId];
            var productSku = product.GetSkuById(inputOrderLine.ProductSkuId);

            if (!inputOrderLine.Quantity.IsBetween(productSku.OrderMinQuantity, productSku.OrderMaxQuantity))
            {
                throw new OrderLineInvalidQuantityException(product.Id, productSku.Id, inputOrderLine.Quantity);
            }

            var totalPrice = productSku.Price * inputOrderLine.Quantity;

            return(new OrderLine(
                       id: _guidGenerator.Create(),
                       productId: product.Id,
                       productSkuId: productSku.Id,
                       productModificationTime: product.LastModificationTime ?? product.CreationTime,
                       productDetailModificationTime: productSku.LastModificationTime ?? productSku.CreationTime,
                       productGroupName: product.ProductGroupName,
                       productGroupDisplayName: product.ProductGroupDisplayName,
                       productUniqueName: product.UniqueName,
                       productDisplayName: product.DisplayName,
                       skuName: productSku.Name,
                       skuDescription: await _productSkuDescriptionProvider.GenerateAsync(product, productSku),
                       mediaResources: product.MediaResources,
                       currency: productSku.Currency,
                       unitPrice: productSku.Price,
                       totalPrice: totalPrice,
                       totalDiscount: 0,
                       actualTotalPrice: totalPrice,
                       quantity: inputOrderLine.Quantity
                       ));
        }
Exemple #2
0
        protected virtual async Task <OrderLine> GenerateOrderLineAsync(CreateOrderDto input,
                                                                        CreateOrderLineDto inputOrderLine, Dictionary <Guid, ProductDto> productDict,
                                                                        Dictionary <Guid, ProductDetailDto> productDetailDict, Currency effectiveCurrency)
        {
            var product    = productDict[inputOrderLine.ProductId];
            var productSku = product.GetSkuById(inputOrderLine.ProductSkuId);

            if (productSku.Currency != effectiveCurrency.Code)
            {
                throw new UnexpectedCurrencyException(effectiveCurrency.Code);
            }

            var productDetailId = productSku.ProductDetailId ?? product.ProductDetailId;
            var productDetail   = productDetailId.HasValue ? productDetailDict[productDetailId.Value] : null;

            if (!inputOrderLine.Quantity.IsBetween(productSku.OrderMinQuantity, productSku.OrderMaxQuantity))
            {
                throw new OrderLineInvalidQuantityException(product.Id, productSku.Id, inputOrderLine.Quantity);
            }

            var unitPrice = await GetUnitPriceAsync(input, inputOrderLine, product, productSku, effectiveCurrency);

            var totalPrice = unitPrice * inputOrderLine.Quantity;

            var orderLine = new OrderLine(
                id: _guidGenerator.Create(),
                productId: product.Id,
                productSkuId: productSku.Id,
                productDetailId: productDetailId,
                productModificationTime: product.LastModificationTime ?? product.CreationTime,
                productDetailModificationTime: productDetail?.LastModificationTime ?? productDetail?.CreationTime,
                productGroupName: product.ProductGroupName,
                productGroupDisplayName: product.ProductGroupDisplayName,
                productUniqueName: product.UniqueName,
                productDisplayName: product.DisplayName,
                skuName: productSku.Name,
                skuDescription: await _productSkuDescriptionProvider.GenerateAsync(product, productSku),
                mediaResources: product.MediaResources,
                currency: productSku.Currency,
                unitPrice: unitPrice.Amount,
                totalPrice: totalPrice.Amount,
                totalDiscount: 0,
                actualTotalPrice: totalPrice.Amount,
                quantity: inputOrderLine.Quantity
                );

            inputOrderLine.MapExtraPropertiesTo(orderLine, MappingPropertyDefinitionChecks.Destination);

            return(orderLine);
        }
        protected virtual async Task UpdateProductDataAsync(int quantity, BasketItem item, ProductDto productDto)
        {
            item.SetIsInvalid(false);

            var productSkuDto = productDto.FindSkuById(item.ProductSkuId);

            if (productSkuDto == null)
            {
                item.SetIsInvalid(true);

                return;
            }

            if (productDto.InventoryStrategy != InventoryStrategy.NoNeed && quantity > productSkuDto.Inventory)
            {
                item.SetIsInvalid(true);
            }

            item.UpdateProductData(quantity, new ProductDataModel
            {
                MediaResources     = productSkuDto.MediaResources ?? productDto.MediaResources,
                ProductUniqueName  = productDto.UniqueName,
                ProductDisplayName = productDto.DisplayName,
                SkuName            = productSkuDto.Name,
                SkuDescription     = await _productSkuDescriptionProvider.GenerateAsync(productDto, productSkuDto),
                Currency           = productSkuDto.Currency,
                UnitPrice          = productSkuDto.DiscountedPrice,
                TotalPrice         = productSkuDto.DiscountedPrice * item.Quantity,
                TotalDiscount      = (productSkuDto.Price - productSkuDto.DiscountedPrice) * item.Quantity,
                Inventory          = productSkuDto.Inventory
            });

            if (!productDto.IsPublished)
            {
                item.SetIsInvalid(true);
            }
        }