Magento get path id or getpathids function to get parent category untill or upto root category
getPathIds ()
Get array categories ids which are part of category path Result array contain id of current category because it is part of the path
Returns:
array
Definition at line 584 of file Category.php.
00585 {
00586 $ids = $this->getData('path_ids');
00587 if (is_null($ids)) {
00588 $ids = explode('/', $this->getPath());
00589 $this->setData('path_ids', $ids);
00590 }
00591 return $ids;
00592 }
Search This Blog
Tuesday, July 12, 2011
magento reference doc or documents or docs
magento reference doc or documents or docs
http://freegento.com/doc/
http://freegento.com/doc/
Friday, July 8, 2011
Magento sql queries or queries or query in magento
getConnection('core_read');
//make connection
$qry = "select name FROM user_data WHERE id=1 LIMIT 1 "; //query
$res = $read->fetchRow($qry); //fetch row
$name = $res['name']; //outputs name
//other form
$qry = "select name FROM user_data WHERE namer LIKE '%a%' ";//query
$res = $read->fetchAll($qry); //get array
//Insert query
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$sql = "INSERT INTO user_data values (?,?)"; //insert query
$write->query($sql, array('name','pass')); //write to database
?>
//make connection
$qry = "select name FROM user_data WHERE id=1 LIMIT 1 "; //query
$res = $read->fetchRow($qry); //fetch row
$name = $res['name']; //outputs name
//other form
$qry = "select name FROM user_data WHERE namer LIKE '%a%' ";//query
$res = $read->fetchAll($qry); //get array
//Insert query
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$sql = "INSERT INTO user_data values (?,?)"; //insert query
$write->query($sql, array('name','pass')); //write to database
?>
Tuesday, July 5, 2011
Magento get root category id or magento getRootCategory or function to get root category id or magento getRootCategory()
Mage::app()->getWebsite(true)->getDefaultStore()->getRootCategoryId()
magento get parent category of or from current category
You can get current category from the following code:
$currentCategory = Mage::registry('current_category');
You can get the parent category from the following code:
/**
* You want the parent category of a sub-category
* Let the sub-category be $subCategory
*/
$parentCategory = Mage::getModel('catalog/category')->load($subCategory->getParentId());
$currentCategory = Mage::registry('current_category');
You can get the parent category from the following code:
/**
* You want the parent category of a sub-category
* Let the sub-category be $subCategory
*/
$parentCategory = Mage::getModel('catalog/category')->load($subCategory->getParentId());
Wednesday, June 1, 2011
Magento - How to run a SQL query against the database
$db = Mage::getResourceSingleton('core/resource')->getConnection('core_write');
$result = $db->query('SELECT 'entity_id' FROM 'catalog_product_entity');
if(!$result) {
return FALSE;
}
$rows = $result->fetch(PDO::FETCH_ASSOC);
if(!$rows) {
return FALSE;
}
print_r($rows);
$result = $db->query('SELECT 'entity_id' FROM 'catalog_product_entity');
if(!$result) {
return FALSE;
}
$rows = $result->fetch(PDO::FETCH_ASSOC);
if(!$rows) {
return FALSE;
}
print_r($rows);
Thursday, May 26, 2011
Magento admin redirect from a form
Class used Mage_Core_Controller_Varien_Action class.
Redirect to url
_redirectUrl($url)
Check url to be used as internal
_isUrlInternal($url)
Redirect to error page
_redirectError($defaultUrl)
Redirect to path
_redirect($path, $arguments=array())
Redirect to success page
_redirectSuccess($defaultUrl)
Identify referer url via all accepted methods (HTTP_REFERER, regular or base64-encoded request param)
_getRefererUrl()
Set referer url for redirect in response
_redirectReferer($defaultUrl=null)
You can use the redirect functions in your controller class.: $url = "http://abc.com";
$this->_redirectUrl($url);
Redirect with path and arguments:-
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl($path, $arguments));
Mage::app()->getFrontController()->getResponse()->setRedirect($url);
Redirect to url
_redirectUrl($url)
Check url to be used as internal
_isUrlInternal($url)
Redirect to error page
_redirectError($defaultUrl)
Redirect to path
_redirect($path, $arguments=array())
Redirect to success page
_redirectSuccess($defaultUrl)
Identify referer url via all accepted methods (HTTP_REFERER, regular or base64-encoded request param)
_getRefererUrl()
Set referer url for redirect in response
_redirectReferer($defaultUrl=null)
You can use the redirect functions in your controller class.: $url = "http://abc.com";
$this->_redirectUrl($url);
Redirect with path and arguments:-
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl($path, $arguments));
Mage::app()->getFrontController()->getResponse()->setRedirect($url);
Subscribe to:
Posts (Atom)