Developer forum

Forum » Swift » Swift bug - Product component slider/grid view

Swift bug - Product component slider/grid view

Marie Louise Veigert
Reply

Hi,

I found a bug on the paragraph item 'Product Component Slider' in the latest Swift (v1.26.3)

When selecting 'selected' to select products, you are not able to select any product. So it will fail. 

I have fixed it myself with adding same functionality check as the paragraph item ''Product component slider/grid view' (both on item and template)

BR
Marie Louise


Replies

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Marie Louise,

 

Could you share more details about the fix itself? What code did you add/replace to get it working?

 

Best Regards,

Nuno Aguiar

 
Marie Louise Veigert
Reply

Hi Nuno,

Of cause.

I wanted to select products for the component slider.
When I selected the 'Selected products' there was not an option to select any products.

So I added the group to the item so I got this options:

 

In the template it looked like this before:

ProductListViewModel relateToViewModel = Model.Item.GetValue<ProductListViewModel>("RelateTo");

 

    //--- PRODUCTS ---

    if (sourceType == "variants" || sourceType == "frequently" || sourceType == "selected" )

    {

        if (relateToViewModel?.Products != null)

        {

            hasVariants = relateToViewModel.Products.Any(p => !string.IsNullOrEmpty(p.VariantId));

            foreach (var fromProduct in relateToViewModel.Products)

            {

                if (hasVariants)

                {

                    if (!string.IsNullOrEmpty(fromProduct.VariantId))

                    {

                        relateFromProductVariantIds.Add($"{fromProduct.Id} {fromProduct.VariantId}");

                    }

                    else

                    {

                        relateFromProductVariantIds.Add($"{fromProduct.Id}");

                    }

                }

                relateFromProductIds.Add($"{fromProduct.Id}");

            }

        }

    }

it gave an error in the frontend.

So I changed to this:
 

    //--- PRODUCTS ---
    if (sourceType == "variants" || sourceType == "frequently")
    {
        if (relateToViewModel?.Products != null)
        {
            hasVariants = relateToViewModel.Products.Any(p => !string.IsNullOrEmpty(p.VariantId));
            foreach (var fromProduct in relateToViewModel.Products)
            {
                if (hasVariants)
                {
                    if (!string.IsNullOrEmpty(fromProduct.VariantId))
                    {
                        relateFromProductVariantIds.Add($"{fromProduct.Id} {fromProduct.VariantId}");
                    }
                    else
                    {
                        relateFromProductVariantIds.Add($"{fromProduct.Id}");
                    }
                }
                relateFromProductIds.Add($"{fromProduct.Id}");
            }
        }
    }
 
   
    //--- SELECTED PRODUCTS ---
    if ((sourceType == "selected") && Model.Item.GetValue<ProductListViewModel>("Products") is ProductListViewModel products)
    {
        hasVariants = products.Products.Any(p => !string.IsNullOrEmpty(p.VariantId));
        foreach (var productSelection in products.Products)
        {
            if (hasVariants)
            {
                if (!string.IsNullOrEmpty(productSelection.VariantId))
                {
                    relateFromProductVariantIds.Add($"{productSelection.Id} {productSelection.VariantId}");
                }
                else
                {
                    relateFromProductVariantIds.Add($"{productSelection.Id}");
                }
            }
            relateFromProductIds.Add($"{productSelection.Id}");
        }
    }
 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Marie Louise,

 

Thanks for sharing. Using DW9 we've been having the same issue, but I can't find them right now, so now I can relate when I come across it again.

 

BR,

Nuno

 

You must be logged in to post in the forum