Skip to main content
added 337 characters in body
Source Link
Marius
  • 198.5k
  • 55
  • 424
  • 833

This line is your problem

$this->getCollection()->load();

You are loading the collection and later you apply a filter in the template.
Once you load the collection all filters and sort orders applied have no effect.
So you should apply the filter before calling load or before iterating through the collection.
In this case you should apply the filter in the block class.

As a general case, the templates should be used only to present data, so all data manipulation should be done in the block classes.

[EDIT]
Make your construct method look like this:

public function __construct()
{
    parent::__construct();
    $collection = Mage::getModel('module/model')->getCollection();
    $customerId = 1;
    $collection->addCustomFilter($customerId);
    $this->setCollection($collection);
}

This line is your problem

$this->getCollection()->load();

You are loading the collection and later you apply a filter in the template.
Once you load the collection all filters and sort orders applied have no effect.
So you should apply the filter before calling load or before iterating through the collection.
In this case you should apply the filter in the block class.

As a general case, the templates should be used only to present data, so all data manipulation should be done in the block classes.

This line is your problem

$this->getCollection()->load();

You are loading the collection and later you apply a filter in the template.
Once you load the collection all filters and sort orders applied have no effect.
So you should apply the filter before calling load or before iterating through the collection.
In this case you should apply the filter in the block class.

As a general case, the templates should be used only to present data, so all data manipulation should be done in the block classes.

[EDIT]
Make your construct method look like this:

public function __construct()
{
    parent::__construct();
    $collection = Mage::getModel('module/model')->getCollection();
    $customerId = 1;
    $collection->addCustomFilter($customerId);
    $this->setCollection($collection);
}
Source Link
Marius
  • 198.5k
  • 55
  • 424
  • 833

This line is your problem

$this->getCollection()->load();

You are loading the collection and later you apply a filter in the template.
Once you load the collection all filters and sort orders applied have no effect.
So you should apply the filter before calling load or before iterating through the collection.
In this case you should apply the filter in the block class.

As a general case, the templates should be used only to present data, so all data manipulation should be done in the block classes.