Wednesday, 3 July 2013

Magento New Products Block For Home Page


To add new products to a CMS Home page use the block code
{{block type="catalog/product_new" name="home.catalog.product.new" alias="product_homepage" template="catalog/product/new.phtml"}}

Add Featured Products to Home Page


{{block type="catalog/product_list" category_id="8" template="catalog/product/list.phtml"}}

Magento: Get and set variables in session

This code that will set / add your custom data into session.
Mage::getSingleton('core/session')->setMyCustomData('demo');

This code for retrieve the session variable


$session = Mage::getSingleton('core/session', array('name' => 'frontend'));
echo $session->getMyCustomData();

Magento: Get details of all Admin users


$adminUserModel = Mage::getModel('admin/user');
$userCollection = $adminUserModel->getCollection()->load(); 
Mage::log($userCollection->getData());

Magento get subcategories by category ID


$catID = "15"; 
$children = Mage::getModel('catalog/category')->getCategories($catID);
foreach ($children as $category) {
        echo $category->getId();
        echo $category->getName();
        print_r($category->getData());
}

Magento filter products by status


$products = Mage::getModel('catalog/category')->load($cat_id)
->getProductCollection()->addAttributeToSelect('*') 
->addAttributeToFilter(
    'status', array('eq' => Mage_Catalog_Model_Product_Status::STATUS_DISABLED) 
        //replace DISABLED to ENABLED for products with status enabled
);

Magento disable guest checkout / enable guest checkout


To disable guest checkout, navigate to:
System > Configuration > Sales section > Checkout > Checkout Options
Set Allow Guest Checkout to No
This will now disable any guest checkout in your site.
To enable guest checkout, simply set the above dropdown option to Yes.