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 09, 2017 @ 16:58
    Tolu Jemilua
    0

    Merchello shared product options with variant

    Any Idea on how to assign shared options whilst creating a variant for a product using code?

    Currently I have this which essentially creates the shared options, but once created I would like to assign certain options to a variant

    if (existingProduct == null)
                                {
                                    merchelloProduct = this.MerchelloServices.ProductService.CreateProductWithKey(product.Name, product.ProductCode, price);
                                    merchelloProduct.Available = product.IsPublished;
    
                                    var colour = string.Empty;
                                    var size = string.Empty;
                                    foreach (var variant in product.ProductVariants)
                                    {
                                        foreach (var option in options)
                                        {
                                            if (variant.Colour != null && variant.Colour.Name != colour && option.Name == "Colour" && !option.Choices.Contains(variant.Colour.Sku))
                                            {
                                                options.First(x => x.Name == "Colour").Choices.Add(new ProductAttribute(variant.Colour.Name, variant.Colour.Sku));
                                                colour = variant.Colour.Name;
                                            }
    
                                            if (variant.Size != null && variant.Size.Name != size && option.Name == "Size" && !option.Choices.Contains(variant.Size.Name))
                                            {
                                                options.First(x => x.Name == "Size").Choices.Add(new ProductAttribute(variant.Size.Name, variant.Size.Name));
                                                size = variant.Size.Name;
                                            }
                                        }
    
                                        var merchelloVariant  = this.MerchelloServices.ProductVariantService.CreateProductVariantWithKey(merchelloProduct,)
                                    }
    
                                    this.MerchelloServices.ProductOptionService.Save(options);
                                }
    

    if anyone could help that would be appriciated

Please Sign in or register to post replies

Write your reply to:

Draft