Smile-SA / mongogento

98 stars 48 forks source link

exception 'BadMethodCallException' with message 'Call to a member function addData() #33

Open engrKaka opened 7 years ago

engrKaka commented 7 years ago

Hello all, I facing this issue when I try to load product collection in chunks exception 'BadMethodCallException' with message 'Call to a member function addData() on a non-object (null)' in /app/code/community/Smile/MongoCatalog/Model/Resource/Override/Catalog/Product/Collection.php:173 in _loadAttributes() function. My code is `public function updateIndex() { $productsCollection = Mage::getModel('catalog/product')->getCollection() ->addFieldToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);

$productsCollection->setPageSize(100);

$pages = $productsCollection->getLastPageNumber();
$currentPage = 1;

do {
    $productsCollection->setCurPage($currentPage);
    $productsCollection->load();

    foreach ($productsCollection as $_product) {

        $insertData = array(
            'entity_id' => $_product->getId(),
            'title' => $_product->getName(),
            'image' => $_product->getImage(),
            'url' => $_product->getUrlKey(),
            'price' => $_product->getFinalPrice(),
        );

        $this->_getWriteAdapter()->insertOnDuplicate(
            $this->getTable('atwix_sonar/suggestions'),
            $insertData,
            array('title', 'image', 'url', 'price')
        );
    }

    $currentPage++;
    //clear collection and free memory
    $productsCollection->clear();
} while ($currentPage <= $pages);

}` Note this is just test code from atwix tutorial Do you have any solution for this?