Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Edgar Rasquin 326 posts 925 karma points
    Apr 19, 2021 @ 10:16
    Edgar Rasquin
    0

    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?

        @{
        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?

    Thanks

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Apr 19, 2021 @ 10:43
    Matt Brailsford
    0

    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 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.

    Matt

  • Edgar Rasquin 326 posts 925 karma points
    Apr 21, 2021 @ 09:32
    Edgar Rasquin
    0

    Hi Matt,

    thanks for your reply.

    1. Which option have you used in the demo store?

    2. 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);
      
      
      
      order.SetProperty("productName", postModel.ProductName );
      
      
      _orderService.SaveOrder(order);
      
      
      uow.Complete();
      
      }

      Is there allready a property on the order with has the alias "productName"?

    Thanks

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Apr 21, 2021 @ 09:47
    Matt Brailsford
    0

    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#L18

    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.

    Hope this helps

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft