コード例 #1
0
        public void Can_add_and_remove_checkoutAttributes()
        {
            var attributes = "";

            //color: green
            attributes = _checkoutAttributeParser.AddCheckoutAttribute(attributes, ca1, cav1_1.Id.ToString());
            //custom option: option 1, option 2
            attributes = _checkoutAttributeParser.AddCheckoutAttribute(attributes, ca2, cav2_1.Id.ToString());
            attributes = _checkoutAttributeParser.AddCheckoutAttribute(attributes, ca2, cav2_2.Id.ToString());
            //custom text
            attributes = _checkoutAttributeParser.AddCheckoutAttribute(attributes, ca3, "Some custom text goes here");
            //delete some of them
            attributes = _checkoutAttributeParser.RemoveCheckoutAttribute(attributes, ca2);
            attributes = _checkoutAttributeParser.RemoveCheckoutAttribute(attributes, ca3);

            var parsed_attributeValues = _checkoutAttributeParser.ParseCheckoutAttributeValues(attributes);

            parsed_attributeValues.Contains(cav1_1).ShouldEqual(true);
            parsed_attributeValues.Contains(cav1_2).ShouldEqual(false);
            parsed_attributeValues.Contains(cav2_1).ShouldEqual(false);
            parsed_attributeValues.Contains(cav2_2).ShouldEqual(false);
            parsed_attributeValues.Contains(cav2_2).ShouldEqual(false);

            var parsedValues = _checkoutAttributeParser.ParseValues(attributes, ca3.Id);

            parsedValues.Count.ShouldEqual(0);
        }
コード例 #2
0
        public void Can_add_and_remove_checkoutAttributes()
        {
            var attributes = "";

            //color: green
            attributes = _checkoutAttributeParser.AddCheckoutAttribute(attributes, ca1, cav1_1.Id.ToString());
            //custom option: option 1, option 2
            attributes = _checkoutAttributeParser.AddCheckoutAttribute(attributes, ca2, cav2_1.Id.ToString());
            attributes = _checkoutAttributeParser.AddCheckoutAttribute(attributes, ca2, cav2_2.Id.ToString());
            //custom text
            attributes = _checkoutAttributeParser.AddCheckoutAttribute(attributes, ca3, "Some custom text goes here");
            //delete some of them
            attributes = _checkoutAttributeParser.RemoveCheckoutAttribute(attributes, ca2);
            attributes = _checkoutAttributeParser.RemoveCheckoutAttribute(attributes, ca3);

            RunWithTestServiceProvider(() =>
            {
                var parsedAttributeValues = _checkoutAttributeParser.ParseCheckoutAttributeValues(attributes).ToList();
                parsedAttributeValues.SelectMany(x => x.values).Contains(cav1_1).Should().BeTrue();
                parsedAttributeValues.SelectMany(x => x.values).Contains(cav1_2).Should().BeFalse();
                parsedAttributeValues.SelectMany(x => x.values).Contains(cav2_1).Should().BeFalse();
                parsedAttributeValues.SelectMany(x => x.values).Contains(cav2_2).Should().BeFalse();
                parsedAttributeValues.SelectMany(x => x.values).Contains(cav2_2).Should().BeFalse();

                var parsedValues = _checkoutAttributeParser.ParseValues(attributes, ca3.Id);
                parsedValues.Count.Should().Be(0);
            });
        }
コード例 #3
0
        public void CanAddAndRemoveCheckoutAttributes()
        {
            var attributes = string.Empty;

            //color: green
            attributes = _checkoutAttributeParser.AddCheckoutAttribute(attributes, _ca1, _cav11.Id.ToString());
            //custom option: option 1, option 2
            attributes = _checkoutAttributeParser.AddCheckoutAttribute(attributes, _ca2, _cav21.Id.ToString());
            attributes = _checkoutAttributeParser.AddCheckoutAttribute(attributes, _ca2, _cav22.Id.ToString());
            //custom text
            attributes = _checkoutAttributeParser.AddCheckoutAttribute(attributes, _ca3, "Some custom text goes here");
            //delete some of them
            attributes = _checkoutAttributeParser.RemoveCheckoutAttribute(attributes, _ca2);
            attributes = _checkoutAttributeParser.RemoveCheckoutAttribute(attributes, _ca3);

            var parsedAttributeValues = _checkoutAttributeParser.ParseCheckoutAttributeValues(attributes).ToList();

            parsedAttributeValues.SelectMany(x => x.values.Select(p => p.Id)).Contains(_cav11.Id).Should().BeTrue();
            parsedAttributeValues.SelectMany(x => x.values.Select(p => p.Id)).Contains(_cav12.Id).Should().BeFalse();
            parsedAttributeValues.SelectMany(x => x.values.Select(p => p.Id)).Contains(_cav21.Id).Should().BeFalse();
            parsedAttributeValues.SelectMany(x => x.values.Select(p => p.Id)).Contains(_cav22.Id).Should().BeFalse();
            parsedAttributeValues.SelectMany(x => x.values.Select(p => p.Id)).Contains(_cav22.Id).Should().BeFalse();

            var parsedValues = _checkoutAttributeParser.ParseValues(attributes, _ca3.Id);

            parsedValues.Count.Should().Be(0);
        }
