1) How do I output the other variants on the variantpage? Variants only gets outputted on the master-product. This is what I use for listing variants:
@foreach (var variant in product.Variants)
{
<div>@variant.VariantSku</div>
}
2) When I try to add the variant to the basket/cart, umbDebugShowTrace tells me: "The product with SKU '1000000' contains variants, and cannot be added the basket. Add a specific variant instead.". So even when I'm on the variantpage I'll have to check if current product is a variant or a master-produkt...? If so, how would I do that?
You can use the product.IsVariant propery, to check if the product you are using is a variant.
When you are sure you have a variant you can use var parent = variant.ParentProduct
and then: parent.Variants.Where(x=> x.Id != variantId.Id) to the other variants.
Listing variants and adding to basket when on a variantpage
Hi,
I'm linking to a variant in this way, which works fine:
Now I've got two problems on the variantpage:
1) How do I output the other variants on the variantpage? Variants only gets outputted on the master-product. This is what I use for listing variants:
@foreach (var variant in product.Variants) { <div>@variant.VariantSku</div> }
2) When I try to add the variant to the basket/cart, umbDebugShowTrace tells me: "The product with SKU '1000000' contains variants, and cannot be added the basket. Add a specific variant instead.".
So even when I'm on the variantpage I'll have to check if current product is a variant or a master-produkt...? If so, how would I do that?
Hey skooter
You can use the
product.IsVariant
propery, to check if the product you are using is a variant.When you are sure you have a variant you can use
var parent = variant.ParentProduct
and then:parent.Variants.Where(x=> x.Id != variantId.Id)
to the other variants.Thanks Nickolaj! So, something like:
Umbraco validation tells me: "The name 'variants' does not exist in the current context" - on the foreach-line.
Seems very right. Maybe a
}
got misplaced causingvariants
to be out of context in the foreach?The code snippet seems to work fine for me
Odd, can't get it to work. But it works with a "normal" if-statement. Will have to do for now :-/
is working on a reply...