Variants and attributes
Is there any example code or documentation for the product attributes? We need to create custom product templates for different product types and this includes controlling/customising how we present and work with the variants. I've bumbled through some code myself today but it would be handy to get some real examples direct from Telerik for how to work with the attributes from code.
thanks
Hi,
We still don't have code samples for most of the ECommerce parts, as it is a relatively new addition to Sitefinity and is being developed and changed with each release. However, you can share exactly what difficulties you are experiencing with the ECommerce API (the attributes in particular) and I will assist you in solving the problem.
Kind regards,The current scenario is as follows:
Hello,
Here's a sample code that gets a single product, then gets its variations for a specific attribute ("size") and for each variation gets the its relevant value. You can then add the values to a collection and bind it to the desired control. The same can be done for all the other variations.
CatalogManager mng = CatalogManager.GetManager();
var product = mng
.GetProducts()
.Where(p => p.Title ==
"Test"
)
.Single();
var variations2 = mng
.GetProductVariations(product.Id)
.Where(v => v
.ProductVariationDetail[0]
.ProductAttributeParent
.Name ==
"size"
);
foreach
(var item
in
variations2)
var val = item.ProductVariationDetail[0].ProductAttributeValueParent.Title;
Hi, thanks for the suggestion, I've just got around to trying it;
CatalogManager catMan = CatalogManager.GetManager(); var singleOptions = catMan.GetProductVariations(ProductItem.Id).Where(v => v.ProductVariationDetail[0].ProductAttributeParent.Name == "single-box"); But this gives me the following error:
Hi,
I apologize, I skipped a part of the code when I pasted it. You should call .ToList() for the IQueryable collection, before filtering, as Open Access currently does not support nested Where clauses, here's the whole correct code:
CatalogManager mng = CatalogManager.GetManager();
var product = mng
.GetProducts()
.Where(p => p.Title ==
"Test"
)
.Single();
var variations2 = mng
.GetProductVariations(product.Id)
.ToList()
.Where(v => v
.ProductVariationDetail[0]
.ProductAttributeParent
.Name ==
"size"
);
foreach
(var item
in
variations2)
var val = item.ProductVariationDetail[0].ProductAttributeValueParent.Title;
OK, I've got this pulling the variations out fine,
Hi,
The product variations in the Backend are ordered by their LastModified property, as far as I can see from my project. I cannot move/reorder them manually. Are you sure you can do that? If so, can you send me a video of that behavior so I can reproduce it locally? Thanks in advance.
Regards,Hi,
Sorry my last post was a bit misleading. The sorting is done in the attributes section, not the product section. I'll try to get a video together later, but for the now the re-ordering is done by:
Ecommerce > Attributes
Hello,
I understand now. If you want to sort the attributes, then you will have to sort the collection that consists of attribute items values (which is actually the second collection that you are going to create). This means that you need to sort the final collection that you will create. You can do something like that:
List<ProductAttributeValue> list =
new
List<ProductAttributeValue>();
foreach
(var item
in
variations2)
var val = item.ProductVariationDetail[0].ProductAttributeValueParent;
list.Add(val);
list.OrderBy(i => i.Ordinal);