I'm trying to figure out how to show the sizes of simple products in stock on a catalog front-end page. After getting the values I'd like to extend the catalog pages with a nice hover effect showing the available sizes for this specific product. Since this is a work in progress, please do not start about the module structure as this is a proof of concept.

So far I can show the label using the following code:

     $configurable = $_product->getTypeInstance();
     $childProducts = $_product->getUsedProducts($configurable);
     foreach ($childProducts as $child) {
     // You have a $child now
        echo $product->getAttributeText( $attribute->getLabel());

This would print the associated Attribute Label for this configurable product like: Shoe Sizes:

I'm able to display all the associated sizes:

    $attrs  = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);
foreach($attrs as $attr) {
if(0 == strcmp("size", $attr['attribute_code'])) {
    $options    = $attr['values'];
    foreach($options as $option) {
       print "{$option['store_label']}<br />";


This would print all configurable attribute values: 39 40 41 42 43 44 45 46 47 48 49

But I'm struggling to just show the sizes that are in stock. The idea is to only get something like: 42 43 44 Any help would be appreciated.

See example image https://i.stack.imgur.com/DKh0s.jpg

1 Answer 1


I've written a possible solution in the meanwhile, however it's extremely poor written:

//TODO OPTIMIZE horrible code
$sizeslabels = array();
 $j = 0;
if ($_product->isConfigurable()) {
foreach ($_product->getTypeInstance(true)->getUsedProducts ( null, $_product) as $simple) {
     $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($simple)->getQty();

     if($simple->getValue() != "0.0000"){
         $sizeslabels[] = preg_split("/\s+(?=\S*+$)/",$simple->getName());
         $j = $j + 1;


   for ($i = 0; $i < $j; ++$i) {

    foreach($sizeslabels[$i] as $key=>$value){
        if($key == 1){
        echo $value;
        if($i<$j-1) echo ",";



This will output something similar to: XS,S,M,L.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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