private void AddVariantProperties(Product product, ProductVariation sfVariant, Product variantProduct)
        {
            // Variant names and values live in comma separated lists in the Sitefinity models
            var variantFieldNames = sfVariant.VariantNames.Attribute.Split(',');
            var variantValues     = sfVariant.VariantNames.AttributeValue.Split(',');

            // Create the unique property values that make up the variant
            for (var i = 0; i < variantFieldNames.Length; i++)
            {
                var variantFieldName = variantFieldNames[i].Trim();
                var variantValue     = variantValues[i].Trim();

                var productDefinitionField = _session.Query <ProductDefinitionField>().FirstOrDefault(x => x.Name == variantFieldName &&
                                                                                                      x.ProductDefinition.ProductDefinitionId == product.ProductDefinition.Id);

                if (productDefinitionField == null)
                {
                    Log.Error(
                        $"Could not add product variant for sku '{product.Sku}'.  Product definition field with name '{variantFieldName}' not found.");
                    continue;
                }

                var productProperty = new ProductProperty()
                {
                    ProductDefinitionField = productDefinitionField,
                    Value   = variantValue,
                    Product = variantProduct
                };

                variantProduct.AddProductProperty(productProperty);
            }
        }
        private void AddProductInventory(Product product, string inventoryJson)
        {
            var productDefinitionField = _session.Query <ProductDefinitionField>().FirstOrDefault(x => x.Name == "InventoryOnHand" &&
                                                                                                  x.ProductDefinition.ProductDefinitionId == product.ProductDefinition.Id);
            var inventoryModel = new JavaScriptSerializer().Deserialize <InventoryModel>(inventoryJson);

            var productProperty = new ProductProperty()
            {
                ProductDefinitionField = productDefinitionField,
                Value   = inventoryModel.Inventory.ToString(),
                Product = product
            };

            product.AddProductProperty(productProperty);
        }
        private void AddProductProperties(Product product, ProductViewModel sfProduct)
        {
            if (sfProduct.Item.CustomFields.Count == 0)
            {
                return;
            }

            // All properties are currently imported as ShortText properties
            var dataType = _session.Query <DataType>().FirstOrDefault(x => x.TypeName == "ShortText");

            foreach (var customProperty in sfProduct.Item.CustomFields)
            {
                if (customProperty.Key == "Department")
                {
                    continue;
                }

                var property =
                    product.ProductDefinition.ProductDefinitionFields.FirstOrDefault(x => x.Name == customProperty.Key);

                if (property == null)
                {
                    property = new ProductDefinitionField
                    {
                        DisplayOnSite     = true,
                        Deleted           = false,
                        RenderInEditor    = true,
                        IsVariantProperty = false,
                        SortOrder         = 0,
                        Name         = customProperty.Key,
                        DataType     = dataType,
                        Multilingual = true
                    };
                    product.ProductDefinition.AddProductDefinitionField(property);
                }

                var propertyValue          = GetPropertyValue(customProperty);
                var currentProductProperty = new ProductProperty
                {
                    Value = propertyValue,
                    ProductDefinitionField = property,
                    Product = product
                };

                product.AddProductProperty(currentProductProperty);
            }
        }