Exemple #1
0
 public void AddProductToOrder()
 {
     Order order = new Order();
     Product product = new Product {Title = "Test Product",ProductId=1,Price=50};
     var orderOperationStatus=order.Add(product, 2, "F", 50);
     Assert.IsTrue(orderOperationStatus.Status);
     Assert.IsTrue(order.NumberOfItems == 2);
     Assert.IsTrue(order.ContainsProduct(product));
     Assert.IsTrue(order.PaymentTotal==100);
 }
Exemple #2
0
 public void ShouldRecogniseWhenCannotUseEarlyBirdPricing()
 {
     Product _sut = new Product
     {
         Price = 10,
         EarlyBirdPrice = 5,
         EarlyBirdPriceCutOffDate = DateTime.Now.AddDays(-5)
     };
     Assert.AreEqual(false, _sut.CanUseEarlyBirdPrice());
 }
Exemple #3
0
 public void ShouldRecogniseProductStartAndFinishDateWithinSingleRange()
 {
     Product _sut = new Product
     {
         StartDate = new DateTime(2014, 08, 15),
         FinishDate = new DateTime(2014, 08, 18),
         StartDateRange1 = new DateTime(2014, 08, 10),
         FinishDateRange1 = new DateTime(2014, 08, 20)
     };
     Assert.AreEqual(true, _sut.HasRestrictedDateRange());
     Assert.AreEqual(true, _sut.HasStartAndFinishDatesWithinRestrictedRange());
 }
        public void Initialise()
        {
            var product = new Product
                {
                    ProductId = 29397,
                    ProductType = "P",
                    OrderIndex = 1,
                    Price = 3,
                    Title = "Test Product"
                };
            var product2 = new Product
                {
                    ProductId = 29398,
                    ProductType = "P",
                    OrderIndex = 1,
                    OptionId = 30001,
                    Price = 3,
                    Title = "Test Product with Option"
                };

            var productRepository = new Mock<IProductRepository>();
            productRepository.Setup(x => x.GetProduct(It.Is<int>(i => i == 29397),It.Is<int>(i => i==0)))
                             .Returns(new ProductOperationStatus {Product = product, Status = true});
            productRepository.Setup(x => x.GetProduct(It.Is<int>(i => i == 29398),It.Is<int>(i=>i==30001)))
                             .Returns(new ProductOperationStatus {Product = product2, Status = true});

            var voucherRepository = new Mock<IVoucherRepository>();

            var contactRepository = new Mock<IContactRepository>();
            Contact contact = new Contact {UserId = "1234", UserName = "******"};
            contactRepository.Setup((x => x.GetContact()))
                             .Returns(new ContactOperationStatus { Status = true, Contact = contact} ); //need to create UpdatedContact details new UpdatedContact
            var orderRepository = new Mock<IOrderRepository>();
            orderRepository.Setup(x => x.Add(It.IsAny<Product>(), It.IsAny<int>(), It.IsAny<string>(),It.IsAny<decimal>(),It.IsAny<Contact>()))
                           .Returns(new OrderOperationStatus {Status = true});
            orderRepository.Setup(x => x.Update(It.IsAny<Product>(),It.IsAny<Product>(), It.IsAny<int>(),It.IsAny<string>(), It.IsAny<decimal>(),It.IsAny<Contact>()))
                           .Returns(new OrderOperationStatus {Status = true});
            orderRepository.Setup(x => x.Remove(It.IsAny<Product>(), It.IsAny<Contact>()))
                           .Returns(new OrderOperationStatus {Status = true});
            orderRepository.Setup(x => x.UpdateSpecialRequirements(It.IsAny<string>(),It.IsAny<int>(),It.IsAny<Contact>()))
                           .Returns(new OrderOperationStatus { Status = true });
            var configService = new Mock<IConfigurationService>();
            configService.Setup(x => x.GetConfiguration()).Returns(new CustomerPortalSection());
            _ecommerceService = new EcommerceService(orderRepository.Object, productRepository.Object, voucherRepository.Object,
                                                     contactRepository.Object, configService.Object);
        }
        public Product CreateBespokePrice(Product product, int quantity)
        {
            if (product.StartDate == null || product.FinishDate == null)
            {

                throw new InvalidDataException("Cannot create pricing: start and finish date must not be null");
            }
            TimeSpan spanOfDays = (DateTime)product.FinishDate - (DateTime)product.StartDate;
            double numberOfNights = spanOfDays.TotalDays;

            int numberOfCostedNights = Convert.ToInt32(numberOfNights - (Math.Floor((numberOfNights/4))));
            product.Price = product.Price*numberOfCostedNights;
            if (product.CanUseEarlyBirdPrice())
                product.EarlyBirdPrice = (decimal)
                                         product.EarlyBirdPrice*numberOfCostedNights;

            return product;
        }
 public void AddThenRemoveFromOrderRepository()
 {
     var product = new Product
         {
             ProductId = 24249,
             ProductType = "P",
             OrderIndex = 1,
             Price = 3,
             Title = "Test Remove Product"
         };
     OrderOperationStatus operationStatus = _orderRepository.Add(product, 1, "F", product.Price,
                                                                 _existingUserCredentials);
     Assert.IsTrue(operationStatus.Status);
     Assert.IsTrue(operationStatus.Order.ContainsProduct(product));
     operationStatus = _orderRepository.Remove(product, _existingUserCredentials);
     Assert.IsTrue(operationStatus.Status);
     Assert.IsFalse(operationStatus.Order.ContainsProduct(product));
 }
 public void AddProductWithPartialPayment()
 {
     var product = new Product
         {
             ProductId = 24314,
             OptionId = 24904,
             DepositAmount = 50,
             ProductType = "P",
             OrderIndex = 1,
             Price = 300,
             Title = "Test Partial Payment Product"
         };
     OrderOperationStatus operationStatus = _orderRepository.Add(product, 1, "D", 1, _existingUserCredentials);
     Assert.IsTrue(operationStatus.Status);
     Assert.IsTrue(operationStatus.Order.ContainsProduct(product));
     Assert.IsTrue(operationStatus.Order.GetOrderLine(product).Quantity == 1);
     Assert.IsTrue(operationStatus.Order.GetOrderLine(product).PaymentAmount.Equals(50));
     Assert.IsTrue(operationStatus.Order.GetOrderLine(product).ProductPrice.Equals(3));
 }
 public void AddThenUpdateOrderRepository()
 {
     var product = new Product
         {
             ProductId = 24249,
             ProductType = "P",
             OrderIndex = 1,
             Price = 3,
             Title = "Test Update Product"
         };
     var newProduct = new Product
         {
             ProductId = 24249,
             ProductType = "P",
             OrderIndex = 1,
             Price = 3,
             Title = "Test Update Product"
         };
     OrderOperationStatus operationStatus = _orderRepository.Add(product, 1, "F", product.Price,
                                                                 _existingUserCredentials);
     Assert.IsTrue(operationStatus.Status);
     Assert.IsTrue(operationStatus.Order.ContainsProduct(product));
     operationStatus = _orderRepository.Update(product, newProduct, 2, "F", product.Price,
                                               _existingUserCredentials);
     Assert.IsTrue(operationStatus.Status);
     Assert.IsTrue(operationStatus.Order.ContainsProduct(product));
     Assert.IsTrue(operationStatus.Order.GetOrderLine(product).Quantity == 2);
 }
