Copied to clipboard

Flag this post as spam?

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


  • Tolu Jemilua 39 posts 166 karma points
    Aug 14, 2017 @ 16:04
    Tolu Jemilua
    0

    Shared Option Properties

    Does anyone know how to set the include choice on the shared option section using code: Essentially deselecting certain options using code

    Thank you

    enter image description here

  • Steve Edson 16 posts 91 karma points
    Aug 14, 2017 @ 16:17
    Steve Edson
    0

    Have you tried editing the following property?

    product.ProductOptions.FirstOrDefault().Choices.FirstOrDefault().IsDefaultChoice = true;
    

    (where product is a IProduct)

    Steve

  • Tolu Jemilua 39 posts 166 karma points
    Aug 14, 2017 @ 16:29
    Tolu Jemilua
    0

    Hey Steve

    This is what I have modified my code to currently but it had no effect, I figured that the variant is created when the product option is created, the problem is the options have been created and made to be shared via code and populates the product options just fine but I am unable to deselect the colours I don't want variants for for each product and that seems to be controlled by the "Include choice" flag

                    //If doesnt exist create product
                    if (existingProduct == null)
                    {
                        merchelloProduct = this.MerchelloServices.ProductService.CreateProductWithKey(product.ProductName, product.ProductCode, product.PriceExclVat.Value);
                        merchelloProduct.Available = true;
                    }
                    else
                    {
                        merchelloProduct = existingProduct;
                    }
    
                    if (merchelloProduct.Sku == product.ProductCode)
                    {
                        var productOptions = currentOptions.Items.Where(x => x.Name == "Colour").FirstOrDefault();
    
                        merchelloProduct.ProductOptions = new ProductOptionCollection { productOptions };
    
                        merchelloProduct.ProductOptions.Where(x => x.Name == "Colour").FirstOrDefault()
                                        .Choices.Where(x => x.Sku == product.ColourSku).FirstOrDefault().IsDefaultChoice = true;
                    }
    
  • Tolu Jemilua 39 posts 166 karma points
    Aug 14, 2017 @ 16:35
    Tolu Jemilua
    0

    It seems the "IsDefaultChoice" Property controls the Selected property only on the choices list and not the included choice

Please Sign in or register to post replies

Write your reply to:

Draft