0

I am working with a site and currently the configurable color swatches show every single out of stock associated products' swatch color on the category page, but not on the product info page.

Is this default behaviour for Enterprise? Is there a way to fix this? I can't imagine it being default behaviour since the product info page displays only the in-stock options.

1
  • Great, worked for me. Think Magento and some themes did not factor configurable product in building the list template Mar 20, 2018 at 18:41

1 Answer 1

1

You need to check product Stock & skip out of stocks color to your list.

You can did following code on

yourtheme/template/configurableswatches/catalog/product/list/swatches.phtml

$_product = $this->getProduct(); 
/* get available instock products */
$instockProductsId = array(); 
$usedProductsArray = array();
$skip = false;
if($_product->getTypeId() == "configurable") {
    $usedProducts = $_product->getTypeInstance()->getUsedProducts();
    foreach ($usedProducts  as $child) {
             if ($child->isSalable()) {
                    $instockProductsId[]  = $child->getId();
             }
    }
}

if(count($instockProductsId)>0){
    $skip = true;
        foreach($instockProductsId as $id){
            $color = Mage::getResourceModel('catalog/product')->getAttributeRawValue($id, 'color', $storeId);
            $usedProductsArray[$id] = $color;       
        }
}
$usedProductsArray = array_unique($usedProductsArray);

then add if condition in foreach loop:

foreach ($_attrValues as $_optionValue => $_optionLabel):   
/* To skip out of stock product on list page */   
    if($skip && !in_array($_optionValue,$usedProductsArray)){
        continue;
    }
endforeach;

Your Answer

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

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