Exemple #9
0
        public void ShouldUpdateQuantityAndEventDatesWhenAddingExistingEvent()
        {
            Order order = new Order();

            Product event1 = new Product { Title = "Test Event 1", ProductId = 1, StartDate = new DateTime(2014,08,1),FinishDate = new DateTime(2014,08,5), Price = 50 };
            order.Add(event1, 2, "F", 50);
            Assert.IsTrue(order.NumberOfItems == 2);
            Assert.IsTrue(order.ContainsProduct(event1));
            Assert.IsTrue(order.PaymentTotal == 100);
            Product event2 = new Product { Title = "Test Event 2", ProductId = 1, StartDate = new DateTime(2014,08,1),FinishDate = new DateTime(2014,08,4), Price = 50 };
            order.Add(event2, 3, "F", 50);
            Assert.IsTrue(order.NumberOfItems == 3);
            Assert.IsTrue(order.PaymentTotal == 150);
            Assert.IsTrue(order.ContainsProduct(event1));
            var eventInOrder = order.GetOrderLine(event1);
            Assert.IsTrue(eventInOrder.StartDate == new DateTime(2014, 08, 1));
            Assert.IsTrue(eventInOrder.FinishDate == new DateTime(2014, 08, 4));
        }
Exemple #10
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="oldProduct"></param>
        /// <param name="newProduct"></param>
        /// <param name="quantity"></param>
        /// <param name="paymentType"></param>
        /// <param name="paymentAmount"></param>
        /// <returns>if product to be updated doesn't exist in order, </returns>
        public OrderOperationStatus Update(Product oldProduct, Product newProduct, int quantity, string paymentType,
                                decimal paymentAmount)
        {
            var orderOperationStatus = new OrderOperationStatus();
            // if the quantity is zero, do a remove instead
            if (quantity == 0)
                return Remove(oldProduct);

            if (newProduct.ChargedPrice == null)
            {
                orderOperationStatus.Message = "The item cannot be added because no price has been specified";
                orderOperationStatus.MessageCode = "CPX.NoPriceSpecified";
                orderOperationStatus.Status = false;
                return orderOperationStatus;
            }

            if (!ContainsProduct(oldProduct))
            {
                orderOperationStatus.Message = "The item cannot be updated because it does not exist in the order";
                orderOperationStatus.MessageCode = "CPX.ItemNotInOrder";
                orderOperationStatus.Status = false;
                return orderOperationStatus;
            }

            //check that the product to be udated to doesn't exist
            if (newProduct.OptionId > 0 && oldProduct.OptionId != newProduct.OptionId &&
                                    ContainsProduct(newProduct))
            {
                orderOperationStatus.Message = "There is already an item of this type in the order";
                orderOperationStatus.MessageCode = "CPX.ItemAlreadyInOrder";
                orderOperationStatus.Status = false;
                return orderOperationStatus;
            }

            if (paymentAmount > newProduct.ChargedPrice)
            {
                orderOperationStatus.Message = "The item cannot be updated because it would mean an over-payment";
                orderOperationStatus.MessageCode = "CPX.OverPayment";
                orderOperationStatus.Status = false;
                return orderOperationStatus;

            }

            //get the order line to update
            OrderLine orderLine = GetOrderLine(oldProduct);
            //merge in changes from the update
            orderLine.ProductPrice = (decimal)newProduct.ChargedPrice;
            orderLine.ProductOptionTitle = newProduct.OptionTitle;
            orderLine.ProductOptionId = newProduct.OptionId;
            orderLine.ProductOptionExternalId = newProduct.OptionExternalId;
            orderLine.StartDate = newProduct.StartDate;
            orderLine.FinishDate = newProduct.FinishDate;

            orderLine.Quantity = quantity;
            orderLine.PaymentType = paymentType;
            orderLine.PaymentAmount = paymentAmount;

            orderOperationStatus.Status = true;
            orderOperationStatus.Order = this;
            orderOperationStatus.OrderLine = orderLine;
            return orderOperationStatus;
        }
