I am using a forced_shipping attribute and the below code in Mage\Shipping\Model\Carrier\Flatrate.php to restrict shipping method for items with the forced_shipping attribute set to Yes.

$items = Mage::getModel('checkout/session')->getQuote()->getAllItems();
$forcedShipping = false;
foreach ( $items as $item ) {
    $_products = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('sku', $item->getSku())->addAttributeToSelect('forced_shipping', 'inner');
    foreach ( $_products as $_product) {
        if ( $_product->getForced_shipping() == 1 ) {
            $forcedShipping = true;
if ( !$forcedShipping ) {
    return false;

While this is working great with flat products disabled, it will fail once I enable them. How do I need to modify my code to make it work with flat products, is it possible at all?

  • 1
    After you have enabled flat catalog you need to do a full reindex to make sure the attribute has been populated in the flat table
    – Smartie
    Sep 15, 2015 at 12:26

1 Answer 1


Turns out the setting Used on Product Page does not include an attribute in the flat table. I had to set Used in Product Listing to Yes to make it work.

Apparently any of these settings will populate the flat table with an attribute:

Use in Layered Navigation, Used in Product Listing, Used for Sorting in Product Listing

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.