4

We recently migrated from a proprietary shopping cart to Magento Enterprise.

Currently we are using a custom module to redirect the old product URL's to the new Magento product URL's.

However, I am looking to move on from this front-end controller that handles this logic, to importing them as URL rewrite rules.

There seems to be a lot of documentation for creating a URL rewrite url in community edition, which uses the deprecated core_url_rewrite table.

Previously, you would do something like:

$results = Mage::getModel('core/url_rewrite')
    ->setIsSystem(0)
    ->setOptions('RP')
    ->setIdPath($legacy_url)
    ->setRequestPath($legacy_url)
    ->setTargetPath($url)
    ->setDescription('legacy product id '.$legacy_id)
    ->save();

However, in Enterprise 1.13, the model I think I should be using is: enterprise_urlrewrite/url_rewrite

Can someone advise on how to do the equivalent? I can't seem to get it to show up in the admin, even after doing a reindex.

Thanks

3

Firsly the model is now Enterprise_UrlRewrite_Model_Url_Rewrite:

Mage::getModel('enterprise_urlrewrite/url_rewrite');

Secondly the options have changed slightly to.

Options

store_id,
identifier
target_path
options
description,
category_id
product_id

Note: category and product id are optional only for category and product rewrites

So assuming that your code is not for product or category rewrites:

$results = Mage::getModel('enterprise_urlrewrite/url_rewrite')
    ->setStoreId($store_id)
    ->setOptions('RP')
    ->setIdentifier($legacy_url)
    ->setTargetPath($url)
    ->setDescription('legacy product id '.$legacy_id)
    ->save();
2

I ran into a similar issue, creating custom rewrites (redirects) in Magento 1.13. I only saw them in the admin when I addressed the redirect model rather than url_rewrite.

Here is a snippet of what I was using to set redirects on save of my custom entity.

//check for existing redirect
$redirect = Mage::getModel('enterprise_urlrewrite/redirect')
    ->getCollection()
    ->addFieldToFilter('target_path', $target_path)
    ->getFirstItem();

if(!$redirect->getId()){
    Mage::Log('no such redirect');
    $redirect = Mage::getModel('enterprise_urlrewrite/redirect');
}

$redirect
    ->setStoreId($store_id)
    ->setOptions('')
    ->setIdentifier($request_path)
    ->setTargetPath($target_path)
    ->save();
0

The correct class to use is Enterprise_UrlRewrite_Model_Redirect, so mtopping was right. However I wouldn't use target_path to check if a rewrite exists as the field itself is not unique, request_path is (hence the column name is 'identifier). Here is what I would do:

Mage::getModel('enterprise_urlrewrite/redirect')->load($aRedirect['request_path'], 'identifier')
                ->setStoreId($iDefaultStoreId)
                ->setOptions('RP')
                ->setIdentifier($aRedirect['request_path'])
                ->setTargetPath($aRedirect['target_path'])
                ->setDescription('Redirect from old site')
                ->save();

That is, assuming you havea single store. For multistores you will have to use collection load. similar to what mtopping suggested but with extra addFieldToFilter for store id.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.