Exemple #11
0
 public int GetQuantityOfProduct(Product product)
 {
     if (product.OptionId == 0)
     {
         return CurrentOrderLines.Where(x => x.ProductId == product.ProductId).Sum(x => x.Quantity);
     }
     else
     {
         return CurrentOrderLines.Where(x => x.ProductId == product.ProductId && x.ProductOptionId == product.OptionId).Sum(x => x.Quantity);
     }
 }
Exemple #12
0
 public bool ContainsProduct(Product product)
 {
     if (product.OptionId==0)
     {
         return CurrentOrderLines.Any(x => x.ProductId == product.ProductId);
     }
     return CurrentOrderLines.Any(x => x.ProductId == product.ProductId && x.ProductOptionId == product.OptionId);
 }
        public void Initialise()
        {
            _courseBespoke3Night = new Product
            {
                Title = "Test Bespoke Course 3 Day",
                Location = "Juniper Hall",
                StartDate = new DateTime(2013, 08, 05),
                FinishDate = new DateTime(2013, 08, 08),
                LocationCode = "JH",
                DepositAmount = 50,
                ProductId = 2000,
                OptionId = 3001,
                Price = (decimal)16.50,
                ProductType = "C",
                OptionTitle = "Sole occupancy",
                OrderIndex = 3,
                Category = "F/10",
                VoucherCategory = ""
            };

            _courseBespoke4Night = new Product
            {
                Title = "Test Bespoke Course 4 Day",
                Location = "Juniper Hall",
                StartDate = new DateTime(2013, 08, 05),
                FinishDate = new DateTime(2013, 08, 09),
                LocationCode = "JH",
                DepositAmount = 50,
                ProductId = 2000,
                OptionId = 3001,
                Price = (decimal)16.50,
                ProductType = "C",
                OptionTitle = "Sole occupancy",
                OrderIndex = 3,
                Category = "F/10",
                VoucherCategory = ""
            };

            _courseBespoke7Night = new Product
            {
                Title = "Test Bespoke Course 4 Day",
                Location = "Juniper Hall",
                StartDate = new DateTime(2013, 08, 05),
                FinishDate = new DateTime(2013, 08, 12),
                LocationCode = "JH",
                DepositAmount = 50,
                ProductId = 2000,
                OptionId = 3001,
                Price = (decimal)16.50,
                ProductType = "C",
                OptionTitle = "Sole occupancy",
                OrderIndex = 3,
                Category = "F/10",
                VoucherCategory = ""
            };

            _courseBespoke8Night = new Product
            {
                Title = "Test Bespoke Course 4 Day",
                Location = "Juniper Hall",
                StartDate = new DateTime(2013, 08, 05),
                FinishDate = new DateTime(2013, 08, 13),
                LocationCode = "JH",
                DepositAmount = 50,
                ProductId = 2000,
                OptionId = 3001,
                Price = (decimal)16.50,
                ProductType = "C",
                OptionTitle = "Sole occupancy",
                OrderIndex = 3,
                Category = "F/10",
                VoucherCategory = ""
            };
        }
Exemple #14
0
 private Product GetBespokePricing(Product product, int quantity)
 {
     IBespokePricingHandler pricingHandler =
         _bespokePricingHandlerFactory.GetBespokePricingHandler(product.BespokePricingHandler);
     return pricingHandler.CreateBespokePrice(product, quantity);
 }
