public async Task CanRenderAttributesWithoutPrices()
        {
            var attributes = string.Empty;

            foreach (var productAttributeMapping in _productAttributeMappings)
            {
                foreach (var productAttributeValue in productAttributeMapping.Value.OrderBy(p => p.Id))
                {
                    attributes = _productAttributeParser.AddProductAttribute(attributes, productAttributeMapping.Key, productAttributeValue.Id.ToString());
                }
            }

            attributes = _productAttributeParser.AddGiftCardAttribute(attributes,
                                                                      "recipientName 1", "*****@*****.**",
                                                                      "senderName 1", "*****@*****.**", "custom message");

            var product = new Product {
                IsGiftCard = true, GiftCardType = GiftCardType.Virtual
            };
            var customer = new Customer();

            var formattedAttributes = await _productAttributeFormatter.FormatAttributesAsync(product,
                                                                                             attributes, customer, "<br />", false);

            formattedAttributes.Should().Be(
                "Processor: 2.2 GHz Intel Pentium Dual-Core E2200<br />Processor: 2.5 GHz Intel Pentium Dual-Core E2200 [+$15.00]<br />RAM: 2 GB<br />RAM: 4GB [+$20.00]<br />RAM: 8GB [+$60.00]<br />HDD: 320 GB<br />HDD: 400 GB [+$100.00]<br />OS: Vista Home [+$50.00]<br />OS: Vista Premium [+$60.00]<br />Software: Microsoft Office [+$50.00]<br />Software: Acrobat Reader [+$10.00]<br />Software: Total Commander [+$5.00]<br />From: senderName 1 <*****@*****.**><br />For: recipientName 1 <*****@*****.**>");

            formattedAttributes = await _productAttributeFormatter.FormatAttributesAsync(product,
                                                                                         attributes, customer, "<br />", false, false);

            formattedAttributes.Should().Be(
                "Processor: 2.2 GHz Intel Pentium Dual-Core E2200<br />Processor: 2.5 GHz Intel Pentium Dual-Core E2200<br />RAM: 2 GB<br />RAM: 4GB<br />RAM: 8GB<br />HDD: 320 GB<br />HDD: 400 GB<br />OS: Vista Home<br />OS: Vista Premium<br />Software: Microsoft Office<br />Software: Acrobat Reader<br />Software: Total Commander<br />From: senderName 1 <*****@*****.**><br />For: recipientName 1 <*****@*****.**>");
        }
