Archive for the ‘Tips’ Category

Update website base url

UPDATE core_config_data SET VALUE=’http://www.website.com/’ WHERE path=’web/unsecure/base_url’; UPDATE core_config_data SET VALUE=’http://www.website.com/’ WHERE path=’web/secure/base_url’;

Cms Block Stores

$blockCollection = Mage::getResourceModel(’cms/block_collection’); foreach($blockCollection as $block) { Zend_Debug::dump($block->getResource()->lookupStoreIds($block->getBlockId())); }

Redirecting in observer

$controller = $observer->getEvent()->getControllerAction(); $controller->getResponse()->setRedirect($redirectUrl); $controller->setFlag(”, Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true); $controller->setFlag(”, Mage_Core_Controller_Varien_Action::FLAG_NO_POST_DISPATCH, true);

Get core config data

$erpSettings = Mage::getStoreConfig(’my/path/settings’); $storeId = 15; $erpSettings = Mage::getStoreConfig(’my/path/settings’, $storeId);

Get adminhtml url

echo Mage::helper("adminhtml")->getUrl("/vendorname_modulename/controllername/",array("param1" => $value1)); echo Mage::helper("adminhtml")->getUrl("/vendorname_modulename/controllername/");

Get current website id

$website_id = Mage::app()->getWebsite()->getId();

Get current store id

$store_id = Mage::app()->getStore()->getId();

Get the store id from the store code

$store_id = Mage::app()->getStore($storeCode)->getId(); $store_id = Mage::getModel("core/store")->load($storeCode, "code");

Magento select single record from db

public function getSingleRecord($userId) { return $this->getCollection() ->addFieldToFilter(’user_id’, $userId) ->getFirstItem(); }

Where Magento keeps configuration data

SELECT * FROM magento01.core_config_data WHERE path LIKE ‘modulename%’;