1

I want to hide Non-available attributes (i.e. color or size) on catalog page or products listing page. I have tried to get quantity/stock for particular attribute_id and product_id but I did not get it. So let me know how can I do that.

I am using colorselectorplus module for displaying color swatches on my site. See how my catalog page is looking :- http://prntscr.com/du7k13 All the colors attribute are there, available and non-available both. And See how my detail page is looking for same product :- http://prntscr.com/du7kn9. I want to display same like product page in catalog page.

Please Help !

0

I found the solution.

First I got the hint from this https://stackoverflow.com/questions/12996469/attributes-and-inventory-for-child-products-of-configurable

I see the getAvailablePerColor() function in /app/code/local/ModuleMart/Colorsizegridview/Helper/Data.php file , below is the code of this function :-

$colorCode = Mage::getStoreConfig('colorsizegridview/settings/color_attribute');
$totalQtyPerColor = 0;

// Get all products with same color
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($product);
$simple_collection = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
$sameColorProducts = array();
foreach($simple_collection as $simple_prod) {
    if($simple_prod->getData($colorCode) == $colorId) {
        $sameColorProducts[] = $simple_prod;
        $totalQtyPerColor += $simple_prod->getStockItem()->getQty();
    }
}

So I used some code from this function, because it is useful to get particular inventory based on attribute for product. See my code :-

$colorCode = Mage::getStoreConfig('colorsizegridview/settings/color_attribute');
$totalQtyPerColor = 0;
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$simple_collection = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
$sameColorProducts = array();
$proAttrQty = array();
foreach($simple_collection as $simple_prod) {
    if(is_object($simple_prod)){
        $stockObj = $simple_prod->getStockItem();
        if(is_object($stockObj) && $simple_prod->getData($colorCode) == $theId){
            $exactQty = $simple_prod->getStockItem()->getQty();
        }
    }
}

This works for me. Hope this help to you also !

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.