Is there a way to get a list of products with their current canonical url on command line?
class Mage_Shell_UrlTest extends Mage_Shell_Abstract
{
public function run()
{
$productCollection = Mage::getResourceModel('catalog/product_collection')
->addStoreFilter()
->addUrlRewrite()
->addAttributeToSelect('*')
->setPageSize(10) // just for testing
->addFieldToFilter('visibility',Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)
->addAttributeToFilter('status', array(
'eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED
));
Mage::getSingleton('cataloginventory/stock')
->addInStockFilterToCollection($productCollection);
foreach ($productCollection as $product) {
$url = $product->getUrlModel()->getUrl($product, array('_ignore_category' => true));
echo PHP_EOL . $url . PHP_EOL; // debug output
}
}
}
$shell = new Mage_Shell_UrlTest();
$shell->run();
I run it with php -f magento/shell/urlTest.php and this gives me something like this: