Question

given a product page, i need to retrieve the product url for another store. I'm trying this solution:

 Mage::getUrl('', array(
        '_current' => true,
        '_use_rewrite' => true,
        '_secure' => true,
        '_store' => 3,
        '_store_to_url' => true
    ));

but the result is that just the base url is changed, while the url key is the same. The link of course is broken. i can't use the url_rewrite model because if there is no record for a product it just returns the base url. Any idea?

thanks

Was it helpful?

Solution

Since you don't have access to URLs from the URL rewrites you'll need to add a setStoreId() when loading the product. Note, it's faster to have a URL key and query it instead of loading up the entire product Model.

$productId = 1234; 
$product = Mage::getModel('catalog/product')
            ->setStoreId(2) // set your store ID
            ->load($productId);

zend_debug::dump($product->getProductUrl());

Further reading:

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top