Webiant Logo Webiant Logo
  1. No results found.

    Try your search with a different keyword or use * as a wildcard.

ExportSpecificationAttribute.cs

using Nop.Core.Domain.Catalog;
using Nop.Services.Catalog;

namespace Nop.Services.ExportImport;

public partial class ExportSpecificationAttribute : ProductSpecificationAttribute
{
    protected ExportSpecificationAttribute() { }

    /// 
    /// Gets or sets the specification attribute identifier
    /// 
    public int SpecificationAttributeId { get; set; }

    /// 
    /// Create data to export the product specification attribute
    /// 
    /// The product specification attribute to export
    /// Specification attribute service
    /// 
    /// 
    public static async Task CreateAsync(ProductSpecificationAttribute specificationAttribute, ISpecificationAttributeService specificationAttributeService)
    {
        var specificationAttributeOption = await specificationAttributeService.GetSpecificationAttributeOptionByIdAsync(specificationAttribute.SpecificationAttributeOptionId);

        var attribute = new ExportSpecificationAttribute
        {
            Id = specificationAttribute.Id,
            AttributeTypeId = specificationAttribute.AttributeTypeId,
            AllowFiltering = specificationAttribute.AllowFiltering,
            ShowOnProductPage = specificationAttribute.ShowOnProductPage,
            DisplayOrder = specificationAttribute.DisplayOrder,
            SpecificationAttributeOptionId = specificationAttribute.SpecificationAttributeOptionId,
            SpecificationAttributeId = specificationAttributeOption.SpecificationAttributeId
        };

        switch (attribute.AttributeType)
        {
            case SpecificationAttributeType.Option:
                attribute.CustomValue = specificationAttributeOption.Name;
                break;
            case SpecificationAttributeType.CustomText:
            case SpecificationAttributeType.CustomHtmlText:
            case SpecificationAttributeType.Hyperlink:
                attribute.CustomValue = specificationAttribute.CustomValue;
                break;
        }

        return attribute;
    }
}