When adding the product attribute, set used_in_product_listing
, used_for_sort_by
and filterable
to true
.
You can do that with the following update script:
$installer = Mage::getResourceModel('catalog/setup', 'catalog_setup');
$installer->startSetup();
$installer->updateAttribute('catalog_product', 'product_type', 'used_in_product_listing', 1);
$installer->updateAttribute('catalog_product', 'product_type', 'used_for_sort_by', 1);
$installer->updateAttribute('catalog_product', 'product_type', 'is_filterable', 1);
$installer->endSetup();
Thats all, if if you are NOT using the flat catalog.
If you enable the flat catalog product feature, then you need to ensure that your custom source model implements the methods getFlatColums()
, getFlatIndexes()
and getFlatUpdateSelect()
.
If they are missing, your attribute won't be included in the generated flat tables, even if used_in_product_listing
is enabled.
Have a look at the class Mage_Eav_Model_Entity_Attribute_Source_Boolean
for an example. You can probably copy over the methods with minimal adjustments into your custom source model from there. Otherwise, please ask a new question.
Without actually running your code, the reasons for this can be difficult to find.
This is not a solution for the actual issue, but a description on how to debug this type of issue. I hope it helps you towards solving the issue.
I hope it also shows to others how important it is to use breakpoints with a debugger to solve a lot of magento 'why the f**ck is this not working' issues.
Are you using a debugger? This type of issue is easy to solve if you use a debugger, and step through the code, and check all the variables, values etc. Without this you are really just taking pot shots in the dark.
btw, I use netbeans with xdebug. (just in case you need a solution for that ;) )
Now, that all said, this is how I would start with the debug of this.
In list.phtml the toolbar is fetched via the code <?php echo $this->getToolbarHtml() ?>
, thus I would start by whacking a breakpoint on that line, and then step into the routine to find why...
ok, so stepping in, I find this code:
/**
* Retrieve list toolbar HTML
*
* @return string
*/
public function getToolbarHtml()
{
return $this->getChildHtml('toolbar');
}
thus, is the child block attached?
yes it is, so that is not the issue.
Lets see what template is used for this block.
Using the debugger, I can expand the toolbar child block, and view all its properties/values etc. The template is:
So, lets go do a break point in that file, and see code flow from there...
The first line of code in that template is <?php if($this->getCollection()->getSize()): ?>
Using the debugger, I can step over this line, and confirm it evaluates to true, if not ? why not....
And here my example ends, as the line in the tolbar could be your issue....
I hope this example helps, and show you how important it is to use a real debugger when coding with magento (or any application for that matter) :)
Using breakpoints, and stepping through the code, and actually have the ability to view all the classes/objects/values etc during a run, makes it pretty easy to solve this type of issue.
Have fun :)
Best Answer
Give this a try and see if it fits:
Passing the second parameter as an array of arrays will concatenate the conditions using
OR