Copied to clipboard

Flag this post as spam?

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


  • Kevin Meilander 82 posts 408 karma points c-trib
    Mar 16, 2022 @ 19:42
    Kevin Meilander
    0

    Child Variant Product Name Logic

    I'm having trouble figuring out how the name on an order line / product snapshot gets generated for a products (using the default UmbracoProductAdapter), and I'm wondering if there is anyway I can override this default logic. I'm on Vendr 2.1 on Umbraco 9.

    Currently, when users add a child variant to the cart, the Order Line item name is just showing the product name instead of the product name with the name variant. I'm assuming this name comes from the Product Snapshot name, since the snapshot name is also missing this and i can't seem to figure out how to make it include that.

    I do have my variants setup a little different than like the demo site, in that the main product doesn't have a sku/price/stock - only the child variants do - since this was confusing to the authors. I'm not sure if that matters, but I thought I'd mention that.

    It looks like I could make a new Snapshot object class and product adapter, but I don't really want to have to mimc all of the logic, and so I'm hoping there's some way to just override the name logic. Or I'm hoping there's some other way I can set this up to include the variant name.

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Mar 17, 2022 @ 09:45
    Matt Brailsford
    100

    Hey Kevin,

    Sure, you can implement a custom IUmbracoProductNameExtractor to override the name extracted by the default product adapter.

    public interface IUmbracoProductNameExtractor
    {
        string ExtractProductName(IPublishedContent content, string languageIsoCode);
        string ExtractProductName(IPublishedContent content, IPublishedElement variantContent, string languageIsoCode);
    }
    

    You'll probably actually want to inherit from the default one UmbracoProductNameExtractor and just override the second method (by default the first method just proxies to the second with a null variandeContent param)

    From there you can extract whatever you want to use from both the parent node and the variant item.

    See the docs on replacing dependencies for how to register this https://vendr.net/docs/core/2.1.0/umbraco-v9/key-concepts/dependency-injection/#replacing-dependencies

  • teslanoj 2 posts 72 karma points
    Mar 17, 2022 @ 11:20
    teslanoj
    0

    We got a product structure of up to 3 levels. The product set changes frequently, and product cockpit users modify content of the Base Product without considering the impact it causes to Base Product variants, i.e change product name and leave the old name under the variants etc

    Fortiva Credit Card

Please Sign in or register to post replies

Write your reply to:

Draft