We are doing custom Magento themes, Magento design, custom Magento extensions and creative services through Magento designers & developers for worldwide shop owners.

Last News
Magento some code about rewrite model for SEO

Magento some code about rewrite model for SEO

get instance of class url_rewrite model:

1
$coreRewrite = Mage::getModel('core/url_rewrite');

get collection request path by products ids and categories ids :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$cat_id=2;
        $product_id=array(1,3);
        $select = $this->getConnection()->select()
        ->from($this->getTable('core/url_rewrite'), array('product_id', 'request_path'))
        ->where('store_id=?', Mage::app()->getStore()->getId())
        ->where('is_system=?', 1)
        ->where('category_id=? OR category_id is NULL', 2) // HERE ASSIGNED
        ->where('product_id IN(?)', $product_id)
        ->order('category_id DESC'); // more priority is data with category id
        $urlRewrites = array();
 
        foreach ($this->getConnection()->fetchAll($select) as $row) {
        if (!isset($urlRewrites[$row['product_id']])) {
            $urlRewrites[$row['product_id']] = $row['request_path'];
        }

get request path by category id and product id and store id :

1
2
3
4
5
6
7
8
9
10
11
$productId=10;
        $categoryId=4;
        $storeId=5
        $coreUrl = Mage::getModel('core/url_rewrite');
        $idPath = sprintf('product/%d', $productId);
        if ($categoryId) {
            $idPath = sprintf('%s/%d', $idPath, $categoryId);
        }
        $coreUrl->setStoreId($storeId);
        $coreUrl->loadByIdPath($idPath);
        echo $coreUrl->getRequestPath();

get target path:

1
2
3
4
$Product = Mage::getModel('catalog/product')->load($productId);
       $coreRewrite = Mage::getModel('core/url_rewrite')->loadByRequestPath($oProduct->getUrlPath());
       $coreRewrite->getTargetPath();
       echo $coreRewrite->getTargetPath()

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*