public ActionResult WriteDownloadToResponse(HttpResponseBase response, Order order, OrderLine orderLine)
        {
            if (order == null || orderLine == null)
                return new ContentResult { Content = "Error", ContentType = "text/plain" };

            var errors = _rules.SelectMany(rule => rule.GetErrors(order, orderLine));
            if (errors.Any())
                return new ContentResult { Content = "Sorry the file you requested to be downloaded is unavailable. Either the order is not paid or the file has been downloaded a maximum amount of times. Contact the store owner if you believe this to be incorrect.", ContentType = "text/plain" };

            if (!_fileSystem.Exists(orderLine.DownloadFileUrl))
                return new ContentResult { Content = "File no longer exists.", ContentType = "text/plain" };

            EcommerceDownloadResult writeDownloadToResponse;
            try
            {
                writeDownloadToResponse = new EcommerceDownloadResult(_fileSystem, orderLine);
            }
            catch (Exception exception)
            {
                _logService.Insert(new Log
                    {
                        Error = new Error(exception),
                        Message = "Error downloading file"
                    });
                return new ContentResult { Content = "An error occoured, please contact the store owner.", ContentType = "text/plain" };
            }

            orderLine.NumberOfDownloads++;
            _session.Transact(session => session.Update(orderLine));
            return writeDownloadToResponse;
        }
Exemplo n.º 2
0
 public TaxRate GetRateForOrderLine(OrderLine orderLine)
 {
     TaxRate taxRate = null;
     ProductVariant pv = _productVariantService.GetProductVariantBySKU(orderLine.SKU);
     if (pv != null && pv.TaxRate != null)
         taxRate = pv.TaxRate;
     return taxRate ?? GetDefaultRate();
 }
        public void ACallToWriteDownloadToResponseShouldHappen()
        {
            var order = new Order();
            var orderLine = new OrderLine();

            _downloadOrderedFileController.Download(order, orderLine);

            A.CallTo(() => _downloadProductService.WriteDownloadToResponse(_downloadOrderedFileController.Response, order, orderLine)).MustHaveHappened();
        }
Exemplo n.º 4
0
        public void SetTaxDetails_SetOrderLinesTaxes_ShouldCallGetDefaultRate()
        {
            var orderLine = new OrderLine() {UnitPrice = 1, Price = 2, Quantity = 2};
            var order = new Order() { Total = 10, ShippingTotal = 1, OrderLines = new List<OrderLine>(){orderLine}};

            _setTaxes.SetOrderLinesTaxes(ref order);

            A.CallTo(() => _taxRateManager.GetRateForOrderLine(orderLine)).MustHaveHappened();
        }
        public void ReturnsTheResultOfServiceCall()
        {
            var order = new Order();
            var orderLine = new OrderLine();
            var stubFileStreamResult = new StubFileStreamResult();
            A.CallTo(
                () =>
                _downloadProductService.WriteDownloadToResponse(_downloadOrderedFileController.Response, order,
                                                                orderLine)).Returns(stubFileStreamResult);

            var actionResult = _downloadOrderedFileController.Download(order, orderLine);

            actionResult.Should().Be(stubFileStreamResult);
        }
Exemplo n.º 6
0
            TaxRateManager_GetDefaultRateForOrderLine_ShouldReturnDefaultTaxRateIfProductVariantTaxRateNotSpecified()
        {
            var taxRate = new TaxRate {Percentage = 10, IsDefault = true, Name = "GLOBAL", Code = "GL"};
            A.CallTo(() => _getDefaultTaxRate.Get()).Returns(taxRate);

            var orderLine = new OrderLine {ProductVariant = new ProductVariant(), SKU = "123"};

            A.CallTo(() => _productVariantService.GetProductVariantBySKU(orderLine.SKU)).Returns(null);

            TaxRate result = _taxRateManager.GetRateForOrderLine(orderLine);

            result.Should().NotBeNull();
            result.Should().Be(taxRate);
        }