Exemple #15
0
 private decimal GetPaymentAmount(Product product, string paymentType)
 {
     decimal paymentAmount = 0;
     if (paymentType == "D") { paymentAmount = product.DepositAmount; }
     if (paymentType == "F"||paymentType=="DON") { paymentAmount = (decimal) product.ChargedPrice; }
     return paymentAmount;
 }
Exemple #16
0
        private OrderOperationStatus AddProductToOrder(Product product, int quantity, string paymentType,
            decimal paymentAmount)
        {
            var orderOperationStatus = new OrderOperationStatus();
            //get the contact
            try
            {
                var contactOperationStatus = _contactService.GetContact();
                if (!contactOperationStatus.Status)
                    return (OrderOperationStatus) new OrderOperationStatus().InjectFrom(contactOperationStatus);

                var contact = contactOperationStatus.Contact;

                //get the current order
                orderOperationStatus = _orderCoordinator.GetOrder(contactOperationStatus.Contact, product.OrderIndex);
                if (orderOperationStatus.Status)
                {
                    var order = orderOperationStatus.Order;
                    //check the quantity
                    if (product.MaximumQuantity != 0 &&
                        quantity + order.GetQuantityOfProduct(product) > product.MaximumQuantity)
                        return new OrderOperationStatus
                        {
                            Message = "No more items of this type can be added!",
                            Status = false
                        };
                    //add the order line
                    orderOperationStatus = order.Add(product, quantity, paymentType, (decimal) paymentAmount);
                    var orderLine = orderOperationStatus.OrderLine;
                    if (orderOperationStatus.Status)
                    {
                        order = _orderCoordinator.UpdateOrderWithShippingAndDiscounts(order, contact);
                        orderOperationStatus = _orderCoordinator.SaveOrder(order, true);
                        if (orderOperationStatus.Status)
                        {
                            orderOperationStatus.OrderLine = orderLine;
                            orderOperationStatus.Message = "Added " + product.Title + " successfully!";
                        }
                    }
                }

            }

            catch (Exception e)
            {
                orderOperationStatus.LogFailedOperation(e, "An error has occurred adding the product to the order");
            }
            return orderOperationStatus;
        }
Exemple #17
0
 public void ShouldNotUpdateWhereNotExistingProductInOrder()
 {
     Order order = new Order();
     Product product = new Product { Title = "Test Product", ProductId = 1, OptionId = 1, OptionTitle = "Option1",Price=50 };
     var operationStatus = order.Update(product, product, 6, "F", 50);
     Assert.IsTrue(operationStatus.Status == false);
     Assert.IsTrue(operationStatus.MessageCode == "CPX.ItemNotInOrder");
 }
Exemple #18
0
 public void UpdateProductInOrderToDifferentOption()
 {
     Order order = new Order();
     Product product = new Product { Title = "Test Product", ProductId = 1,OptionId = 1,OptionTitle = "Option1", Price=50};
     order.Add(product, 2, "F", 50);
     Assert.IsTrue(order.NumberOfItems == 2);
     Assert.IsTrue(order.ContainsProduct(product));
     Assert.IsTrue(order.PaymentTotal == 100);
     Product updateProduct = new Product { Title = "Test Product", ProductId = 1, OptionId = 2, OptionTitle = "Option2",Price=50 };
     order.Update(product, updateProduct, 6, "F", 50);
     Assert.IsTrue(order.NumberOfItems == 6);
     Assert.IsTrue(order.ContainsProduct(updateProduct));
     Assert.IsFalse(order.ContainsProduct(product));
     Assert.IsTrue(order.PaymentTotal == 300);
 }
