Magento default settings
In config.xml <?xml version="1.0"?> <config> <default> <modulename> <parametergroup> <param>value</param> </parametergroup> </modulename> </default> </config>
In config.xml <?xml version="1.0"?> <config> <default> <modulename> <parametergroup> <param>value</param> </parametergroup> </modulename> </default> </config>
$tableDataCollection = Mage::getResourceModel(’modulename/tablename_collection’)->setPageSize(50); $tableDataCollection->getSelect() ->join(array(’alias’ => Mage::getSingleton(’core/resource’)->getTableName(’modulename/tablename’)), ‘main_table.id=alias.id’, ‘*’) ->where(’alias.condition = ?’, true);
Mage::getSingleton(’core/resource’)->getTableName(’tablename’)
$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’]);
addFieldToFilter() is used to filter Non-EAV collections. addAttributeToFilter() is used to filter EAV collections.
gteq – greater than or equal (>=) lteq – less then or equal () lt – less (
$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);
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 */ […]
<?php protected function _addColumnFilterToCollection($column) { if ($column->getId() == ‘name’) { $this->getCollection()->addFieldToFilter($column->getId(), array(’like’ => $column->getFilter()->getValue() . ‘%’)); … $this->getCollection()->addFieldToFilter($column->geId(), $column->getFilter()->getCondition()); … $this->getCollection()->addFieldToFilter(’name’, array(’like’ => ‘%’ . $name . ‘%’)); else { parent::_addColumnFilterToCollection($column); } return $this; }
Step 1: Mage::dispatchEvent(’my_event’); Step 2: link method MyEvent to event “my_event” in your module’s config.xml file Observer.php public function MyEvent(Varien_Event_Observer $observer) { Mage::getSingleton(’customer/session’)->setData(’my_event’, ‘results’); } } Step 3: $result = Mage::getSingleton(’customer/session’)->getData(’my_event’));