Developer forum

Forum » Development » RelatedProductList loop vanishes

RelatedProductList loop vanishes

Morten Fink Eriksen
Reply

I have created a relatedproductlistprovider and it seems to work fine when there is something in the productcollection, but if the productcollection is empty the loop vanishes from the available tags for my productpage.

 

Problem is i am using the loop to show elements on the page which should only be shown if something is in the loop, but if the loop doesn't exist on the page, then the content gets shown on the page where it shouldn't because the tags no longer are valid on the page.

 

Is there some way to ensure the tag is available on the page even though it might be empty?

 


Replies

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi Morten,

 

Can you post the code for the provider? Normally, an empty loop should should show up in your code (so you can use the EmptyLoop tag) so maybe there's something wrong in your code?

Imar
 

 
Mikkel Høst
Reply

You just have to use

template.GetLoop("LoopName"); 
Even when there are no items in your loop
 

 

 

 
Morten Fink Eriksen
Reply
[RelatedProductList("RelatedProductAccesoryPackages")]
    public class RelatedProductAccessoryPackages : RelatedProductListProvider
    {
        public override Dynamicweb.eCommerce.Products.ProductCollection GetCollection(RelatedProductListProviderEventArgs eventArgs)
        {
            if (eventArgs.Product == null) return null;

            StringBuilder sql = new StringBuilder();

            sql.Append("SELECT * FROM EcomProducts ep ");         
            sql.Append("WHERE ProductID IN ( ");
            sql.Append("SELECT * FROM fnCSVToTable(convert(varchar(8000),ISNULL((SELECT DISTINCT customproducttilvalgspakke FROM EcomProducts WHERE ProductID = '{0}'),-1))) ");
            sql.Append(") AND ProductVariantID = '' ");

            return Product.GetProductBySql(string.Format(sql.ToString(), eventArgs.Product.ID));
        }        
    }

 

 
Morten Fink Eriksen
Reply

If something was wrong with my code, shouldn't it fail on the page?

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

>> If something was wrong with my code, shouldn't it fail on the page?

 

Not everything that's wrong results in an error.

 

In which case do you get the empty loop? When args.product is null? Or from the SQL statement? In the former case, have you tried returning new ProductCollection() instead of null? (Just a guess though).

 

Imar

 
Morten Fink Eriksen
Reply

Yes tried that already.. problem is i dont get the emptyloop.. the tag is no longer recognized on the page, so i get this in the case that nothing is in the result..

  <!--@LoopStart(RelatedProductAccesoryPackages)-->                
                    <!--@HeaderStart-->
                    <div class="tilvalg row left">
                        <h4>Tilvalg</h4>
                    <!--@HeaderEnd-->
                        <div class="left crosshatch"><span class="left">Abus Hill Bill</span><span class="price left"><!--@Ecom:Product.Price.PriceWithVATFormatted--></span><img src="/Files/Templates/Designs/Fricykler2012/images/icons/info.png" class="left" data-modalid="tilvalgPROD1770" /><input type="button" data-produktid="PROD1770" class="right cancel" value="Tilføj" /></div>                 
                        <div class="modal" id="tilvalgPROD1770">
                            <span class="modal-close"></span>
                            <div>
                                Rigtig smart cykelhjelm fra Abus i flot design. Hjelmen er en suveræn stærk cykelhjelm med 19 store luftkanaler og Abus Safety Tech-teknologi, der fordeler trykket over et større område, hvis uheldet er ude.  
                            </div>
                        </div>
                    <!--@FooterStart-->
                    </div>
                    <!--@FooterEnd-->
                <!--@LoopEnd(RelatedProductAccesoryPackages)-->       
 
Mikkel Høst
Reply

Hi Morten.

If you can't get it to work you can make a ProductTemplateExtender, use TagExists and then template.GetLoop();

This way you are sure that the loop is recognized in all cases. 

 

 
Morten Bengtson
Reply

It looks like it might be a bug in DW :/

 

GetLoop is called by Dynamicweb when rendering the list of products, but not when the list is empty :/
As a workaround you might be able to use If Defined in the template...

<!--@If Defined(LoopStart(RelatedProductAccesoryPackages))-->
	your stuff here, when loop is available
<!--@EndIf(LoopStart(RelatedProductAccesoryPackages))-->

However, if Dynamicweb decides to fix the bug, this will no longer work as expected.

 
Morten Fink Eriksen
Reply
 
Morten Fink Eriksen
Reply
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Ah, I see. I think this is a bug where Dynamicweb doesn't correctly create the loop when the collection is empty.  I can reproduce this on my machine as well.

 

I would report it so they can fix it.

 

Cheers,

 

Imar

 
Morten Fink Eriksen
Reply
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

FYI, here's the code from Dynamicweb that renders the related products:

 

If template.LoopExists(loopName) Then
	Dim products As ProductCollection = RelatedProductListManager.GetCollection(relatedParams, loopName)

	If products Is Nothing OrElse products.Count = 0 Then Continue For

	RenderProducts(products, template, loopName, 1, False)
