i've got a custom attribute "real_stock" Yes/No for simple product.
I would like to filter collection by this attribute and return configurable products with child that has got this attribute.

Vers. Magento 1.9.3.7

To do this i create a module:
config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Bileamara_SpecialCollection>
            <version>0.0.1</version>
        </Bileamara_SpecialCollection>
    </modules>
    <global>
        <blocks>
            <specialcollection>
                <class>Bileamara_SpecialCollection_Block</class>
            </specialcollection>
        </blocks>
        <models>
            <specialcollection>
                <class>Bileamara_SpecialCollection_Model</class>
            </specialcollection>
        </models>
    </global>
</config>

block

<?php
class Bileamara_SpecialCollection_Block_Magazzino extends Mage_Catalog_Block_Product_List
{
    public function getLayer()
    {
        $layer = Mage::registry('current_layer');
        if ($layer) {
            return $layer;
        }
        return Mage::getSingleton('specialcollection/magazzino');
    }
}

model

<?php 
class Bileamara_SpecialCollection_Model_Magazzino extends Mage_Catalog_Model_Layer
{
    public function prepareProductCollection($collection)
    {
        $collection
            ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
            ->addAttributeToFilter('real_stock','1')
            ->addMinimalPrice()
            ->addFinalPrice()
            ->addTaxPercents()
            ->addUrlRewrite($this->getCurrentCategory()->getId());

        Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);

        return $this;
    }
}

but this doesn't show configurable products and layer navigation doesn't work. Any help?

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.