private void AddProductDescriptionsForVariants(Product product, ProductVariation sfProduct)
        {
            var productDefinitionId = product.ProductDefinition.Id;
            var definition          = _session.Query <ProductDefinition>().FirstOrDefault(x => x.ProductDefinitionId == productDefinitionId);

            if (definition == null)
            {
                return;
            }

            // Create product descriptions for each variant culture
            foreach (var translation in sfProduct.CultureTranslations)
            {
                var attributeNames              = translation.Value.VariantNames.Attribute.Split(',');
                var attributeValues             = translation.Value.VariantNames.AttributeValue.Split(',');
                var productDefinitionFieldNames = sfProduct.VariantNames.Attribute.Split(',');

                // There are no descriptions in Sitefinity at the variant level so for uCommerce we use
                // the concatenated variant values for display name + long & short descriptions
                var displayName      = translation.Value.VariantNames.AttributeValue;
                var shortDescription = translation.Value.VariantNames.AttributeValue;
                var longDescription  = translation.Value.VariantNames.AttributeValue;

                var productDescription = new ProductDescription
                {
                    CultureCode      = translation.Key,
                    DisplayName      = displayName,
                    ShortDescription = shortDescription,
                    LongDescription  = longDescription
                };

                // Create product description properties for each variant value culture
                for (var i = 0; i < attributeNames.Length; i++)
                {
                    var fieldName = productDefinitionFieldNames[i];
                    var field     = definition.ProductDefinitionFields.FirstOrDefault(x => x.Name == fieldName.Trim());

                    var productDescriptionProperty = new ProductDescriptionProperty
                    {
                        ProductDefinitionField = field,
                        ProductDescription     = productDescription,
                        Value       = attributeValues[i],
                        CultureCode = translation.Key
                    };

                    productDescription.AddProductDescriptionProperty(productDescriptionProperty);
                }

                product.AddProductDescription(productDescription);
            }
        }
Esempio n. 2
0
        private void AddProductDescriptionProperty(Product product, string name, string value, string cultureCode)
        {
            var field = new ProductDefinitionField();

            field.Name         = name;
            field.Multilingual = true;

            var productDescription = product.ProductDescriptions.SingleOrDefault(x => x.CultureCode == cultureCode);

            if (productDescription == null)
            {
                throw new NullReferenceException(
                          "productDescription should not be null since its parsed before 'ProductDescriptionProperties'");
            }

            var productProperty = new ProductDescriptionProperty
            {
                Value = value,
                ProductDefinitionField = field
            };

            productDescription.ProductDescriptionProperties.Add(productProperty);
        }