End If

The problem is in the line that checks for nothing or an empty collection. Seems to be done as an optimization. RenderProducts is the method that creates the loop and since this is never called, no empty loop ever gets created.

 

 

dvsdvsdvs

Cheers,

 

Imar

 
Morten Fink Eriksen
Reply

That essentially makes relatedproductlist provider useless in my opinion, because then i would have to insure some other way of showing/hiding the the results
 

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

As a very, very ugly workaround you could new up a Product instance, set some field to some know value (e.g. ID to -1) and then in your template test for that value and not show the product if you encounter it. That way, your collection is never empty and the loop gets created successfully.

 

Very stupid workaround, but it would work for now.... ;-)

 

Imar

 

 
Morten Fink Eriksen
Reply

Went with Mikkels productextender idea... very ugly to, but it works :)

 
Merethe Nielsen
Reply

Hi Morten

I have been told from our developer that it´s by design, and if you want it changed, then it´s a feature request.
He referred to http://developer.dynamicweb-cms.com/documentation/for-developers/ecommerce/extensibility/providers/related-product-list-providers.aspx

Kind regards,
Merethe
 

 
Morten Bengtson
Reply

Another bug "by design" ;-)

 
Morten Fink Eriksen
Reply

Practically makes the related provider useless when needed to show content based on if something is in the collection or not..

 
Mikkel Høst
Reply

 

I think a feature request here is a good idea. It's already pretty hard to figure out when you can ask if defined on a loop or tag, when loops are available and so on. In my book loops should ALLWAYS be available, so our dear frontenders can make markup based on items in the loop; even when there are none.

 

 
Morten Fink Eriksen
Reply

Second that request.. just seems rational...

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi all,

The documentation clearly states that the loop is not available when the collection is null or contains 0 products.
This means that we don't(!) see this as a bug. Besides you can use If LoopDefined--which has been in the product since 8.1.1.5--to check for the existance of the loop. I would recommend you use this instead!


- Jeppe
 

 
Morten Fink Eriksen
Reply

Didn't see that statement anywhere yesterday when i reported the bug, but i will try and use "if loopdefined" from now on..

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Indeed, and neither did Google: http://webcache.googleusercontent.com/search?q=cache:an0umalUZ5IJ:developer.dynamicweb-cms.com/documentation/for-developers/ecommerce/extensibility/providers/related-product-list-providers.aspx+&cd=1&hl=en&ct=clnk

The original documentation said that the "related product list will contain all of the template tags the default product loop does" which apparently isn't true. It does not contain the EmptyLoop for example, as the entire loop is not processed.

If this is "by design", I'd say it's a buggy design which to me comes down to the same thing....

Imar

 
Mikkel Høst
Reply
Ohh SNAP!
 
Morten Bengtson
Reply

Hi Jeppe,

 

Nice to know about the If LoopDefined... where is that mentioned in the documentation? I couldn't find it in the template documentation at http://templates.dynamicweb-cms.com/

 

Has it been mentioned anywhere at all besides this thread? How are we supposed to know about these new features?

 

BTW... Just adding some text in the documentation stating that stuff don't work as expected is a nice trick. That way you can avoid fixing bugs(!) and just tell anyone that it is "by design" (for no apparent reason). Good luck with that approach.

 

/Morten

 

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi all,

 

By referring to the documentation, I was trying to communicate that our assessment of the issue was that it was not a bug. While it's true that the documentation was changed by me last Thursday to reflect that position, I never mentioned anything about when this was added nor was it my intent to imply that this had always been part of the documentation. But in retrospect I can see how my statement could be misinterpreted, which a lot if you did. I apologize for the confusion!

 

Now to the matter at hand. We viewed the issue as not being a bug due in part to If LoopDefined but we may have to revise that assessment. We're going to have an internal meeting later today (Monday) to decide whether to actually categorize it as a bug.

 

I mention LoopDefined and Morten brings up a point with regard to documentation. Of course the documentation should be there. If it's not at the moment then we will fix that as soon as possible.

 

I hope this helps to clarify my previous post and our stand on this issue. I will be back later today--after the meeting--with an update.

 

- Jeppe
 

 
Morten Fink Eriksen
Reply

The fact of the matter is that the documentation is lacking and is not being keept up date which is a very serious issue, causing us developers to use a lot of time trying to create workarounds and hacks in order to implement features which might already be implemented, but that we don't know of.

 
Jacob Bertelsen
Reply

The frontenders I know who work in DW, including myself, have been asking for more documentation, for quite some time.

I can only agree, that more focus on documentation would be nice.

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Here's the promised update.

We have created a bug item for this issue. Bug number is 9947.

 
Kristian Knudsen
Reply
This post has been marked as an answer
The bug is now fixed and part of 8.1.2.2 which is available from the Downloads section.
Votes for this answer: 1
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Excellent. Quick service!

 

Imar

 

You must be logged in to post in the forum