Developer forum

Forum » Ecommerce - Standard features » Only show active/available variant options on a product page

Only show active/available variant options on a product page

Hans Ravnsfjall
Hans Ravnsfjall
Reply

Hi

On a productpage, we show variants options. So if a sweater is available in blak or white, and size small, medium, large - we show this using the variants and options loop.

However, if variants have been available earlier, but have been deactivated in the on the product, these variant are also included in the variants / options loop.

This results in outputing variant options in the size and color selector, where there no match when eg. selecting the inactive color og inactive size.

How can we get only available/active variant options in the variants options loop?

/Hans


Replies

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply
Make sure that you have configured which products should be visible:
But I think you need to use the "VariantCombinations" loop instead.
 
Alternatively, you can use @Model.VariantInfo in razor templates with view models, if you use the "Product catalog for ViewModel" app.
 
Best regards,
Morten
 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Thank you for your reply Morten

But the VariantCombinations loop won´t give me the options for colors and sizes as seperated values, or am I wrong?

What I hav done, is that I use the VariantAvailableOptions loop inside the VarianGroups loop, and i have set the settings to only show ative variants, but the VariantAvailableOptions still gives me variants on deactivated variants.

how could this be?

/Hans

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

You can try this...

Go to Settings > Ecommerce > Advanced configuration > General
Enable the following two settings:
- Only show products > That are in stock
- Only show variants > That are in stock
 
Otherwise, you should be able to use the "VariantInfos" loop instead.
 
 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Hi Morten

thanks for your reply. I can´t use the stock setting, as we dont keep stock. So if I check these chekmarks, all variants become unavailable.

Where can I find the loop VariantInfos? I cant find on the product page.

But isn´t it a bug that unavaillable options are shown in the loop

 

@foreach (LoopItem i in GetLoop("VariantGroups")){
foreach(LoopItem u in i.GetLoop("VariantAvailableOptions")){
// this also shows unavailable variant options
}
}
 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply
@foreach (LoopItem variantInfo in GetLoop("VariantInfos")){
   <div>@variantInfo.TemplateTags()</div>
}

If you are using a very old version then that template loop might not be there.

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Hi Morten

The solution is running version 9.12.10

On a product catalogue page where we show the product, this loop is not available.

/Hans

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

Not available or empty?
If you add <div>@TemplateTags()</div> in your product detail template then it will not show "VariantInfos" in the list of available template loops?

The "VariantInfos" template loop works fine for me on 9.12.10

Please paste your product detail template code here (or attach as txt file)?

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Hi

It is not available. If i add @TemplateTags() it does not show up in the available data.

I am using regular product catalogue module - not product catalogue for viewmodel. Could that explain it?

I have attached my productdetails template.

 

/Hans

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

I had to solve it by making an array based on the VariantCombinations loop, where I test if the variant combo is active - and test in my VariantAvailableOptions loop inside the VariantGroups to see if the color / size is in my array.

A very long detour to get the active color and size options.

Not the easiest/fastest way of getting the available size and color for our products. This ought to be easier.

/Hans
 

 
Nicolai Pedersen
Reply

Hi Hans

Yes - you are using the template tags based version of the product catalog. The viewmodel based version has a new approach where we have tried to simplify it as much as possible.

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Ok, thank you Nicolai

I am running Mac, and haven´t really been able to try the viewmodel based templates/features yet.

What is your experince from running mac? Is it "safe", or is it best to wait for Dynamicweb 10

/Hans

 
Nicolai Pedersen
Reply

Viewmodels has nothing to do with mac....? You can use viewmodels just the same as template tags version of the product catalog.

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Yes, i am aware of that - but without templatetags and intellisense, it wil be quite timeconsuming to find datavalues?

/Hans

 
Nicolai Pedersen
Reply

There is no difference in intellisense tags compared to viewmodels. Both will work or not work under the exact same conditions.

You can replace @TemaplateTags() with @Model.ToJson() if you want to see the full data available. Also compared to template tags documentation, the viewmodel documentation is in the API docs and allways up to date - i.e. here: https://doc.dynamicweb.com/api/html/d9c8e164-e6c5-1121-4a9d-c115b563a63d.htm

 

You must be logged in to post in the forum