adampmoss / CreareSEO

A free SEO extension for Magento 1
GNU General Public License v2.0
151 stars 72 forks source link

Making "discontinued" feature work when Flat Tables are enabled #133

Closed EricSeastrand closed 5 years ago

EricSeastrand commented 6 years ago

Fixes #101 : A collection loaded from the flat table won't include the creare_discontinued attribute value or label, so instead, we must call $model->load().

sprankhub commented 6 years ago

Thanks for your pull request!

Loading the whole product / category is not a good idea from a performance point of view. It would be much better to add the required attributes to the flat tables.

EricSeastrand commented 6 years ago

Adding this attribute to the flat tables will require creating an install/upgrade script and incrementing the module's version number. Is that an acceptable solution?

sprankhub commented 6 years ago

I do not think so. AFAIK, you can do this via pure XML or an observer (at least for products). Not sure about categories, would have to check that.

EricSeastrand commented 6 years ago

In the case of product flat tables, the only way I know of is to mark those attributes as one of: is_used_for_promo_rules, used_in_product_listing, used_for_sort_by. This would need to be done in a migration/upgrade script since it's stored in the database.

The product flat indexer checks for those when creating the table.

What was the XML or observer-based method you were referring to?

EricSeastrand commented 6 years ago

The more I think about it, the current product or category might already have been loaded by Magento. I'll see if this is a viable option before going down the rabbit hole that is flat table shenanigans.

sprankhub commented 6 years ago

See https://github.com/OpenMage/magento-mirror/blob/f4b5f152af50e7a1da128b6a1f634658305ae72a/app/code/core/Mage/Catalog/Model/Resource/Product/Flat/Indexer.php#L163-L170

You can add product attributes for the flat indexer via XML as well:

<config>
    <frontend>
        <product>
            <collection>
                <attributes>
                    <your_attribute_code/>
                </attributes>
            </collection>
        </product>
    </frontend>
</config>

And if I see it correctly on a very first view, the category flat indexer Mage_Catalog_Model_Resource_Category_Flat uses every attribute anyway.

Quazz commented 6 years ago

I'm interested in this issue as I'd like to get it work correctly.

However, it seems like the flat table indexer doesn't index Disabled products (and removes products who's status changes to Disabled).

I added the xml config node to make sure it got indexed in the flat tables.

Adding Mage::app()->getStore()->setConfig('catalog/frontend/flat_catalog_product', 0); before the query seems to work fine. (as per https://magento.stackexchange.com/questions/35626/get-disabled-inactive-products-from-flat-catalog-product-strucutre)

sprankhub commented 5 years ago

I just fixed the issue in https://github.com/adampmoss/CreareSEO/commit/f5581944f3d73cdfd21331e6222cd68adf367293.