1.How to get CMS page id in Magento?



Actually you can easily manage CMS page from an admin panel. However, you are able to insert blocks in it. For example we have 2 cms pages: contacts and FAQ, these pages include block with banner which appears on each of these 2 pages, but content for this block is based on some PHP code. And if block content somehow depends on the page, we have to use following method.

PHP Code:
function getCurrentCmsPage() {

$pageId Mage::getBlockSingleton('cms/page')->;getPage()->;getIdentifier();

return 
$pageId;


Done

2.How to filtrate Magento category collection by rank?



Sometimes you need to get a list of all categories with a particular level for a custom navigation menu. This can be done as follows:

PHP Code:
$model=Mage::getModel('catalog/category');

$categories=$model->;getCollection()->;addLevelFilter(2)

->;
addAttributeToSelect(' ')->;addIsActiveFilter(); 
However, this is not always correct. I think I should explain why, right?

If I will enter request to a base I will get the following: SELECT main_table. FROMcatalog_category_flat_store_1 AS main_table WH ERE (main_table.level <= 2) AND (is_active = ’1′)

It is very visible that condition <= is in use, what doesn’t fit, because filtering categories of 3 rd level we will also get categories with 2 nd level.

Due to this we should do filtration in the following way:

PHP Code:
$categories=$model->;getCollection()->;addAttributeToFilter('level',2)

->;
addAttributeToSelect(' ')->;addIsActiveFilter(); 
After this we can do whatever we want with the collection.

3. 404 error appears when entering Magento admin panel.



Sometimes migration to the other server can cause some problems such as error 404. The most frequent reason is a hosting switching.

And if you want to fix it, first of all you have to commit the next query:

Code:
SET FOREIGN_KEY_CHECKS=0;

UPDATE `core_store` SET store_id = 0 WHERE code='admin';

UPDATE `core_store_group` SET group_id = 0 WHERE name='Default';

UPDATE `core_website` SET website_id = 0 WHERE code='admin';

UPDATE `customer_group` SET customer_group_id = 0 WHERE customer_group_code='NOT LOGGEDIN';

SET FOREIGN_KEY_CHECKS=1;
Next, clear your cache folder in /var/cache/. If you own enterprise version or FPC has been installed – then folder /var/full_page_cache/ needs to be cleared as well.

View more threads in the same category: