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()
|