Exemple #19
0
        public ProductOperationStatus GetProduct(int productId, int optionId)
        {
            //TODO: give option of using Examine to get nodes
            var operationStatus = new ProductOperationStatus();
            try
            {
                var product = new Product();
                //get the info from Umbraco
                Node productNode = new Node(productId);
                Node optionNode = (optionId == 0) ? new Node(productId) : new Node(optionId);

                product.ProductId = productId;

                IProductTypeSetting productTypeSetting =
                    _config.GetConfiguration().ProductTypeSettings[productNode.NodeTypeAlias];

                product.OrderIndex = (productTypeSetting != null)
                                         ? productTypeSetting.OrderIndex
                                         : 1;

                product.Title = (productTypeSetting != null)
                                    ? UmbracoHelper.InsertPropertyAliases(productNode, productTypeSetting.TitleProperty)
                                    : UmbracoHelper.InsertPropertyAliases(productNode,
                                                                          _config.GetConfiguration()
                                                                                 .ProductTitleProperty);

                product.ProductUrl = (productNode.template > 0) ? productNode.NiceUrl : "";

                product.ProductExternalId = (productTypeSetting != null)
                                                ? UmbracoHelper.GetPropertyAlias(productNode,
                                                                                 productTypeSetting.ExternalIdProperty)
                                                : UmbracoHelper.GetPropertyAlias(productNode,
                                                                                 _config.GetConfiguration()
                                                                                        .ProductExternalIdProperty);

                string locationConfig = (productTypeSetting != null)
                                            ? productTypeSetting.LocationHandler
                                            : _config.GetConfiguration().LocationHandler;

                var locationHandler = _locationHandlerFactory.GetLocationHandler(locationConfig);

                string locationCode = (productTypeSetting != null)
                                          ? UmbracoHelper.GetPropertyAlias(productNode,
                                                                           productTypeSetting.LocationProperty)
                                          : "";

                product.LocationCode = locationCode;

                var location = locationHandler.GetLocation(locationCode);

                product.Location = location.Title;
                product.LocationEmail = location.Email;

                product.StartDate = (productTypeSetting != null)
                                        ? UmbracoHelper.GetDateTimePropertyAlias(productNode,
                                                                                 productTypeSetting
                                                                                     .StartDateProperty)
                                        : UmbracoHelper.GetDateTimePropertyAlias(productNode,
                                                                                 _config.GetConfiguration()
                                                                                        .ProductStartDateProperty);

                product.FinishDate = (productTypeSetting != null)
                                         ? UmbracoHelper.GetDateTimePropertyAlias(productNode,
                                                                                  productTypeSetting.FinishDateProperty)
                                         : UmbracoHelper.GetDateTimePropertyAlias(productNode,
                                                                                  _config.GetConfiguration()
                                                                                         .ProductFinishDateProperty);

                product.StartDateRange1 = (productTypeSetting != null)
                                        ? UmbracoHelper.GetDateTimePropertyAlias(productNode,
                                                                                 productTypeSetting
                                                                                     .StartDateRange1Property)
                                        : UmbracoHelper.GetDateTimePropertyAlias(productNode,
                                                                                 _config.GetConfiguration()
                                                                                        .ProductStartDateRange1Property);

                product.FinishDateRange1 = (productTypeSetting != null)
                                         ? UmbracoHelper.GetDateTimePropertyAlias(productNode,
                                                                                  productTypeSetting.FinishDateRange1Property)
                                         : UmbracoHelper.GetDateTimePropertyAlias(productNode,
                                                                                  _config.GetConfiguration()
                                                                                         .ProductFinishDateRange1Property);

                product.StartDateRange2 = (productTypeSetting != null)
                                        ? UmbracoHelper.GetDateTimePropertyAlias(productNode,
                                                                                 productTypeSetting
                                                                                     .StartDateRange2Property)
                                        : UmbracoHelper.GetDateTimePropertyAlias(productNode,
                                                                                 _config.GetConfiguration()
                                                                                        .ProductStartDateRange2Property);

                product.FinishDateRange2 = (productTypeSetting != null)
                                         ? UmbracoHelper.GetDateTimePropertyAlias(productNode,
                                                                                  productTypeSetting.FinishDateRange2Property)
                                         : UmbracoHelper.GetDateTimePropertyAlias(productNode,
                                                                                  _config.GetConfiguration()
                                                                                         .ProductFinishDateRange2Property);

                product.ProductType = (productTypeSetting != null)
                                          ? productTypeSetting.ProductType
                                          : _config.GetConfiguration().ProductType;

                product.ProductTypeCode = productNode.NodeTypeAlias;

                product.Category = (productTypeSetting != null)
                                       ? UmbracoHelper.GetPropertyAlias(productNode, productTypeSetting.CategoryProperty)
                                       : UmbracoHelper.GetPropertyAlias(productNode,
                                                                        _config.GetConfiguration()
                                                                               .ProductCategoryProperty);

                product.VoucherCategory = (productTypeSetting != null)
                                              ? UmbracoHelper.GetPropertyAlias(productNode,
                                                                               productTypeSetting
                                                                                   .VoucherCategoryProperty)
                                              : UmbracoHelper.GetPropertyAlias(productNode,
                                                                               _config.GetConfiguration()
                                                                                      .ProductVoucherCategoryProperty);

                product.Code = (productTypeSetting != null)
                                   ? UmbracoHelper.GetPropertyAlias(productNode, productTypeSetting.CodeProperty)
                                   : UmbracoHelper.GetPropertyAlias(productNode,
                                                                    _config.GetConfiguration().ProductCodeProperty);

                product.Status = (productTypeSetting != null)
                                     ? UmbracoHelper.GetPropertyAlias(productNode, productTypeSetting.StatusProperty)
                                     : UmbracoHelper.GetPropertyAlias(productNode,
                                                                      _config.GetConfiguration().ProductStatusProperty);

                product.EcommerceDisabled = (productTypeSetting != null)
                                                ? UmbracoHelper.GetBooleanPropertyAlias(productNode,
                                                                                        productTypeSetting
                                                                                            .EcommerceDisabledProperty, false)
                                                : UmbracoHelper.GetBooleanPropertyAlias(productNode,
                                                                                        _config.GetConfiguration()
                                                                                               .ProductEcommerceDisabledProperty,
                                                                                        false);

                product.DepositOptionDisabled = (productTypeSetting != null)
                                                ? UmbracoHelper.GetBooleanPropertyAlias(productNode,
                                                                                        productTypeSetting
                                                                                            .DepositOptionDisabledProperty, false)
                                                : UmbracoHelper.GetBooleanPropertyAlias(productNode,
                                                                                        _config.GetConfiguration()
                                                                                               .ProductDepositOptionDisabledProperty,
                                                                                        false);

                product.DepositAmount = (productTypeSetting != null)
                                            ? productTypeSetting.DepositAmount
                                            : _config.GetConfiguration().ProductDepositAmount;

                product.MaximumQuantity = (productTypeSetting != null)
                                              ? productTypeSetting.MaximumQuantity
                                              : 0;

                product.OptionId = optionId;

                string priceAlias = (productTypeSetting != null)
                                        ? productTypeSetting.PriceProperty
                                        : _config.GetConfiguration().ProductPriceProperty;

                string earlyBirdPriceAlias = (productTypeSetting != null)
                        ? productTypeSetting.EarlyBirdPriceProperty
                        : _config.GetConfiguration().ProductEarlyBirdPriceProperty;

                decimal? price, earlyBirdPrice = null;
                decimal tempPrice, tempEarlyBirdPrice;

                if (optionId > 0)
                {
                    product.OptionTitle = (productTypeSetting != null)
                                              ? UmbracoHelper.InsertPropertyAliases(optionNode,
                                                                                    productTypeSetting
                                                                                        .OptionProperty)
                                              : UmbracoHelper.InsertPropertyAliases(optionNode,
                                                                                    _config.GetConfiguration()
                                                                                           .ProductOptionProperty);
                    product.OptionExternalId = (productTypeSetting != null)
                                                   ? UmbracoHelper.GetPropertyAlias(optionNode,
                                                                                    productTypeSetting
                                                                                        .OptionExternalIdProperty)
                                                   : UmbracoHelper.GetPropertyAlias(optionNode,
                                                                                    _config.GetConfiguration()
                                                                                           .ProductOptionExternalIdProperty);
                    price = decimal.TryParse(UmbracoHelper.GetPropertyAlias(optionNode, priceAlias), out tempPrice) ? tempPrice : (decimal?)null;
                    earlyBirdPrice=decimal.TryParse(UmbracoHelper.GetPropertyAlias(optionNode, earlyBirdPriceAlias), out tempEarlyBirdPrice) ? tempEarlyBirdPrice : (decimal?)null;

                }
                else
                {
                    price = decimal.TryParse(UmbracoHelper.GetPropertyAlias(productNode, priceAlias), out tempPrice) ? tempPrice : (decimal?)null;
                    earlyBirdPrice = decimal.TryParse(UmbracoHelper.GetPropertyAlias(productNode, earlyBirdPriceAlias),
                        out tempEarlyBirdPrice)
                        ? tempEarlyBirdPrice
                        : (decimal?) null;

                }
                product.Price = price;
                product.EarlyBirdPrice = earlyBirdPrice;
                product.BespokePricingHandler = (productTypeSetting != null)
                                                           ? productTypeSetting.BespokePricingHandler
                                                           : "";

                product.EarlyBirdPriceCutOffDate = (productTypeSetting != null)
                                         ? UmbracoHelper.GetDateTimePropertyAlias(productNode,
                                                                                  productTypeSetting.EarlyBirdPriceCutOffDateProperty)
                                         : UmbracoHelper.GetDateTimePropertyAlias(productNode,
                                                                                  _config.GetConfiguration()
                                                                                         .ProductEarlyBirdPriceCutOffDateProperty);

                operationStatus.Product = product;
                operationStatus.Status = true;
            }
            catch (Exception e)
            {
                operationStatus = OperationStatusExceptionHelper<ProductOperationStatus>
                    .CreateFromException("An error has occurred retrieving the product", e);
            }

            return operationStatus;
        }
        public void AddToOrderRepository()
        {
            var product = new Product
                {
                    ProductId = 29397,
                    ProductType = "P",
                    OrderIndex = 1,
                    Price = 3,
                    Title = "Test Product"
                };

            OrderOperationStatus operationStatus = _orderRepository.Add(product, 1, "F", product.Price,
                                                                        _existingUserCredentials);
            Assert.IsTrue(operationStatus.Status);
            //TODO: check that the product has been added sucessfully
        }
