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.

  • Great, worked for me. Think Magento and some themes did not factor configurable product in building the list template – Kpono-Abasi Akpabio Mar 20 '18 at 18:41
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, privacy policy and cookie policy

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