We have a LOT of sizes in our database. This makes a size filter near impossible unless we narrow down the filter to the possible values found in the category the user is browsing.

Is it possible to return an array or list made from only the sizes that are available in the products of a certain category?


You can get sizes that are available in the products of a certain category by this code:

$categoryId = 1;
$category = Mage::getModel('catalog/category')->load($categoryId);

$collection = $category->getProductCollection();
$collection->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
$collection->addAttributeToFilter('size', array('neq' => null));
$collection->addFieldToFilter('visibility', array(
$collection->addAttributeToFilter('qty', array('gteq' => 1));

$sizeCollection = array();
foreach ($collection as $product) {
    $sizeCollection[] = $product['size'];

echo '<pre>';
  • Won't this load up all the products though? How will this be performance wise? Edit: Nevermind, just noticed you grouped by size. Thank you! – Pat Jun 6 '17 at 13:26
  • Going to try it asap and mark the answer correct. :) – Pat Jun 6 '17 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.