Exemplo n.º 7
0
        public OrderLine GetOrderLine(CartItem item)
        {
            var options = string.Join(", ", item.Item.OptionValues.Select(value => value.FormattedValue));

            var orderLine = new OrderLine
            {
                UnitPrice = item.UnitPrice,
                UnitPricePreTax = item.UnitPricePreTax,
                Weight = item.Weight,
                TaxRate = item.TaxRatePercentage,
                Tax = item.Tax,
                Quantity = item.Quantity,
                ProductVariant = item.Item,
                PricePreTax = item.PricePreTax,
                Price = item.Price,
                SKU = item.Item.SKU,
                Name = item.Item.FullName,
                Options = options,
                Discount = item.DiscountAmount,
                RequiresShipping = item.RequiresShipping,
                Data = item.Data
            };
            if (item.IsDownloadable)
            {
                orderLine.IsDownloadable = true;
                orderLine.AllowedNumberOfDownloads = item.AllowedNumberOfDownloads;
                orderLine.DownloadExpiresOn =
                    (item.AllowedNumberOfDaysForDownload.HasValue && item.AllowedNumberOfDaysForDownload > 0)
                        ? CurrentRequestData.Now.AddDays(
                            item.AllowedNumberOfDaysForDownload
                                .GetValueOrDefault())
                        : (DateTime?)null;
                orderLine.NumberOfDownloads = 0;
                var fileByUrl = _fileService.GetFileByUrl(item.DownloadFileUrl);
                if (fileByUrl != null)
                {
                    orderLine.DownloadFileUrl = fileByUrl.FileUrl;
                    orderLine.DownloadFileContentType = fileByUrl.ContentType;
                    orderLine.DownloadFileName = fileByUrl.FileName;
                }
                else
                {
                    orderLine.DownloadFileUrl = item.DownloadFileUrl;
                }
            }
            return orderLine;
        }
Exemplo n.º 8
0
        public void SetTaxDetails_SetOrderLinesTaxes_TakesIntoAccountRounding()
        {
            Kernel.SetTaxSettings(true, true);
            var orderLine = new OrderLine() { UnitPrice = 6.51m, Price = 13.02m, Quantity = 2 };
            var order = new Order() { Total = 13.02m,  OrderLines = new List<OrderLine>() { orderLine } };

            var taxRate = new TaxRate() { Percentage = 20 };

            A.CallTo(() => _taxRateManager.GetRateForOrderLine(orderLine)).Returns(taxRate);

            _setTaxes.SetOrderLinesTaxes(ref order);

            order.Tax.Should().Be(2.18m);//decimal.Parse("0,22"));
            order.Total.Should().Be(13.02m);//.Be(decimal.Parse("2,22"));

            order.OrderLines.First().UnitPrice.Should().Be(6.51m); //.Be(decimal.Parse("1,1"));
            order.OrderLines.First().UnitPricePreTax.Should().Be(5.42m);
            order.OrderLines.First().Price.Should().Be(13.02m); //.Be(decimal.Parse("2,2"));
            order.OrderLines.First().PricePreTax.Should().Be(10.84m);
            order.OrderLines.First().Tax.Should().Be(2.18m);//.Be(decimal.Parse("0,22"));
            order.OrderLines.First().TaxRate.Should().Be(20);
        }
Exemplo n.º 9
0
        public void SetTaxDetails_SetOrderLinesTaxes_ShouldSetProperties()
        {
            Kernel.Rebind<TaxSettings>()
                .ToConstant(new TaxSettings {TaxesEnabled = true, LoadedPricesIncludeTax = true});
            var orderLine = new OrderLine() { UnitPrice = 6, Price = 12, Quantity = 2 };
            var order = new Order() { Total = 12, ShippingTotal = 0m, OrderLines = new List<OrderLine>() { orderLine } };

            var taxRate = new TaxRate() {Percentage = 20};

            A.CallTo(() => _taxRateManager.GetRateForOrderLine(orderLine)).Returns(taxRate);

            _setTaxes.SetOrderLinesTaxes(ref order);

            order.Tax.Should().Be(2);//decimal.Parse("0,22"));
            order.Total.Should().Be(12);//.Be(decimal.Parse("2,22"));

            order.OrderLines.First().UnitPrice.Should().Be(6); //.Be(decimal.Parse("1,1"));
            order.OrderLines.First().UnitPricePreTax.Should().Be(5);
            order.OrderLines.First().Price.Should().Be(12); //.Be(decimal.Parse("2,2"));
            order.OrderLines.First().PricePreTax.Should().Be(10);
            order.OrderLines.First().Tax.Should().Be(2);//.Be(decimal.Parse("0,22"));
            order.OrderLines.First().TaxRate.Should().Be(20);
        }
 public IEnumerable<string> GetErrors(Order order, OrderLine orderLine)
 {
     if (orderLine.AllowedNumberOfDownloads.HasValue && orderLine.AllowedNumberOfDownloads != 0 && orderLine.NumberOfDownloads >= orderLine.AllowedNumberOfDownloads)
         yield return "Download limit reached.";
 }
 public IEnumerable<string> GetErrors(Order order, OrderLine orderLine)
 {
     if (!orderLine.IsDownloadable)
         yield return "Order line is not downloadable.";
 }
