Showing posts with label rewrite. Show all posts
Showing posts with label rewrite. Show all posts

2014-06-09

Rewrite controllers in magento

For rewriting controller in magento you have to add to your module config.xml:

 
  
   
    
     SliRx_Test
    
   
  
 

where Mage_Checkout - module with a controller which you are going to rewrite.
SliRx_Test - your module which contains the controller for rewrite.

The above config means that magento will search the controller in your module first and after that, if doesn't find it, in Mage_Checkout.
Then you have to create the file SliRx/Test/controllers/CartController.php:
require_once(Mage::getModuleDir('controllers', 'Mage_Checkout') . DS . 'CartController.php');

class SliRx_Test_CartController extends Mage_Checkout_CartController
{
    public function indexAction()
    {
        echo "it's cart!";
    }
}
But magento doesn't know about Mage_Checkout_CartController and you must include the file with this class by yourself. That's why before declaring SliRx_Test_CartController calls require_once;

2014-06-07

Rewrite class/method in Magento

To rewrite class method you have to add rewrite config to etc/config.xml:

 
  
   
    
     SliRx_Test_Model_Category
    
   
  
 

Where tags "catalog" and "category" are assigned to Mage::getModel('catalog/category')
Than create corresponding class at app/code/local/SliRx/Test/Model/Category.php:
class SliRx_Test_Model_Category extends Mage_Catalog_Model_Category
{
    public function getChildren()
    {
        return $this->getResource()->getChildren($this, false);
    }
}

2013-10-31

Добавление правила перезаписи ссылки (rewrite url)

Для создания перезаписи ссылки используем такой код:

$rewrite = Mage::getModel('core/url_rewrite');
$rewrite->setStoreId($storeId)
    ->setIdPath('path_1')
    ->setRequestPath('mego-page.html')
    ->setTargetPath('cityinfo/index/index/city/Киев')
    ->setIsSystem(false)
    ->save();

где path_1 - уникальный идентификатор записи,
mego-page.html - новый адрес для ссылки,
cityinfo/index/index/city/Киев - оригинальный адрес, сюда на самом деле будет идти запрос.