Beispiel #2
0
        public void Can_add_and_parse_giftCardAttributes()
        {
            var attributes = "";

            attributes = _productAttributeParser.AddGiftCardAttribute(attributes,
                                                                      "recipientName 1", "*****@*****.**",
                                                                      "senderName 1", "*****@*****.**", "custom message");

            _productAttributeParser.GetGiftCardAttribute(attributes,
                                                         out var recipientName,
                                                         out var recipientEmail,
                                                         out var senderName,
                                                         out var senderEmail,
                                                         out var giftCardMessage);
            recipientName.ShouldEqual("recipientName 1");
            recipientEmail.ShouldEqual("*****@*****.**");
            senderName.ShouldEqual("senderName 1");
            senderEmail.ShouldEqual("*****@*****.**");
            giftCardMessage.ShouldEqual("custom message");
        }
        public void Can_add_and_parse_giftCardAttributes()
        {
            string attributes = "";

            attributes = _productAttributeParser.AddGiftCardAttribute(attributes,
                                                                      "recipientName 1", "*****@*****.**",
                                                                      "senderName 1", "*****@*****.**", "custom message");

            string recipientName, recipientEmail, senderName, senderEmail, giftCardMessage;

            _productAttributeParser.GetGiftCardAttribute(attributes,
                                                         out recipientName,
                                                         out recipientEmail,
                                                         out senderName,
                                                         out senderEmail,
                                                         out giftCardMessage);
            Assert.AreEqual("recipientName 1", recipientName);
            Assert.AreEqual("*****@*****.**", recipientEmail);
            Assert.AreEqual("senderName 1", senderName);
            Assert.AreEqual("*****@*****.**", senderEmail);
            Assert.AreEqual("custom message", giftCardMessage);
        }
        public static string AddGiftCardAttribute(this NameValueCollection collection, string attributes, int productId, IProductAttributeParser productAttributeParser, int bundleItemId = 0)
        {
            string recipientName   = "";
            string recipientEmail  = "";
            string senderName      = "";
            string senderEmail     = "";
            string giftCardMessage = "";

            string strProductId = "";

            if (productId != 0)
            {
                strProductId = "_{0}_{1}".FormatWith(productId, bundleItemId);
            }

            foreach (string formKey in collection.AllKeys)
            {
                if (formKey.Equals(string.Format("giftcard{0}.RecipientName", strProductId), StringComparison.InvariantCultureIgnoreCase))
                {
                    recipientName = collection[formKey];
                    continue;
                }
                if (formKey.Equals(string.Format("giftcard{0}.RecipientEmail", strProductId), StringComparison.InvariantCultureIgnoreCase))
                {
                    recipientEmail = collection[formKey];
                    continue;
                }
                if (formKey.Equals(string.Format("giftcard{0}.SenderName", strProductId), StringComparison.InvariantCultureIgnoreCase))
                {
                    senderName = collection[formKey];
                    continue;
                }
                if (formKey.Equals(string.Format("giftcard{0}.SenderEmail", strProductId), StringComparison.InvariantCultureIgnoreCase))
                {
                    senderEmail = collection[formKey];
                    continue;
                }
                if (formKey.Equals(string.Format("giftcard{0}.Message", strProductId), StringComparison.InvariantCultureIgnoreCase))
                {
                    giftCardMessage = collection[formKey];
                    continue;
                }
            }

            return(productAttributeParser.AddGiftCardAttribute(attributes, recipientName, recipientEmail, senderName, senderEmail, giftCardMessage));
        }
        public static string AddGiftCardAttribute(this NameValueCollection collection, string attributes, int productId, IProductAttributeParser productAttributeParser, int bundleItemId = 0)
        {
            string recipientName = "";
            string recipientEmail = "";
            string senderName = "";
            string senderEmail = "";
            string giftCardMessage = "";

            string strProductId = "";
            if (productId != 0)
                strProductId = "_{0}_{1}".FormatWith(productId, bundleItemId);

            foreach (string formKey in collection.AllKeys)
            {
                if (formKey.Equals(string.Format("giftcard{0}.RecipientName", strProductId), StringComparison.InvariantCultureIgnoreCase))
                {
                    recipientName = collection[formKey];
                    continue;
                }
                if (formKey.Equals(string.Format("giftcard{0}.RecipientEmail", strProductId), StringComparison.InvariantCultureIgnoreCase))
                {
                    recipientEmail = collection[formKey];
                    continue;
                }
                if (formKey.Equals(string.Format("giftcard{0}.SenderName", strProductId), StringComparison.InvariantCultureIgnoreCase))
                {
                    senderName = collection[formKey];
                    continue;
                }
                if (formKey.Equals(string.Format("giftcard{0}.SenderEmail", strProductId), StringComparison.InvariantCultureIgnoreCase))
                {
                    senderEmail = collection[formKey];
                    continue;
                }
                if (formKey.Equals(string.Format("giftcard{0}.Message", strProductId), StringComparison.InvariantCultureIgnoreCase))
                {
                    giftCardMessage = collection[formKey];
                    continue;
                }
            }

            return productAttributeParser.AddGiftCardAttribute(attributes, recipientName, recipientEmail, senderName, senderEmail, giftCardMessage);
        }
        public async Task <string> Handle(GetParseProductAttributes request, CancellationToken cancellationToken)
        {
            string attributesXml = "";

            #region Product attributes

            var productAttributes = request.Product.ProductAttributeMappings.ToList();
            if (request.Product.ProductType == ProductType.BundledProduct)
            {
                foreach (var bundle in request.Product.BundleProducts)
                {
                    var bp = await _productService.GetProductById(bundle.ProductId);

                    if (bp.ProductAttributeMappings.Any())
                    {
                        productAttributes.AddRange(bp.ProductAttributeMappings);
                    }
                }
            }

            foreach (var attribute in productAttributes)
            {
                string controlId = string.Format("product_attribute_{0}", attribute.Id);
                switch (attribute.AttributeControlType)
                {
                case AttributeControlType.DropdownList:
                case AttributeControlType.RadioList:
                case AttributeControlType.ColorSquares:
                case AttributeControlType.ImageSquares:
                {
                    var ctrlAttributes = request.Form[controlId];
                    if (!String.IsNullOrEmpty(ctrlAttributes))
                    {
                        attributesXml = _productAttributeParser.AddProductAttribute(attributesXml,
                                                                                    attribute, ctrlAttributes);
                    }
                }
                break;

                case AttributeControlType.Checkboxes:
                {
                    var ctrlAttributes = request.Form[controlId].ToString();
                    if (!String.IsNullOrEmpty(ctrlAttributes))
                    {
                        foreach (var item in ctrlAttributes.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            if (!String.IsNullOrEmpty(item))
                            {
                                attributesXml = _productAttributeParser.AddProductAttribute(attributesXml,
                                                                                            attribute, item);
                            }
                        }
                    }
                }
                break;

                case AttributeControlType.ReadonlyCheckboxes:
                {
                    //load read-only (already server-side selected) values
                    var attributeValues = attribute.ProductAttributeValues;
                    foreach (var selectedAttributeId in attributeValues
                             .Where(v => v.IsPreSelected)
                             .Select(v => v.Id)
                             .ToList())
                    {
                        attributesXml = _productAttributeParser.AddProductAttribute(attributesXml,
                                                                                    attribute, selectedAttributeId);
                    }
                }
                break;

                case AttributeControlType.TextBox:
                case AttributeControlType.MultilineTextbox:
                {
                    var ctrlAttributes = request.Form[controlId].ToString();
                    if (!String.IsNullOrEmpty(ctrlAttributes))
                    {
                        string enteredText = ctrlAttributes.Trim();
                        attributesXml = _productAttributeParser.AddProductAttribute(attributesXml,
                                                                                    attribute, enteredText);
                    }
                }
                break;

                case AttributeControlType.Datepicker:
                {
                    var      day          = request.Form[controlId + "_day"];
                    var      month        = request.Form[controlId + "_month"];
                    var      year         = request.Form[controlId + "_year"];
                    DateTime?selectedDate = null;
                    try
                    {
                        selectedDate = new DateTime(Int32.Parse(year), Int32.Parse(month), Int32.Parse(day));
                    }
                    catch { }
                    if (selectedDate.HasValue)
                    {
                        attributesXml = _productAttributeParser.AddProductAttribute(attributesXml,
                                                                                    attribute, selectedDate.Value.ToString("D"));
                    }
                }
                break;

                case AttributeControlType.FileUpload:
                {
                    Guid downloadGuid;
                    Guid.TryParse(request.Form[controlId], out downloadGuid);
                    var download = await _downloadService.GetDownloadByGuid(downloadGuid);

                    if (download != null)
                    {
                        attributesXml = _productAttributeParser.AddProductAttribute(attributesXml,
                                                                                    attribute, download.DownloadGuid.ToString());
                    }
                }
                break;

                default:
                    break;
                }
            }
            //validate conditional attributes (if specified)
            foreach (var attribute in productAttributes)
            {
                var conditionMet = _productAttributeParser.IsConditionMet(request.Product, attribute, attributesXml);
                if (conditionMet.HasValue && !conditionMet.Value)
                {
                    attributesXml = _productAttributeParser.RemoveProductAttribute(attributesXml, attribute);
                }
            }

            #endregion

            #region Gift cards

            if (request.Product.IsGiftCard)
            {
                string recipientName   = "";
                string recipientEmail  = "";
                string senderName      = "";
                string senderEmail     = "";
                string giftCardMessage = "";
                foreach (string formKey in request.Form.Keys)
                {
                    if (formKey.Equals(string.Format("giftcard_{0}.RecipientName", request.Product.Id), StringComparison.OrdinalIgnoreCase))
                    {
                        recipientName = request.Form[formKey];
                        continue;
                    }
                    if (formKey.Equals(string.Format("giftcard_{0}.RecipientEmail", request.Product.Id), StringComparison.OrdinalIgnoreCase))
                    {
                        recipientEmail = request.Form[formKey];
                        continue;
                    }
                    if (formKey.Equals(string.Format("giftcard_{0}.SenderName", request.Product.Id), StringComparison.OrdinalIgnoreCase))
                    {
                        senderName = request.Form[formKey];
                        continue;
                    }
                    if (formKey.Equals(string.Format("giftcard_{0}.SenderEmail", request.Product.Id), StringComparison.OrdinalIgnoreCase))
                    {
                        senderEmail = request.Form[formKey];
                        continue;
                    }
                    if (formKey.Equals(string.Format("giftcard_{0}.Message", request.Product.Id), StringComparison.OrdinalIgnoreCase))
                    {
                        giftCardMessage = request.Form[formKey];
                        continue;
                    }
                }

                attributesXml = _productAttributeParser.AddGiftCardAttribute(attributesXml,
                                                                             recipientName, recipientEmail, senderName, senderEmail, giftCardMessage);
            }

            #endregion

            return(attributesXml);
        }