Exemplo n.º 12
0
        public void TaxRateManager_GetDefaultRateForOrderLine_ShouldCallGetProductVariantBySKU()
        {
            var pv = new ProductVariant();
            var orderLine = new OrderLine {ProductVariant = pv, SKU = "123"};

            _taxRateManager.GetRateForOrderLine(orderLine);

            A.CallTo(() => _productVariantService.GetProductVariantBySKU(orderLine.SKU)).MustHaveHappened();
        }
Exemplo n.º 13
0
 public void Save(OrderLine item)
 {
     _session.Transact(session => session.SaveOrUpdate(item));
 }
Exemplo n.º 14
0
 private void SetRulesStatus(Order order, OrderLine orderLine, bool passing)
 {
     var downloadOrderedFileValidationRule = A.Fake<IDownloadOrderedFileValidationRule>();
     var errors = passing ? new List<string>() : new List<string> { "an error" };
     A.CallTo(() => downloadOrderedFileValidationRule.GetErrors(order, orderLine)).Returns(errors);
     _rules.Add(downloadOrderedFileValidationRule);
 }
Exemplo n.º 15
0
        public string ProcessOrders(NopCommerceDataReader dataReader, NopImportContext nopImportContext)
        {
            HashSet<OrderData> orders = dataReader.GetOrderData();
            HashSet<OrderLineData> orderLines = dataReader.GetOrderLineData();

            using (EventContext.Instance.Disable<GenerateGiftCards>())
            {
                _session.Transact(session =>
                {
                    foreach (OrderData data in orders)
                    {
                        Guid guid = data.Guid;
                        if (session.QueryOver<Order>().Where(o => o.Guid == guid).Any())
                            continue;

                        var billingAddress = nopImportContext.FindNew<Address>(data.BillingAddressId);
                        var shippingAddress =
                            nopImportContext.FindNew<Address>(data.ShippingAddressId.GetValueOrDefault());
                        var order = new Order
                        {
                            BillingAddress = billingAddress.ToAddressData(),
                            ShippingAddress = shippingAddress != null ? shippingAddress.ToAddressData() : null,
                            CustomerIP = data.CustomerIp,
                            DiscountAmount = data.OrderDiscount,
                            Id = data.Id,
                            OrderEmail = data.Email,
                            PaidDate = data.PaidDate,
                            PaymentStatus = GetPaymentStatus(data.PaymentStatus),
                            ShippingStatus = GetShippingStatus(data.ShippingStatus),
                            ShippingMethodName = data.ShippingMethodName,
                            ShippingSubtotal = data.OrderShippingExclTax,
                            ShippingTax = data.OrderShippingInclTax - data.OrderShippingExclTax,
                            ShippingTotal = data.OrderShippingInclTax,
                            Subtotal = data.OrderSubtotalInclTax,
                            Tax = data.OrderTax,
                            Total = data.OrderTotal,
                            TotalPaid = data.OrderTotal,
                            User = nopImportContext.FindNew<User>(data.CustomerId),
                            SalesChannel = EcommerceApp.NopCommerceSalesChannel,
                            PaymentMethod = data.PaymentMethod,
                            OrderDate = data.OrderDate
                        };
                        order.SetGuid(data.Guid);
                        session.Save(order);

                        if (order.OrderNotes == null)
                            order.OrderNotes = new List<OrderNote>();
                        data.Notes.Add(new OrderNoteData
                        {
                            Note = "Previous order id: " + data.Id,
                            ShowToCustomer = false
                        });
                        foreach (OrderNoteData note in data.Notes)
                        {
                            var orderNote = new OrderNote
                            {
                                ShowToClient = note.ShowToCustomer,
                                Note = note.Note,
                                Order = order
                            };
                            if (note.Date.HasValue)
                                orderNote.CreatedOn = note.Date.Value;
                            order.OrderNotes.Add(orderNote);
                            session.Save(orderNote);
                        }
                        int orderId = data.Id;
                        HashSet<OrderLineData> lineDatas = orderLines.FindAll(x => x.OrderId == orderId);
                        foreach (OrderLineData lineData in lineDatas)
                        {
                            var orderLine = new OrderLine
                            {
                                Discount = lineData.DiscountAmountInclTax,
                                Id = lineData.Id,
                                Order = order,
                                Quantity = lineData.Quantity,
                                Name = lineData.ProductName,
                                Price = lineData.PriceInclTax,
                                UnitPrice = lineData.UnitPriceInclTax,
                                UnitPricePreTax = lineData.DiscountAmountExclTax,
                                PricePreTax = lineData.PriceExclTax,
                                Tax = lineData.PriceInclTax - lineData.PriceExclTax,
                                Weight = lineData.ItemWeight.GetValueOrDefault(),
                                SKU = lineData.SKU,
                                RequiresShipping = lineData.RequiresShipping
                            };
                            order.OrderLines.Add(orderLine);
                            session.Save(orderLine);
                        }
                        nopImportContext.AddEntry(data.Id, order);
                    }
                });
            }

            return string.Format("{0} orders processed", orders.Count);
        }
 public IEnumerable<string> GetErrors(Order order, OrderLine orderLine)
 {
     if (!order.OrderLines.Contains(orderLine))
         yield return "Order line does not belong to order.";
 }
