Fieldvalueselectortype on productmodel

How can I use FieldValueSelectorType value on the productmodel?

It says here in the description that it

“Gets or sets the field value selector.”

But its defined as:

public virtual ProductModel.FieldValueSelectorType FieldValueSelector { get; }

Im interested in having it as VariantAndBaseProduct = 8 How can I make that happen?

Version 7.7.1

Yes it is only “get” we must fix the documentation.
This needs to be set on ProductModel initialization:

public ProductModel(BaseProduct baseProduct, Variant selectedVariant, FieldValueSelectorType fieldValueSelector, Lazy<ProductFieldTemplate> fieldTemplate, Lazy<ProductDisplayTemplate> displayTemplate)
        {
            BaseProduct = baseProduct;
            SelectedVariant = selectedVariant;
            FieldValueSelector = fieldValueSelector;
            _fieldTemplate = fieldTemplate;
            _displayTemplate = displayTemplate;
        }

What is the FieldValueSelectorType set to when using ProductModelBuilder?

Not sure what you mean but this gets set in ProductModelBuilderImpl.cs depending on what method (eg. BuildFromVariant or BuildFromBaseProduct) is called to generate the ProductModel.
Why do you need to set FieldValueSelectorType your self, what are you trying to do?

I would like to know what FieldValueSelectorType is set to when using the different methods in ProductModelBuilder

        [Obsolete("Channel is mandatory, use overload.")]
        public override ProductModel BuildFromBaseProduct(BaseProduct baseProduct, WebSite webSite)
        {
            throw new NotSupportedException("Building ProductModel from baseProduct and website is not supported.");
        }

        public override ProductModel BuildFromBaseProduct(BaseProduct baseProduct, Channel channel)
        {
            if (baseProduct == null)
            {
                return null;
            }

            var variant = _variantService
                .GetByBaseProduct(baseProduct.SystemId)
                .FirstOrDefault(x => x.ChannelLinks.Any(z => z.ChannelSystemId == channel.SystemId));
            return variant == null ? null : BuildFromBaseProduct(baseProduct, variant);
        }

        public override ProductModel BuildFromBaseProduct(BaseProduct baseProduct, Variant selectedVariant)
        {
            return Create(baseProduct, selectedVariant);
        }

        public override ProductModel BuildFromBaseProduct(BaseProduct baseProduct)
        {
            if (baseProduct == null)
            {
                return null;
            }

            var channel = _routeRequestLookupInfoAccessor.RouteRequestLookupInfo?.Channel;
            if (channel == null)
            {
                return null;
            }

            var variant = _variantService
                .GetByBaseProduct(baseProduct.SystemId)
                .FirstOrDefault(x => x.ChannelLinks.Any(z => z.ChannelSystemId == channel.SystemId));
            return variant == null ? null : BuildFromBaseProduct(baseProduct, variant);
        }

        public override ProductModel BuildFromVariant(Variant variant)
        {
            if (variant == null)
            {
                return null;
            }

            return Create(null, variant);
        }

        public override ProductModel BuildFromVariant(Variant variant, BaseProduct baseProduct)
        {
            if (variant == null)
            {
                return null;
            }

            return Create(baseProduct, variant, ProductModel.FieldValueSelectorType.VariantAndBaseProduct);
        }

        private ProductModel Create(BaseProduct baseProduct, [NotNull] Variant selectedVariant, ProductModel.FieldValueSelectorType? fieldValueSelectorTypeDefault = null)
        {
            var fieldValueSelector = fieldValueSelectorTypeDefault ??
                (baseProduct == null ? ProductModel.FieldValueSelectorType.VariantAndBaseProduct : ProductModel.FieldValueSelectorType.BaseProductAndVariant);

            if (baseProduct == null)
            {
                baseProduct = _baseProductService.Get(selectedVariant.BaseProductSystemId);
            }
            else if (baseProduct.SystemId != selectedVariant.BaseProductSystemId)
            {
                throw new ArgumentException("Variant does not belong to the BaseProduct.", nameof(selectedVariant));
            }

            foreach (var validator in _renderingValidators)
            {
                if (!validator.Validate(baseProduct))
                {
                    return null;
                }
            }

            var fieldTemplate = new Lazy<ProductFieldTemplate>(() => _fieldTemplateService.Get<ProductFieldTemplate>(baseProduct.FieldTemplateSystemId));
            var displayTemplate = new Lazy<ProductDisplayTemplate>(() => _displayTemplateService.Get<ProductDisplayTemplate>(fieldTemplate.Value.DisplayTemplateSystemId));

            return new ProductModel(baseProduct, selectedVariant, fieldValueSelector, fieldTemplate, displayTemplate);
        }

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.