interchange / Dancer-Plugin-Interchange6

Dancer Plugin for Interchange6 shop machine
4 stars 1 forks source link

"products" should be reset after hook #26

Closed murwiz closed 9 years ago

murwiz commented 10 years ago

While exploring the "before_navigation_display" hook, I did this:

    debug('there are ' . $context->{count});
    my $p = $context->{products}->first;
    my @skus;
    while ($p) {
        push @skus, $p->sku;
        $p = $context->{products}->next;
    }
    debug('products list ' . join ',', @skus);

I.e., I "walked" the products iterator but did not reset it. As a result, the navigation page did not display any products.

SysPete commented 10 years ago

I have use cases where I intentionally mess with products in this hook so a forced reset means I would have to create a new token which is ugly. Either way we need to document this better so my proposal is to add note to docs that if iterators are used on any tokens that contain resulsets inside hooks then it is the job of the application developer to reset the resultset back into the state they want it to be in for the template. So in other words if you mess with $token->{products} in hooks then you should make sure you do $token->{products}->reset at the end of the hook.

racke commented 10 years ago

Actually I will change the behaviour of Template::Flute to always reset iterators for lists - otherwise you can't have multiple lists using the same iterator.

SysPete commented 9 years ago

This should be fixed by racke/Template-Flute@59d849e6c08428bc1f1618458ba84d2b2c606174 so am closing this issue for now.