Exemplo n.º 17
0
        public void TaxRateManager_GetDefaultRateForOrderLine_ShouldReturnTaxRate()
        {
            var taxRate = new TaxRate {Percentage = 10, IsDefault = true, Name = "GLOBAL", Code = "GL"};
            var taxRate2 = new TaxRate {Percentage = 50, IsDefault = false, Name = "UK", Code = "UK"};

            _taxRateManager.Add(taxRate);
            _taxRateManager.Add(taxRate2);

            var pv = new ProductVariant {TaxRate = taxRate2};
            var orderLine = new OrderLine {ProductVariant = pv, SKU = "123"};

            A.CallTo(() => _productVariantService.GetProductVariantBySKU(orderLine.SKU)).Returns(pv);

            TaxRate result = _taxRateManager.GetRateForOrderLine(orderLine);

            result.Should().NotBeNull();
            result.Should().Be(taxRate2);
        }
 public IEnumerable<string> GetErrors(Order order, OrderLine orderLine)
 {
     if (orderLine.DownloadExpiresOn.HasValue && orderLine.DownloadExpiresOn <= CurrentRequestData.Now)
         yield return "Download link has expired.";
 }
Exemplo n.º 19
0
 public EcommerceDownloadResult(IFileSystem fileSystem, OrderLine orderLine)
 {
     _fileSystem = fileSystem;
     _orderLine = orderLine;
 }
 public IEnumerable<string> GetErrors(Order order, OrderLine orderLine)
 {
     if (!order.PaymentStatus.Equals(PaymentStatus.Paid))
         yield return "This order must be paid before being downloaded.";
 }
Exemplo n.º 21
0
 private void GetOrderLines(AmazonOrder amazonOrder, ref Ecommerce.Entities.Orders.Order order)
 {
     foreach (AmazonOrderItem amazonOrderItem in amazonOrder.Items)
     {
         var orderLine = new OrderLine
         {
             Order = order,
             UnitPrice =
                 amazonOrderItem.QuantityOrdered > 0
                     ? (amazonOrderItem.ItemPriceAmount / amazonOrderItem.QuantityOrdered)
                     : 0,
             Price = amazonOrderItem.ItemPriceAmount,
             Name = amazonOrderItem.Title,
             Tax = amazonOrderItem.ItemTaxAmount,
             Discount = amazonOrderItem.PromotionDiscountAmount,
             Quantity = Decimal.ToInt32(amazonOrderItem.QuantityOrdered),
             SKU = amazonOrderItem.SellerSKU
         };
         order.OrderLines.Add(orderLine);
         _session.Transact(session => session.Save(orderLine));
     }
 }