In Umbraco I have created a Document Type called "Shared Option Image" which has an image picker.
In Merchello I have set "Product Option Content Types" to include "Shared Option Image".
I have created a shared option e.g. colour (just an example), and assigned images yellow.jpg, green.jpg and blue.jpg.
I have created a product, assigned it some shared options and can see the variants.
In code, how do I access the "Shared Option Image" content type data of the option for a product. I have:
var merchello = new MerchelloHelper();
var productQuery = merchello.Query.Product;
var product = productQuery.GetByKey(productKey);
var productOption = product.ProductOptions.FirstOrDefault();
You're getting hung up on an API that I'm slowly trying to obsolete - productQuery is returning ProductDisplay and you want IProductContent.
Try:
var product = productQuery.TypedProductContent(productKey);
var productOption = product.ProductOptions.FirstOrDefault();
foreach(var choice in productOption.Choices)
{
var image = choice.GetPropertyValue("image");
}
FYI - We're working on cleaning these up and making that portion of the API much cleaner.
Thanks Rusty, however your example may not be correct?
This line won't compile
var image = choice.GetPropertyValue("image");
'ProductAttributeDisplay' does not contain a definition for 'GetPropertyValue'
Your way is better than mine if we can get it working - I just got this far to get the image ID.
var product = product.AsProductContent();
var option = product.ProductOptions.FirstOrDefault();
foreach (var choice in option.Choices)
{
foreach (var prop in choice.Properties)
{
if (prop.PropertyTypeAlias.Equals("ImageFieldName"))
{
var imageId = prop.Value;
// get the image URL
// TODO:
}
}
}
As a side question ,which part of my original example are you trying to make obsolete? The whole MerchelloHelper Query or just the GetByKey method?
I apologize, your correct - the ProductOption collection is another place where we could not make changes immediately due to too many breaking changes.
// use the new "Options" collection
var option = product.Options.FirstOrDefault();
Also, we're going to hopefully move the .AsProductContent() extension internal in V3 as it can circumvent the caching ... so try to stick with the Query.Product.TypeProductContent(productKey)
I am working on something very similar, I have added images with some JS and hidden the dropdown lists to allow the user to click on an image to select size and colour.
This all works perfectly however I can only get it to work on 1 product at a time. My site is based on 3 products and they all have similar product choices size and colour.
If i build the project the first product i click on after the build (locally) will show the image selection but the other 2 products wont.
I need all 3 to work but cant understand why only 1 will work at a time.
Get ProductOption ContentType Umbraco data in code
In Umbraco I have created a Document Type called "Shared Option Image" which has an image picker.
In Merchello I have set "Product Option Content Types" to include "Shared Option Image".
I have created a shared option e.g. colour (just an example), and assigned images yellow.jpg, green.jpg and blue.jpg.
I have created a product, assigned it some shared options and can see the variants.
In code, how do I access the "Shared Option Image" content type data of the option for a product. I have:
Now I'm stuck. Any help appreciated.
Hey Kevin,
You're getting hung up on an API that I'm slowly trying to obsolete - productQuery is returning
ProductDisplay
and you wantIProductContent
.Try:
FYI - We're working on cleaning these up and making that portion of the API much cleaner.
Thanks Rusty, however your example may not be correct?
This line won't compile
'ProductAttributeDisplay' does not contain a definition for 'GetPropertyValue'
Your way is better than mine if we can get it working - I just got this far to get the image ID.
As a side question ,which part of my original example are you trying to make obsolete? The whole MerchelloHelper Query or just the GetByKey method?
Thanks again.
I apologize, your correct - the ProductOption collection is another place where we could not make changes immediately due to too many breaking changes.
Also, we're going to hopefully move the .AsProductContent() extension internal in V3 as it can circumvent the caching ... so try to stick with the
Query.Product.TypeProductContent(productKey)
That has sorted it - thank you.
Hi All,
I am working on something very similar, I have added images with some JS and hidden the dropdown lists to allow the user to click on an image to select size and colour.
This all works perfectly however I can only get it to work on 1 product at a time. My site is based on 3 products and they all have similar product choices size and colour.
If i build the project the first product i click on after the build (locally) will show the image selection but the other 2 products wont.
I need all 3 to work but cant understand why only 1 will work at a time.
Any ideas?
Thanks
David
is working on a reply...