Megento Solutions is a place where you can get answers to you questions about magento. For beginner its a best place to start with.
Wednesday, December 23, 2009
How to show new products on home page?
Go to "CMS - Manage Pages" and select "Home Page" from the list of pages.
Use this code to show products as "New Products" on your home page:
{{block type="catalog/product_new" name="home.catalog.product.new" alias="product_homepage" template="catalog/product/new.phtml"}}
(Note that you must have some new products in your catalogue for anything to show when you do this. In this context new doesn’t mean that you’ve recently added them; only products explicitly marked as new using ‘Set Product as New from Date’ and ‘Set Product as New to Date’ options in the ‘General’ product information page in the admin tool will be shown.)
Sunday, December 13, 2009
Code to get the Categories list in magento.
Below code can be used to get the categories tree in magento
require_once $_SERVER[‘DOCUMENT_ROOT’]."/app/Mage.php";
Mage::app(’1’);
function nodeToArray(Varien_Data_Tree_Node $node)
{
$result = array();
$result[’category_id’] = $node->getId();
$result[’parent_id’] = $node->getParentId();
$result[’name’] = $node->getName();
$result[’is_active’] = $node->getIsActive();
$result[’position’] = $node->getPosition();
$result[’level’] = $node->getLevel();
$result[’children’] = array();
foreach ($node->getChildren() as $child) {
$result[’children’][] = nodeToArray($child);
}
return $result;
}
function load_tree() {
$tree = Mage::getResourceSingleton(’catalog/category_tree’)
->load();
$store = 1;
$parentId = 1;
$tree = Mage::getResourceSingleton(’catalog/category_tree’)
->load();
$root = $tree->getNodeById($parentId);
if($root && $root->getId() == 1) {
$root->setName(Mage::helper(’catalog’)->__(’Root’));
}
$collection = Mage::getModel(’catalog/category’)->getCollection()
->setStoreId($store)
->addAttributeToSelect(’name’)
->addAttributeToSelect(’is_active’);
$tree->addCollectionData($collection, true);
return nodeToArray($root);
}
function print_tree($tree,$level) {
$level ++;
foreach($tree as $item) {
echo str_repeat(" ", $level).$item[’name’]."<br>";
print_tree($item[’children’],$level);
}
}
$tree = load_tree();
print_tree($tree[’children’],0);