Archive for December 2017

Yet another raw sql example

$resource = Mage::getSingleton(’core/resource’); $readConnection = $resource->getConnection(’core_read’);   $query = ‘SELECT COUNT(id) AS rows FROM table’; $sql = $readConnection->prepare($query); $sql->execute(); $data = $sql->fetch(); printf("Rows: %d\n", $data[’rows’]);

Difference between addFieldToFilter and addAttributeToFilter

addFieldToFilter() is used to filter Non-EAV collections. addAttributeToFilter() is used to filter EAV collections.

Between

gteq – greater than or equal (>=) lteq – less then or equal () lt – less (

Magento Iterate with Pages

$tableDataCollection = Mage::getResourceModel(’modulename/tablename_collection’)->setPageSize(50);   // Set number of pages and current page $pages = $tableDataCollection->getLastPageNumber(); $currentPage = 1;   // Interate do { $tableDataCollection->setCurPage($currentPage); $tableDataCollection->load();   foreach ($tableDataCollection as $tableRow) { echo $tableRow->getId()."\n"; }   $currentPage++;   //Clear collection and free memory $tableDataCollection->clear(); } while ($pages => $currentPage);

Running Magento from command line

Method 1 <?php   require_once dirname(__DIR__) . ‘/../../../../../app/Mage.php’; $app = Mage::app(); Mage::register(’isSecureArea’, true); // your code goes here or <?php   require_once dirname(__DIR__) . ‘/../../../../../app/Mage.php’;   /** * Class My Shell Class */ class My_Shell_Class {   /** * Constructor */ public function __construct() { Mage::app(); Mage::register(’isSecureArea’, true); }   /** * Custom function */ […]