Exemple #21
0
        public OrderOperationStatus Add(Product product, int quantity,string paymentType,decimal paymentAmount)
        {
            var orderOperationStatus = new OrderOperationStatus();
            if (ContainsProduct(product)&&product.ProductType!="D")
            {
                return Update(product, product, quantity, paymentType, paymentAmount);
            }

            if (product.ChargedPrice == null)
            {
                orderOperationStatus.Message = "The item cannot be added because no price has been specified";
                orderOperationStatus.MessageCode = "CPX.NoPriceSpecified";
                orderOperationStatus.Status = false;
                return orderOperationStatus;
            }

            var orderLine = new OrderLine
            {
                OrderId = OrderId,
                ProductId = product.ProductId,
                ProductExternalId = product.ProductExternalId,
                ProductPrice = (decimal)product.ChargedPrice,
                ProductTitle = product.Title,
                ProductOptionId = product.OptionId,
                ProductOptionTitle = product.OptionTitle,
                ProductCategory = product.Category,
                ProductVoucherCategory = product.VoucherCategory,
                ProductCode = product.Code,
                ProductOptionExternalId = product.OptionExternalId,
                ProductType = product.ProductType,
                ProductUrl = product.ProductUrl,
                PaymentType = paymentType,
                PaymentAmount = paymentAmount,
                Location=product.Location,
                LocationCode=product.LocationCode,
                LocationEmail=product.LocationEmail,
                StartDate = product.StartDate,
                FinishDate=product.FinishDate,
                Quantity = quantity,
                OrderStatus="PROV",
                PaymentStatus="N"
            };
            OrderLines.Add(orderLine);

            orderOperationStatus.Status = true;
            orderOperationStatus.Order = this;
            orderOperationStatus.OrderLine = orderLine;
            return orderOperationStatus;
        }
