Copied to clipboard

Flag this post as spam?

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


  • Neil Hodges 338 posts 987 karma points
    Feb 26, 2020 @ 20:50
    Neil Hodges
    0

    Adding selected product variants options to Orderline/checkout area

    Hi

    Sorry to bombard the support section with questions.

    When a user selects their product variants from the products page, we have a series of 4 dropdowns, for instance:

    Bundle = 10
    Paper Type = Textured
    Foil = Gold
    

    How can I show these selected values in the basket?

    Do I add them as bundles? Or am I missing how to access the selected variant option when in the basket?

    Dp they need appending as properties to the OrderLine?

    Id like the admin to see what they have selected and also the confirmation emails to follow suit, as well as the back office to see selected variant options for that particular product.

  • Neil Hodges 338 posts 987 karma points
    Feb 26, 2020 @ 21:26
    Neil Hodges
    0

    Ok, think I've figured it out :)

      VariantPublishedContent variant = TC.GetVariant( 1, Model, "AFA77248-1D5B-4B31-ACE2-6FD1C609B93B", true );
    

    'Model' being the IPublishedContent Product itself.

    I assume I can then loop over the variant combo that's been selected.

  • Neil Hodges 338 posts 987 karma points
    Feb 26, 2020 @ 22:29
    Neil Hodges
    0

    Ok hit another little snag, so in the basket, I can output the variant selected fine,

    However in the:

    macroscripts > tea-commerce > edit-order.cshtml

    macroscripts > tea-commerce > email-template-confirmation.cshtml

    I'm getting:

    The requested service 
    'TeaCommerce.Umbraco.Configuration.Variants.Services.IVariantService`2[[System.Collections.Generic.IEnumerable`1[[Umbraco.Core.Models.IPublishedContent, 
    Umbraco.Core, Version=1.0.7180.24662, Culture=neutral, PublicKeyToken=null]], mscorlib, Version=4.0.0.0, Culture=neutral, 
    PublicKeyToken=b77a5c561934e089],[TeaCommerce.Umbraco.Configuration.Variants.Models.VariantPublishedContent, 
    TeaCommerce.Umbraco.Configuration, Version=3.3.7207.28303, Culture=neutral, PublicKeyToken=null]]' 
    has not been registered. To avoid this exception, either register a component to provide the service, 
    check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.
    

    Seems to be when I call:

    var variant = TC.GetVariant(1, productType, prod1split, true);
    

    Any ideas on how to get the variant to go into the confirmation email and the order in the back office?

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Feb 27, 2020 @ 08:19
    Matt Brailsford
    0

    Hi Neil,

    It might be easier to store the selected variant values in the order lines properties collection. That way you don’t have to keep looking them up. You can add properties as part of the AddOrUpdateOrderline API

    https://docs.teacommerce.net/3.4.0/api/order-line/#addorupdateorderline

    Once stored in the properties collection, it should then be available wherever the order line is available.

  • Neil Hodges 338 posts 987 karma points
    Feb 27, 2020 @ 10:43
    Neil Hodges
    0

    Ah Ok.

    Can I call an external class maybe and pass the IPubishedContent Product to it, let it do it's searching and return a list of the variant in a Dictionary String or something similar?

    Is it just that it's inside the Macro Partial it's cant access the Variant?

    It's just we have a non-triditional setup which has 2 product landing pages for the same product. Hard to explain here, but you view the product, select variants, then go to customize it, that's where the AddOrUpdateOrderline update happens.

    Adding it to the properties at this stage would need a bit of refactoring time which we dont have, but if thats the only way i'll do it that way, was just looking for a quick win on it for now.

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Feb 27, 2020 @ 11:13
    Matt Brailsford
    100

    Hi Neil,

    I think the issue is that the email templates are rendered in a thread where the TC DI container isn't available (ie, it's not a regular web request). I think the simplest option will be to store them on the orderline and read them from there.

    Matt

  • Neil Hodges 338 posts 987 karma points
    Feb 27, 2020 @ 12:32
    Neil Hodges
    1

    HI Matt

    I've gone with something like this, to get it out of the scope of the macrosScript.

    edit-order.cshtml

    if (productType.Any())
    {
      var variantList = TC_GetChosenVariantsHelper.VariantSelctor(productType.FirstOrDefault(), prodVarId);
      if (variantList.Any())
      {
        foreach (var variantCombo in variantList)
        {
          <p>
             @variantCombo.VariantName<br/>
             <strong>
                @variantCombo.VariantDetail
             </strong>
          </p>
        }
      }
    }
    

    Then in the helper did this:

     public static List<SelectedVariants> VariantSelctor(IPublishedContent product, string variantId)
            {
                List<SelectedVariants> variantList = new List<SelectedVariants>();
                var variant = TC.GetVariant(1, product, variantId, true);
                if (variant != null)
                {
                    foreach (var varcombo in variant.Combination)
                    {
                        SelectedVariants v = new SelectedVariants();
                        v.VariantDetail = varcombo.Name;
                        v.VariantName = varcombo.GroupName;
                        variantList.Add(v);
                    }
                }
    
                return variantList;
            }
    

    A little hacky I know, but needed something quick as it's going Live, In the future, I think I'll add them to the properties, but this fixes it short term for me.

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Feb 27, 2020 @ 12:37
    Matt Brailsford
    0

    Haha, nice!

    No judgement here. Sometimes needs must.

    Glad you got something working

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft