Saturday, February 23, 2013

Magento queries list

Quick reference list of Magento queries


Getting store information

Load store object ($identifier can be store id or code):
$store = Mage::getModel('core/store')->load($identifier);
Get (admin) Store Id using store code:
$adminStoreId = Mage::getModel('core/store')->load('admin')->getId();

Filtering by null fields

Get items with a NULL field:
$collection = Mage::getModel('your/model')->getCollection();
$collection->addFieldToFilter('field_code',array('null' => true));
$collection->load();
Get items with non NULL field:
$collection = Mage::getModel('your/model')->getCollection();
$collection->addFieldToFilter('field_code',array('neq' => 'NULL'));
$collection->load();

No comments:

Post a Comment