コード例 #4
0
        public void Can_add_checkoutAttributes()
        {
            IList <CustomAttribute> attributes = new List <CustomAttribute>();

            //color: green
            attributes = _checkoutAttributeParser.AddCheckoutAttribute(attributes, ca1, cav1_1.Id.ToString()).ToList();
            //custom option: option 1, option 2
            attributes = _checkoutAttributeParser.AddCheckoutAttribute(attributes, ca2, cav2_1.Id.ToString()).ToList();
            attributes = _checkoutAttributeParser.AddCheckoutAttribute(attributes, ca2, cav2_2.Id.ToString()).ToList();
            //custom text
            attributes = _checkoutAttributeParser.AddCheckoutAttribute(attributes, ca3, "absolutely any value").ToList();

            Assert.IsTrue(attributes.Count == 4);
            Assert.IsTrue(attributes.Any(c => c.Key.Equals(ca1.Id)));
            Assert.IsTrue(attributes.Any(c => c.Key.Equals(ca2.Id)));
            Assert.IsTrue(attributes.Any(c => c.Key.Equals(ca3.Id)));
            attributes = _checkoutAttributeParser.RemoveCheckoutAttribute(attributes, ca1);
            Assert.IsTrue(attributes.Count == 3);
            Assert.IsFalse(attributes.Any(c => c.Key.Equals(ca1.Id)));
        }
        public async Task <IList <CustomAttribute> > Handle(SaveCheckoutAttributesCommand request, CancellationToken cancellationToken)
        {
            if (request.Cart == null)
            {
                throw new ArgumentNullException("cart");
            }

            if (request.Form == null)
            {
                throw new ArgumentNullException("form");
            }

            var customAttributes   = new List <CustomAttribute>();
            var checkoutAttributes = await _checkoutAttributeService.GetAllCheckoutAttributes(request.Store.Id, !request.Cart.RequiresShipping());

            foreach (var attribute in checkoutAttributes)
            {
                string controlId = string.Format("checkout_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))
                    {
                        customAttributes = _checkoutAttributeParser.AddCheckoutAttribute(customAttributes,
                                                                                         attribute, ctrlAttributes).ToList();
                    }
                }
                break;

                case AttributeControlType.Checkboxes:
                {
                    var cblAttributes = request.Form[controlId].ToString();
                    if (!string.IsNullOrEmpty(cblAttributes))
                    {
                        foreach (var item in cblAttributes.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            customAttributes = _checkoutAttributeParser.AddCheckoutAttribute(customAttributes, attribute, item).ToList();
                        }
                    }
                }
                break;

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

                case AttributeControlType.TextBox:
                case AttributeControlType.MultilineTextbox:
                {
                    var ctrlAttributes = request.Form[controlId].ToString();
                    if (!string.IsNullOrEmpty(ctrlAttributes))
                    {
                        string enteredText = ctrlAttributes.Trim();
                        customAttributes = _checkoutAttributeParser.AddCheckoutAttribute(customAttributes,
                                                                                         attribute, enteredText).ToList();
                    }
                }
                break;

                case AttributeControlType.Datepicker:
                {
                    var      date         = 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(date));
                    }
                    catch { }
                    if (selectedDate.HasValue)
                    {
                        customAttributes = _checkoutAttributeParser.AddCheckoutAttribute(customAttributes,
                                                                                         attribute, selectedDate.Value.ToString("D")).ToList();
                    }
                }
                break;

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

                    if (download != null)
                    {
                        customAttributes = _checkoutAttributeParser.AddCheckoutAttribute(customAttributes,
                                                                                         attribute, download.DownloadGuid.ToString()).ToList();
                    }
                }
                break;

                default:
                    break;
                }
            }

            //save checkout attributes
            //validate conditional attributes (if specified)
            foreach (var attribute in checkoutAttributes)
            {
                var conditionMet = await _checkoutAttributeParser.IsConditionMet(attribute, customAttributes);

                if (conditionMet.HasValue && !conditionMet.Value)
                {
                    customAttributes = _checkoutAttributeParser.RemoveCheckoutAttribute(customAttributes, attribute).ToList();
                }
            }
            await _genericAttributeService.SaveAttribute(request.Customer, SystemCustomerAttributeNames.CheckoutAttributes, customAttributes, request.Store.Id);

            return(customAttributes);
        }