Exemple #22
0
 public void ShouldNotUpdateItemToExistingProduct()
 {
     Order order = new Order();
     Product product = new Product {Title = "Test Product", ProductId = 1, OptionId = 1, OptionTitle = "Option1",Price=50};
     order.Add(product, 2, "F", 50);
     Assert.IsTrue(order.NumberOfItems == 2);
     Assert.IsTrue(order.ContainsProduct(product));
     Assert.IsTrue(order.PaymentTotal == 100);
     Product product2 = new Product
         {
             Title = "Test Product",
             ProductId = 1,
             OptionId = 2,
             OptionTitle = "Option2",
             Price=50
         };
     order.Add(product2, 2, "F", 50);
     Assert.IsTrue(order.NumberOfItems == 4);
     Assert.IsTrue(order.ContainsProduct(product2));
     Assert.IsTrue(order.PaymentTotal == 200);
     Product updateProduct = new Product
         {
             Title = "Test Product",
             ProductId = 1,
             OptionId = 2,
             OptionTitle = "Option2",
             Price=50
         };
     var operationStatus = order.Update(product, updateProduct, 6, "F", 50);
     Assert.IsTrue(operationStatus.Status == false);
     Assert.IsTrue(operationStatus.MessageCode == "CPX.ItemAlreadyInOrder");
 }
Exemple #23
0
        public OrderLine GetOrderLine(Product product)
        {
            if (ContainsProduct(product))
            {
                if (product.OptionId == 0)
                {
                    return CurrentOrderLines.FirstOrDefault(x => x.ProductId == product.ProductId);
                }
                return CurrentOrderLines.FirstOrDefault(x => x.ProductId == product.ProductId && x.ProductOptionId == product.OptionId);
            }

            else
            {
                throw new DataException("The product does not exist in the order, and therefore cannot be updated.");
            }
        }
 public Product CreateBespokePrice(Product product,int quantity)
 {
     return product;
 }
