You should not need to alter any code at all and can add any number of properties to you product you want by adding them to the document type you have associated with your product.
From the front end you access the properties in the same way you do with a normal Umbraco page.
var brief = product.GetPropertyValue<IHtmlString>("brief");
Actually, I'm writing a method to create a product and try to add brief and description into new created product automatically. So I need a short code to do that.
Does "product" in your line of code has data type of "ProductDisplay" or "IProduct"?
// we need to remove the detached content to generate the product to begin with due to db foreign keys
var detachedContents = product.DetachedContents.ToArray();
product.DetachedContents = Enumerable.Empty<ProductVariantDetachedContentDisplay>();
// First create the product record and save it
var merchProduct = _productService.CreateProduct(product.Name, product.Sku, product.Price);
merchProduct = product.ToProduct(merchProduct);
// Add description to product
var detachedContentType = detachedContents.FirstOrDefault();
ProductVariantDetachedContent detachedContent = new ProductVariantDetachedContent(
merchProduct.ProductVariantKey,
detachedContentType,
"en-US",
new DetachedDataValuesCollection(
new[]
{
new KeyValuePair<string, string>("description", offerDescription),
new KeyValuePair<string, string>("brief", ""),
new KeyValuePair<string, string>("image", "")
}))
{
CanBeRendered = true
};
merchProduct.DetachedContents.Add(detachedContent);
The code generate an error:
How can I convert "ProductVarianDetachedContentDisplay" to "IDetachedContentType" to be used to get "detachedContentType"?
How to add brief and description to a product?
Hello,
I want to add brief and description to a product (see image) from code behind.
I have looked into ProductApiController.cs under Merchello.Web and see some posible function to help me to do that:
But still I don't know how to modify the code to help me to insert a brief and description to a particular product by ID. Please help me with this.
You should not need to alter any code at all and can add any number of properties to you product you want by adding them to the document type you have associated with your product.
From the front end you access the properties in the same way you do with a normal Umbraco page.
Actually, I'm writing a method to create a product and try to add brief and description into new created product automatically. So I need a short code to do that.
Does "product" in your line of code has data type of "ProductDisplay" or "IProduct"?
As long as you have the document type setup in Umbraco it should be pretty straight forward.
Checkout how we do it in the FastTrack installer: https://github.com/Merchello/Merchello/blob/merchello-dev/src/Merchello.FastTrack/Install/FastTrackDataInstaller.cs#L525
I got stuck at this code block:
The code generate an error:
How can I convert "ProductVarianDetachedContentDisplay" to "IDetachedContentType" to be used to get "detachedContentType"?
is working on a reply...