public
function
indexAction()
{
if
(
$category
=
$this
->_initCatagory()) {
Mage::getModel(
'catalog/design'
)->applyDesign(
$category
, Mage_Catalog_Model_Design::APPLY_FOR_CATEGORY);
Mage::getSingleton(
'catalog/session'
)->setLastViewedCategoryId(
$category
->getId());
$update
=
$this
->getLayout()->getUpdate();
$update
->addHandle(
'default'
);
if
(!
$category
->hasChildren()) {
$update
->addHandle(
'catalog_category_layered_nochildren'
);
}
$this
->addActionLayoutHandles();
$update
->addHandle(
$category
->getLayoutUpdateHandle());
$update
->addHandle(
'CATEGORY_'
.
$category
->getId());
if
(
$category
->getPageLayout()) {
$this
->getLayout()->helper(
'page/layout'
)
->applyHandle(
$category
->getPageLayout());
}
$this
->loadLayoutUpdates();
$update
->addUpdate(
$category
->getCustomLayoutUpdate());
$this
->generateLayoutXml()->generateLayoutBlocks();
if
(
$category
->getPageLayout()) {
$this
->getLayout()->helper(
'page/layout'
)
->applyTemplate(
$category
->getPageLayout());
}
if
(
$root
=
$this
->getLayout()->getBlock(
'root'
)) {
$root
->addBodyClass(
'categorypath-'
.
$category
->getUrlPath())
->addBodyClass(
'category-'
.
$category
->getUrlKey());
}
$this
->_initLayoutMessages(
'catalog/session'
);
$this
->_initLayoutMessages(
'checkout/session'
);
$this
->_modifyCanonial()->renderLayout();
}
elseif
(!
$this
->getResponse()->isRedirect()) {
$this
->_forward(
'noRoute'
);
}
}
protected
function
_modifyCanonial() {
if
(
$headBlock
=
$this
->getLayout()->getBlock(
'head'
)) {
$items
=
$headBlock
->getData(
'items'
);
foreach
(
$items
as
$key
=>
$value
) {
if
(false !==
strpos
(
$key
,
'link_rel'
)) {
if
(
$value
[
'type'
] ==
'link_rel'
&&
$value
[
'params'
] ==
'rel="canonical"'
) {
$value
[
'name'
] = Mage::getUrl();
$items
[
$key
] =
$value
;
$headBlock
->setData(
'items'
,
$items
);
break
;
}
}
}
}
return
$this
;
}