Developer forum

Forum » Swift » Swift 2 - Related product list variants

Swift 2 - Related product list variants

Alex Guo
Reply

Hi everyone,

I'm having trouble with the RelatedProductsList.cshtml in Swift 2

When selecting variants, it only shows the main product and not the variants.
All the settings seem to be correct

Things I checked:

  • The products have variants
  • The products per page is set to 8
  • I've set the relatedproductlist to variants
  • Build the product index

DW Care suggested to changing the template:

​@if (sourceType == "variants")
{
​<input type="hidden" name="ProductID" value="@productIds">
​<input type="hidden" name="isVariant" value="true">
} 

This does not work for me, does anybody know how to fix this?

 


Replies

 
Karsten Thuen Dynamicweb Employee
Karsten Thuen
Reply
This post has been marked as an answer

Hi Alex

We have recently fixed this on bug #24990
To do the fix by yourself, you need to specificly use the ProductID when requesting variants, not the ProductKey, as we do for the rest of the requests. 

Update RelatedProductsList.cshtml wirh:
 

        @if (sourceType == "variants")
        {
            string masterProductId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form["MasterProductID"]) ? Dynamicweb.Context.Current.Request.Form["MasterProductID"].ToString() : string.Empty;
            <input type="hidden" name="MasterProductID" value="@masterProductId">
            <input type="hidden" name="isVariant" value="true">
        }


 

Update Swift-v2_RelatedProductsList.cshtml with:

@if (sourceType == "variants")
            {
                <input type="hidden" name="MasterProductID" value="@productIds">
                <input type="hidden" name="isVariant" value="true">
            }

Update the index by adding a new parameter:




Best regards
Karsten Thuen

Votes for this answer: 1
 
Alex Guo
Reply

Hi,

I changed the templates and variants indeed show up like here below

 

But then when I navigate to a product without variants, it doesn't show a table at all


Do you know what causes this and a possible fix?
Thanks in advance!

 

 

----

Edit: I fixed it by adding an if else and checking if the product had variants.
If it did not I passed the master product

 

You must be logged in to post in the forum