3 deleted 7 characters in body
source | link
    <frontend>
        <events>
            <catalog_product_collection_load_before>
                <observers>
                    <review>
                        <type>model</type>
                        <class>ssd_test/observer</class>
                        <method>catalogBlockProductCollectionBeforeToHtml<<method>catalogProductCollectionLoadBefore</method>
                    </review>
                </observers>
            </catalog_product_collection_load_before>
        </events>
    </frontend>
    <frontend>
        <events>
            <catalog_product_collection_load_before>
                <observers>
                    <review>
                        <type>model</type>
                        <class>ssd_test/observer</class>
                        <method>catalogBlockProductCollectionBeforeToHtml</method>
                    </review>
                </observers>
            </catalog_product_collection_load_before>
        </events>
    </frontend>
    <frontend>
        <events>
            <catalog_product_collection_load_before>
                <observers>
                    <review>
                        <type>model</type>
                        <class>ssd_test/observer</class>
                        <method>catalogProductCollectionLoadBefore</method>
                    </review>
                </observers>
            </catalog_product_collection_load_before>
        </events>
    </frontend>
2 added 2084 characters in body
source | link

1.Add event observer

Solution 1

This moves out of stock products to the end of the list on page, not all over the pagination

:

1.Add event observer:

3.Set "Display Out of Stock Products" to "Yes" on System->Configuration->Inventory. This logic does

Solution 2

This moves out of stock products to the end of the list within all over the pagination:

config.xml:

    <frontend>
        <events>
            <catalog_product_collection_load_before>
                <observers>
                    <review>
                        <type>model</type>
                        <class>ssd_test/observer</class>
                        <method>catalogBlockProductCollectionBeforeToHtml</method>
                    </review>
                </observers>
            </catalog_product_collection_load_before>
        </events>
    </frontend>

Observer.php:

    public function catalogProductCollectionLoadBefore($observer)
    {
        $toolbar = Mage::getBlockSingleton('catalog/product_list_toolbar');
        if ($toolbar) {
            $products = $observer->getEvent()->getCollection();

            $stockId = Mage_CatalogInventory_Model_Stock::DEFAULT_STOCK_ID;
            $websiteId = Mage::app()->getStore($products->getStoreId())->getWebsiteId();

            $products->getSelect()->joinLeft(
                array('_inv' => $products->getResource()->getTable('cataloginventory/stock_status')),
                "_inv.product_id = e.entity_id and _inv.website_id=$websiteId and _inv.stock_id=$stockId",
                array('stock_status')
            );
            $products->addExpressionAttributeToSelect('in_stock', 'IFNULL(_inv.stock_status,0)', array());

            $products->getSelect()->reset('order');
            $products->getSelect()->order('in_stock DESC');

            if ($toolbar->getCurrentOrder()) {
                $products->addAttributeToSort($toolbar->getCurrentOrder(), $toolbar->getCurrentDirection());
            }
        }

        return $this;
    }

Set "Display Out of Stock Products" to "Yes" on System->Configuration->Inventory.

Above logics do not affect to your catalog sort/pagination functionality, only moves not salable products to the end.

1.Add event observer:

3.Set "Display Out of Stock Products" to "Yes" on System->Configuration->Inventory. This logic does not affect to your catalog sort/pagination functionality, only moves not salable products to the end.

Solution 1

This moves out of stock products to the end of the list on page, not all over the pagination

:

1.Add event observer:

3.Set "Display Out of Stock Products" to "Yes" on System->Configuration->Inventory.

Solution 2

This moves out of stock products to the end of the list within all over the pagination:

config.xml:

    <frontend>
        <events>
            <catalog_product_collection_load_before>
                <observers>
                    <review>
                        <type>model</type>
                        <class>ssd_test/observer</class>
                        <method>catalogBlockProductCollectionBeforeToHtml</method>
                    </review>
                </observers>
            </catalog_product_collection_load_before>
        </events>
    </frontend>

Observer.php:

    public function catalogProductCollectionLoadBefore($observer)
    {
        $toolbar = Mage::getBlockSingleton('catalog/product_list_toolbar');
        if ($toolbar) {
            $products = $observer->getEvent()->getCollection();

            $stockId = Mage_CatalogInventory_Model_Stock::DEFAULT_STOCK_ID;
            $websiteId = Mage::app()->getStore($products->getStoreId())->getWebsiteId();

            $products->getSelect()->joinLeft(
                array('_inv' => $products->getResource()->getTable('cataloginventory/stock_status')),
                "_inv.product_id = e.entity_id and _inv.website_id=$websiteId and _inv.stock_id=$stockId",
                array('stock_status')
            );
            $products->addExpressionAttributeToSelect('in_stock', 'IFNULL(_inv.stock_status,0)', array());

            $products->getSelect()->reset('order');
            $products->getSelect()->order('in_stock DESC');

            if ($toolbar->getCurrentOrder()) {
                $products->addAttributeToSort($toolbar->getCurrentOrder(), $toolbar->getCurrentDirection());
            }
        }

        return $this;
    }

Set "Display Out of Stock Products" to "Yes" on System->Configuration->Inventory.

Above logics do not affect to your catalog sort/pagination functionality, only moves not salable products to the end.

1
source | link

1.Add event observer:

<frontend>
    <events>
        <catalog_block_product_list_collection>
            <observers>
                <ssd_test>
                    <type>model</type>
                    <class>ssd_test/observer</class>
                    <method>catalogBlockProductCollectionBeforeToHtml</method>
                </ssd_test>
            </observers>
        </catalog_block_product_list_collection>
    </events>
</frontend>

2.Observer logic:

public function catalogBlockProductCollectionBeforeToHtml($observer)
{
    /**
     * @var $products Varien_Data_Collection
     */
    $products         = $observer->getEvent()->getCollection();
    $soldOuts         = array();
    if ($products instanceof Varien_Data_Collection) {
        foreach ($products as $product) {
            if (!$product->isSaleable()) {
                $products->removeItemByKey($product->getId());
                $soldOuts[] = $product;
            }
        }
        foreach ($soldOuts as $product) {
            $products->addItem($product);
        }
    }
    return $this;
}

3.Set "Display Out of Stock Products" to "Yes" on System->Configuration->Inventory. This logic does not affect to your catalog sort/pagination functionality, only moves not salable products to the end.