Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top