Ejemplo n.º 1
0
        public virtual async Task <Order> GenerateAsync(CreateOrderDto input, Dictionary <Guid, ProductDto> productDict, Dictionary <string, object> orderExtraProperties)
        {
            var orderLines = new List <OrderLine>();

            foreach (var orderLine in input.OrderLines)
            {
                orderLines.Add(await GenerateNewOrderLineAsync(orderLine, productDict));
            }

            var productTotalPrice = orderLines.Select(x => x.TotalPrice).Sum();

            var order = new Order(
                id: _guidGenerator.Create(),
                tenantId: _currentTenant.Id,
                storeId: input.StoreId,
                customerUserId: _currentUser.GetId(),
                currency: await GetStoreCurrencyAsync(input.StoreId),
                productTotalPrice: productTotalPrice,
                totalDiscount: orderLines.Select(x => x.TotalDiscount).Sum(),
                totalPrice: productTotalPrice,
                refundedAmount: 0,
                customerRemark: input.CustomerRemark);

            foreach (var orderExtraProperty in orderExtraProperties)
            {
                order.SetProperty(orderExtraProperty.Key, orderExtraProperty.Value);
            }

            order.SetOrderLines(orderLines);

            order.SetOrderNumber(await _orderNumberGenerator.CreateAsync(order));

            return(order);
        }
Ejemplo n.º 2
0
        public virtual async Task <Order> GenerateAsync(Guid customerUserId, CreateOrderDto input,
                                                        Dictionary <Guid, ProductDto> productDict, Dictionary <Guid, ProductDetailDto> productDetailDict)
        {
            var effectiveCurrency = await GetEffectiveCurrencyAsync();

            var orderLines = new List <OrderLine>();

            foreach (var inputOrderLine in input.OrderLines)
            {
                orderLines.Add(await GenerateOrderLineAsync(
                                   input, inputOrderLine, productDict, productDetailDict, effectiveCurrency));
            }

            var productTotalPrice = orderLines.Select(x => x.TotalPrice).Sum();

            var paymentExpireIn = orderLines.Select(x => productDict[x.ProductId].GetSkuPaymentExpireIn(x.ProductSkuId))
                                  .Min();

            var totalPrice    = productTotalPrice;
            var totalDiscount = orderLines.Select(x => x.TotalDiscount).Sum();

            var order = new Order(
                id: _guidGenerator.Create(),
                tenantId: _currentTenant.Id,
                storeId: input.StoreId,
                customerUserId: customerUserId,
                currency: effectiveCurrency.Code,
                productTotalPrice: productTotalPrice,
                totalDiscount: totalDiscount,
                totalPrice: totalPrice,
                actualTotalPrice: totalPrice - totalDiscount,
                customerRemark: input.CustomerRemark,
                paymentExpiration: paymentExpireIn.HasValue ? _clock.Now.Add(paymentExpireIn.Value) : null
                );

            input.MapExtraPropertiesTo(order, MappingPropertyDefinitionChecks.Destination);

            await AddOrderExtraFeesAsync(order, customerUserId, input, productDict, effectiveCurrency);

            order.SetOrderLines(orderLines);

            order.SetOrderNumber(await _orderNumberGenerator.CreateAsync(order));

            return(order);
        }
Ejemplo n.º 3
0
        public virtual async Task <Order> GenerateAsync(Guid customerUserId, CreateOrderDto input,
                                                        Dictionary <Guid, ProductDto> productDict)
        {
            var orderLines = new List <OrderLine>();

            foreach (var inputOrderLine in input.OrderLines)
            {
                orderLines.Add(await GenerateOrderLineAsync(input, inputOrderLine, productDict));
            }

            var storeCurrency = await GetStoreCurrencyAsync(input.StoreId);

            if (orderLines.Any(x => x.Currency != storeCurrency))
            {
                throw new CurrencyIsLimitException(storeCurrency);
            }

            var productTotalPrice = orderLines.Select(x => x.TotalPrice).Sum();

            var totalPrice    = productTotalPrice;
            var totalDiscount = orderLines.Select(x => x.TotalDiscount).Sum();

            var order = new Order(
                id: _guidGenerator.Create(),
                tenantId: _currentTenant.Id,
                storeId: input.StoreId,
                customerUserId: customerUserId,
                currency: storeCurrency,
                productTotalPrice: productTotalPrice,
                totalDiscount: totalDiscount,
                totalPrice: totalPrice,
                actualTotalPrice: totalPrice - totalDiscount,
                customerRemark: input.CustomerRemark);

            input.MapExtraPropertiesTo(order, MappingPropertyDefinitionChecks.Destination);

            await AddOrderExtraFeesAsync(order, customerUserId, input, productDict);

            order.SetOrderLines(orderLines);

            order.SetOrderNumber(await _orderNumberGenerator.CreateAsync(order));

            return(order);
        }