An invalid URL is generated because it cannot find the rewritten URL. Perhaps this is caused by the wrong store_id. eg:
$id = 290; Mage::app()->setCurrentStore('default'); echo "store_id: ".Mage::app()->getStore()->getId()."<br>"; $url = Mage::helper('catalog/product')->getProductUrl($id); echo $url."<br>"; //change store id Mage::app()->setCurrentStore('admin'); echo "store_id: ".Mage::app()->getStore()->getId()."<br>"; $url = Mage::helper('catalog/product')->getProductUrl($id); echo $url."<br>";
result:
store_id: 1 http://local.com/surestep-pro-diabetic-test-strips-50-strips-professional-care.html store_id: 0 https://local.com/index.php/catalog/product/view/id/290/s/surestep-pro-diabetic-test-strips-50-strips-professional-care/
The correct rewrite URL can be found in the table named core_url_rewrite (including store_id information)
If it finds a match value in core_url_rewrite, it will generate the โcorrect urlโ, otherwise it will execute the code product_id + url + category_id
$routePath = 'catalog/product/view'; $routeParams['id'] = $product->getId(); $routeParams['s'] = $product->getUrlKey(); if ($categoryId) { $routeParams['category'] = $categoryId; }
ivantedja
source share