Copied to clipboard

Flag this post as spam?

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


  • Bo Jacobsen 606 posts 2404 karma points
    Jun 17, 2021 @ 12:22
    Bo Jacobsen
    0

    get Price for ProductVariantCollection ProductVariantItem

    Hi.

    How can i get the price on each ProductVariantItem in a ProductVariantCollection?

    I know i can get a IProductSnapshot from a variant by doing VendrApi.Instance.GetProduct(productReference: IPublishedContent.Key.ToString(), productVariantReference: ProductVariantItem.Content.Key.ToString(), languageIsoCode: culture).CalculatePrice();

    But is there a way to get the price with only using the ProductVariantCollection?

    foreach (ProductVariantItem variant in ProductVariantCollection)
    {
        var price = variant.???
    }
    
  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jun 17, 2021 @ 12:28
    Matt Brailsford
    100

    Hey Bo,

    You'll need to use the GetProduct method you mention. The ProductVariantCollection is an Umbraco property editor related model but to get a price from Vendr, it needs converting to a Vendr product snapshot first.

    We might be able to create some extension methods to simplify this, but we don't currently have those so you'll either need to create them or go the long way round using the GetProduct method.

    Matt

  • Bo Jacobsen 606 posts 2404 karma points
    Jun 17, 2021 @ 12:34
    Bo Jacobsen
    1

    For now i made a simple method, thanks :)

    public IEnumerable<T> Method(IPublishedContent content, ProductVariantCollection productVariantCollection, string culture = null)
    {
        // ...
    
        foreach (var productVariant in productVariantCollection)
        {
            var product = VendrApi.Instance.GetProduct(content.Key.ToString(), productVariant.Content.Key.ToString(), languageIsoCode: culture);
            var price = product.CalculatePrice();
        }
    
        // ...
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft