示例#1
0
        protected virtual void ConvertVariant(ProductVariantQuery query, string key, string value)
        {
            if (key.EndsWith("-day") || key.EndsWith("-month"))
            {
                return;
            }

            var ids = key.Replace("pvari", "").SplitSafe("-");

            if (ids.Length > 3)
            {
                var variant = new ProductVariantQueryItem(value);
                variant.ProductId          = ids[0].ToInt();
                variant.BundleItemId       = ids[1].ToInt();
                variant.AttributeId        = ids[2].ToInt();
                variant.VariantAttributeId = ids[3].ToInt();

                if (key.EndsWith("-date") || key.EndsWith("-year"))
                {
                    variant.Date = ConvertToDate(key, value);
                }

                query.AddVariant(variant);
            }
        }
        protected virtual void ConvertVariant(ProductVariantQuery query, string key, ICollection <string> values)
        {
            var ids = key.Replace("pvari", "").SplitSafe("-");

            if (ids.Length < 4)
            {
                return;
            }

            var isDate = key.EndsWith("-date") || key.EndsWith("-year");
            var isFile = key.EndsWith("-file");
            var isText = key.EndsWith("-text");

            if (isDate || isFile || isText)
            {
                var value   = isText ? string.Join(",", values) : values.First();
                var variant = new ProductVariantQueryItem(value)
                {
                    ProductId          = ids[0].ToInt(),
                    BundleItemId       = ids[1].ToInt(),
                    AttributeId        = ids[2].ToInt(),
                    VariantAttributeId = ids[3].ToInt(),
                    IsFile             = isFile,
                    IsText             = isText
                };

                if (isDate)
                {
                    variant.Date = ConvertToDate(key, value);
                }

                query.AddVariant(variant);
            }
            else
            {
                foreach (var value in values)
                {
                    var variant = new ProductVariantQueryItem(value)
                    {
                        ProductId          = ids[0].ToInt(),
                        BundleItemId       = ids[1].ToInt(),
                        AttributeId        = ids[2].ToInt(),
                        VariantAttributeId = ids[3].ToInt()
                    };

                    query.AddVariant(variant);
                }
            }
        }
示例#3
0
        public void AddVariant(ProductVariantQueryItem item)
        {
            var exists = _variants.Any(x =>
                                       x.ProductId == item.ProductId &&
                                       x.BundleItemId == item.BundleItemId &&
                                       x.AttributeId == item.AttributeId &&
                                       x.VariantAttributeId == item.VariantAttributeId &&
                                       x.Value == item.Value
                                       );

            if (!exists)
            {
                _variants.Add(item);
            }
        }
示例#4
0
        protected virtual bool ConvertVariantAlias(ProductVariantQuery query, string key, ICollection <string> values, int languageId)
        {
            if (values.Count == 0)
            {
                return(false);
            }

            var ids = key.SplitSafe("-");
            var len = ids.Length;

            if (len < 4)
            {
                return(false);
            }

            var alias = string.Join("-", ids.Take(len - 3));

            var attributeId = _catalogSearchQueryAliasMapper.GetVariantIdByAlias(alias, languageId);

            if (attributeId == 0)
            {
                return(false);
            }

            var productId          = ids.SafeGet(len - 3).ToInt();
            var bundleItemId       = ids.SafeGet(len - 2).ToInt();
            var variantAttributeId = ids.SafeGet(len - 1).ToInt();

            if (productId == 0 || variantAttributeId == 0)
            {
                return(false);
            }

            foreach (var value in values)
            {
                // We cannot use GetVariantOptionIdByAlias. It doesn't necessarily provide a ProductVariantAttributeValue.Id associated with this product.
                //var optionId = _catalogSearchQueryAliasMapper.GetVariantOptionIdByAlias(value, attributeId, languageId);
                var    optionId   = 0;
                string valueAlias = null;
                var    valueIds   = value.SplitSafe("-");
                if (valueIds.Length >= 2)
                {
                    optionId   = valueIds.SafeGet(valueIds.Length - 1).ToInt();
                    valueAlias = string.Join("-", valueIds.Take(valueIds.Length - 1));
                }

                var variant = new ProductVariantQueryItem(optionId == 0 ? value : optionId.ToString());
                variant.ProductId          = productId;
                variant.BundleItemId       = bundleItemId;
                variant.AttributeId        = attributeId;
                variant.VariantAttributeId = variantAttributeId;
                variant.Alias = alias;

                if (optionId != 0)
                {
                    variant.ValueAlias = valueAlias;
                }

                query.AddVariant(variant);
            }

            return(true);
        }
        protected virtual void ConvertVariantAlias(ProductVariantQuery query, string key, ICollection <string> values, int languageId)
        {
            var ids = key.SplitSafe("-");
            var len = ids.Length;

            if (len < 4)
            {
                return;
            }

            var isDate = key.EndsWith("-date") || key.EndsWith("-year");
            var isFile = key.EndsWith("-file");
            var isText = key.EndsWith("-text");

            if (isDate || isFile || isText)
            {
                ids = ids.Take(len - 1).ToArray();
                len = ids.Length;
            }

            var alias       = string.Join("-", ids.Take(len - 3));
            var attributeId = _catalogSearchQueryAliasMapper.GetVariantIdByAlias(alias, languageId);

            if (attributeId == 0)
            {
                return;
            }

            var productId          = ids.SafeGet(len - 3).ToInt();
            var bundleItemId       = ids.SafeGet(len - 2).ToInt();
            var variantAttributeId = ids.SafeGet(len - 1).ToInt();

            if (productId == 0 || variantAttributeId == 0)
            {
                return;
            }

            if (isDate || isFile || isText)
            {
                var value   = isText ? string.Join(",", values) : values.First();
                var variant = new ProductVariantQueryItem(value)
                {
                    ProductId          = productId,
                    BundleItemId       = bundleItemId,
                    AttributeId        = attributeId,
                    VariantAttributeId = variantAttributeId,
                    Alias  = alias,
                    IsFile = isFile,
                    IsText = isText
                };

                if (isDate)
                {
                    variant.Date = ConvertToDate(key, value);
                }

                query.AddVariant(variant);
            }
            else
            {
                foreach (var value in values)
                {
                    // We cannot use GetVariantOptionIdByAlias. It doesn't necessarily provide a ProductVariantAttributeValue.Id associated with this product.
                    //var optionId = _catalogSearchQueryAliasMapper.GetVariantOptionIdByAlias(value, attributeId, languageId);
                    var    optionId   = 0;
                    string valueAlias = null;

                    var valueIds = value.SplitSafe("-");
                    if (valueIds.Length >= 2)
                    {
                        optionId   = valueIds.SafeGet(valueIds.Length - 1).ToInt();
                        valueAlias = string.Join("-", valueIds.Take(valueIds.Length - 1));
                    }

                    var variant = new ProductVariantQueryItem(optionId == 0 ? value : optionId.ToString())
                    {
                        ProductId          = productId,
                        BundleItemId       = bundleItemId,
                        AttributeId        = attributeId,
                        VariantAttributeId = variantAttributeId,
                        Alias = alias
                    };

                    if (optionId != 0)
                    {
                        variant.ValueAlias = valueAlias;
                    }

                    query.AddVariant(variant);
                }
            }
        }
示例#6
0
 public void AddVariant(ProductVariantQueryItem item)
 {
     _variants.Add(item);
 }