But when I add the Variant to the cart, in my cart > orderlines I only get the name of my variant for example: "red" when really I should show the Product Name + Variant name like: "Baseball red"
Do I have to collect the parent name manually like so?
@{
var productName = product.Name;
if (product.Parent.IsDocumentType("product"))
{
productName = product.Parent.Name + " " + productName;
}
}
Am I doing something wrong? What is the best way to go with this?
If using child node variants, you need to do 1 of 3 things.
1) Pass both the parent product node key + the child variant product node key in a AddProduct method with a signature that accepts a productNodeReference and a productVariantReference
2) Implement a custom IUmbracoProductNameExtractor to extract a products name based on any rules you define.
3) Pass a productName property to the added order line to explicitly set the name when adding your product.
Ultimately, given just the child variant node on it's own, Vendr has no idea whether it is a variant or product node, so you need to tell in some way "this is actually a variant of this product" via one of the mechanisms above.
If I should decide to pass a productName property to the added order line to explicitly set the name when adding the product. Would I pass the value like so:
using (var uow = _unitOfWorkProvider.Create())
{
var store = CurrentPage.GetStore();
var order = _sessionManager.GetOrCreateCurrentOrder(store.Id)
.AsWritable(uow)
.AddProduct(postModel.ProductReference, postModel.ProductVariantReference, postModel.Quantity);
If you want to pass the product name to the orderline, you'll want to pass it as part of the AddProduct call which can accept a dictionary of properties. You need it to be an Order Line property, but the example you have you are setting an Order level property.
And no, there isn't already a productName property that is captured, this is just used as a mechanism to bypass the normal name generation should you wish to.
Problem with child variants
Hi Matt,
I have implemented the simple Child Variants.
But when I add the Variant to the cart, in my cart > orderlines I only get the name of my variant for example: "red" when really I should show the Product Name + Variant name like: "Baseball red"
Do I have to collect the parent name manually like so?
Am I doing something wrong? What is the best way to go with this?
Thanks
Hi Edgar,
If using child node variants, you need to do 1 of 3 things.
1) Pass both the parent product node key + the child variant product node key in a
AddProduct
method with a signature that accepts a productNodeReference and a productVariantReference2) Implement a custom
IUmbracoProductNameExtractor
to extract a products name based on any rules you define.3) Pass a
productName
property to the added order line to explicitly set the name when adding your product.Ultimately, given just the child variant node on it's own, Vendr has no idea whether it is a variant or product node, so you need to tell in some way "this is actually a variant of this product" via one of the mechanisms above.
Matt
Hi Matt,
thanks for your reply.
Which option have you used in the demo store?
If I should decide to pass a productName property to the added order line to explicitly set the name when adding the product. Would I pass the value like so:
Is there allready a property on the order with has the alias "productName"?
Thanks
Hi Edgar,
In the demo store we go the route of the
IUmbracoProductNameExtractor
which you can see here https://github.com/vendrhub/vendr-demo-store/blob/main/src/Vendr.DemoStore/Web/Extractors/CompositeProductNameExtractor.cs and registered here https://github.com/vendrhub/vendr-demo-store/blob/main/src/Vendr.DemoStore/Composing/DemoStoreComposer.cs#L18If you want to pass the product name to the orderline, you'll want to pass it as part of the
AddProduct
call which can accept a dictionary of properties. You need it to be an Order Line property, but the example you have you are setting an Order level property.And no, there isn't already a
productName
property that is captured, this is just used as a mechanism to bypass the normal name generation should you wish to.Hope this helps
Matt
is working on a reply...