Exemple #25
0
 public OrderOperationStatus Remove(Product product)
 {
     var orderOperationStatus = new OrderOperationStatus();
     OrderLine orderLine = GetOrderLine(product);
     orderLine.OrderStatus = "DEL";
     orderOperationStatus.Order = this;
     orderOperationStatus.Status = true;
     orderOperationStatus.OrderLine = orderLine;
     orderOperationStatus.OrderLineDeleted = true;
     return orderOperationStatus;
 }
        public void DeletingProductWithDifferentOptions()
        {
            var product = new Product
                {
                    ProductId = 24359,
                    OptionId = 24904,
                    ProductType = "P",
                    OrderIndex = 1,
                    Price = 3,
                    Title = "Test Removing Same Poduct with Different Options 1"
                };
            OrderOperationStatus operationStatus = _orderRepository.Add(product, 1, "F", product.Price,
                                                                        _existingUserCredentials);
            Assert.IsTrue(operationStatus.Status);
            Assert.IsTrue(operationStatus.Order.ContainsProduct(product));
            var secondProduct = new Product()
            {
                ProductId = 24359,
                OptionId = 25308,
                ProductType = "P",
                OrderIndex = 1,
                Price = 3,
                Title = "Test Removing Same Poduct with Different Options 2"
            };

            operationStatus = _orderRepository.Add(secondProduct, 1, "F", product.Price, _existingUserCredentials);
            Assert.IsTrue(operationStatus.Status);
            Assert.IsTrue(operationStatus.Order.ContainsProduct(product));
            Assert.IsTrue(operationStatus.Order.ContainsProduct(secondProduct));
            Assert.IsTrue(operationStatus.Order.GetOrderLine(product).Quantity == 1);
            Assert.IsTrue(operationStatus.Order.GetOrderLine(secondProduct).Quantity == 1);

            operationStatus = _orderRepository.Remove(secondProduct, _existingUserCredentials);
            Assert.IsTrue(operationStatus.Status);
            Assert.IsTrue(operationStatus.Order.ContainsProduct(product));
            Assert.IsFalse(operationStatus.Order.ContainsProduct(secondProduct));
        }
 public void CheckAddingSameProduct()
 {
     var product = new Product
         {
             ProductId = 24126,
             ProductType = "P",
             OrderIndex = 1,
             Price = 3,
             Title = "Test Checking Same Twice Product"
         };
     OrderOperationStatus operationStatus = _orderRepository.Add(product, 1, "F", product.Price,
                                                                 _existingUserCredentials);
     Assert.IsTrue(operationStatus.Status);
     Assert.IsTrue(operationStatus.Order.ContainsProduct(product));
     operationStatus = _orderRepository.Add(product, 2, "F", product.Price, _existingUserCredentials);
     Assert.IsTrue(operationStatus.Status);
     Assert.IsTrue(operationStatus.Order.ContainsProduct(product));
     Assert.IsTrue(operationStatus.Order.GetOrderLine(product).Quantity == 3);
 }
Exemple #28
0
        public void ShouldReturnLocationEmailsCorrectly()
        {
            Order order = new Order();
            Product product = new Product
                {
                    Title = "Test Product",
                    ProductId = 1,
                    OptionId = 1,
                    OptionTitle = "Option1",
                    LocationEmail = "*****@*****.**",
                    Price=50
                };
            order.Add(product, 2, "F", 50);
            Assert.IsTrue(order.NumberOfItems == 2);
            Assert.IsTrue(order.ContainsProduct(product));
            var expectedEmailList = new List<string> {"*****@*****.**"};
            var actualEmailList = order.GetLocationEmails();

            Assert.AreEqual(expectedEmailList.Count,actualEmailList.Count);
            Assert.AreEqual(expectedEmailList[0],actualEmailList[0]);
            Product product2 = new Product
                {
                    Title = "Test Product 2",
                    ProductId = 2,
                    LocationEmail = "*****@*****.**",
                    Price=50
                };
            order.Add(product2, 2, "F", 50);
            Assert.IsTrue(order.NumberOfItems == 4);
            Assert.IsTrue(order.ContainsProduct(product2));

            expectedEmailList = new List<string> {"*****@*****.**", "*****@*****.**"};
            actualEmailList = order.GetLocationEmails();

            Assert.AreEqual(expectedEmailList.Count,actualEmailList.Count);
            Assert.AreEqual(expectedEmailList[0],actualEmailList[0]);
            Assert.AreEqual(expectedEmailList[1],actualEmailList[1]);

            //check that it only returns distinct email addresses
            Product product3 = new Product
            {
                Title = "Test Product 3",
                ProductId = 3,
                LocationEmail = "*****@*****.**",
                Price=50
            };
            order.Add(product3,2, "F", 50);
            Assert.IsTrue(order.NumberOfItems == 6);
            Assert.IsTrue(order.ContainsProduct(product3));

            actualEmailList = order.GetLocationEmails();
            Assert.AreEqual(expectedEmailList.Count,actualEmailList.Count);
            Assert.AreEqual(expectedEmailList[0],actualEmailList[0]);
            Assert.AreEqual(expectedEmailList[1],actualEmailList[1]);
        }
Exemple #29
0
 public void ShouldRecogniseWhenCanUseEarlyBirdPricingOnCutOffDay()
 {
     Product _sut = new Product
     {
         Price = 10,
         EarlyBirdPrice = 5,
         EarlyBirdPriceCutOffDate = DateTime.Now
     };
     Assert.AreEqual(true, _sut.CanUseEarlyBirdPrice());
 }
        public void CreateAndAddToOrderRepository()
        {
            var product = new Product
                {
                    ProductId = 29397,
                    ProductType = "P",
                    OrderIndex = 1,
                    Price = 3,
                    Title = "Test Product"
                };

            OrderOperationStatus operationStatus = _orderRepository.Add(product, 1, "F", product.Price,
                                                                        _newUserCredentials);
            Assert.IsTrue(operationStatus.Status);
            operationStatus = _orderRepository.GetOrder(_newUserCredentials);
            Assert.IsTrue(operationStatus.Status);
            var updatedOrder = operationStatus.Order;
            Assert.IsTrue(updatedOrder.ContainsProduct(product));
        }