4

Redirects in Magento have me utterly confused. Enterprise 1.13 has not helped the situation. My problem is this, I want to add a product link widget to the home page but newer products do not show up. I've traced the problem back to Mage_Catalog_Block_Widget_Link::getHref():

$urlRewriteResource = Mage::getResourceSingleton('core/url_rewrite');
$href = $urlRewriteResource->getRequestPathByIdPath($this->getData('id_path'), $store);

Now, the Mage_Core_Model_Url_Rewrite model uses the table core_url_rewrite. And my new products do not exist in that table! Weird, because they are Enabled, visible in Catalog, they have a url_key and I can navigate to the product page just fine. So they must exist in one of the other Enterprise tables. Which one?

core_url_rewrite -> Url Rewrites
enterprise_catalog_category_rewrite -> Relation between rewrites and categories
enterprise_catalog_product_rewrite -> Relation between rewrites and products
enterprise_url_rewrite -> URL Rewrite
enterprise_url_rewrite_redirect -> Permanent redirect
enterprise_url_rewrite_redirect_rewrite -> Relation between rewrites and redirects

Yep, it exists in the enterprise_url_rewrite table ...

+----------------+-----------------------+--------------------------------+-----------+------+-----------------------+-----+----------+----------+-------------+
| url_rewrite_id | request_path          | target_path                    | is_system | guid | identifier            | inc | value_id | store_id | entity_type |
+----------------+-----------------------+--------------------------------+-----------+------+-----------------------+-----+----------+----------+-------------+
|       31282261 | product-1-working     | catalog/product/view/id/256037 |         1 | xyz  | product-1-working     |   1 |  9236282 |        0 |           3 |
|       31294573 | product-2-not-working | catalog/product/view/id/268697 |         1 | xyz  | product-2-not-working |   1 |  9610723 |        0 |           3 |
+----------------+-----------------------+--------------------------------+-----------+------+-----------------------+-----+----------+----------+-------------+
2 rows in set (0.00 sec)

but not in the core_url_rewrite table ...

+----------------+----------+-------------+------------+----------------+-----------------------+--------------------------------+-----------+---------+-------------+
| url_rewrite_id | store_id | category_id | product_id | id_path        | request_path          | target_path                    | is_system | options | description |
+----------------+----------+-------------+------------+----------------+-----------------------+--------------------------------+-----------+---------+-------------+
|        3512685 |        1 |        NULL |     256037 | product/256037 | product-1-working.htm | catalog/product/view/id/256037 |         1 | NULL    | NULL        |
+----------------+----------+-------------+------------+----------------+-----------------------+--------------------------------+-----------+---------+-------------+
1 row in set (0.34 sec)

Next I tried reindexing the url indexes (and if someone could explain the difference between these I'd appreciate it)

$ php shell/indexer.php --reindex catalog_url_product,url_redirect
Product URL Rewrites index was rebuilt successfully
URL Redirects index was rebuilt successfully

Nope, still nothing. What do I have to do to get products in the core_url_rewrite table, other than by creating them manually myself?

  • In short, this is how EE works, in 1.13 it uses enterprise_ tables, in CE 1.8 uses core_rewrite table, just have to use the appropriate one for the version you work on – Petar Dzhambazov Apr 11 '14 at 17:20
  • @PetarDzhambazov So how/why does anything get written to the core_ table? – nachito Apr 11 '14 at 17:45
  • If you change $urlRewriteResource = Mage::getResourceSingleton('core/url_rewrite'); to $urlRewriteResource = Mage::getResourceSingleton('enterprise/url_rewrite'); does it work then? It may just be an oversight in Mage_Catalog_Block_Widget_Link. – Melvyn Apr 11 '14 at 20:24
  • @nachito you can write to core_url_rewrite if you really want, but only for your needs, EE 1.13 is not using it – Petar Dzhambazov Apr 13 '14 at 9:43
6

In Magento Enterprise the is a new module for storing url rewrite Enterprise_UrlRewrite. This module contains new tables for storing the rewrites, some layout files for the admin section, a new admin html controller and a new url matcher to name but a few items.

To understand when the enterprise system uses the new tables for saving rewrites we can first look into the controller Enterprise_UrlRewrite_Adminhtml_UrlrewriteController, here we find the function _getRedirect which is used to to load the current redirect being worked on and returns a model of type Enterprise_UrlRewrite_Model_Redirect.

If we then look into the config.xml for Enterprise_UrlRewrite you can see that it has it's own table information stored so that when the model is being used it does not use the standard community tables.

<models>
    <enterprise_urlrewrite>
        <class>Enterprise_UrlRewrite_Model</class>
        <resourceModel>enterprise_urlrewrite_resource</resourceModel>
    </enterprise_urlrewrite>
    <enterprise_urlrewrite_resource>
        <class>Enterprise_UrlRewrite_Model_Resource</class>
        <entities>
            <url_rewrite>
                <table>enterprise_url_rewrite</table>
            </url_rewrite>
            <redirect>
                <table>enterprise_url_rewrite_redirect</table>
            </redirect>
            <redirect_rewrite>
                <table>enterprise_url_rewrite_redirect_rewrite</table>
            </redirect_rewrite>
        </entities>
    </enterprise_urlrewrite_resource>
</models>

The structure of these new tables, is in my opinion vast improvement of the community editions single table, as the category and product information is moved into separate tables and also the redirect information is also separated.

2

In Magento 1.13 EE, like you already found out in the database, all rewrites, redirects etc. are moved from core to enterprise related tables.

You can find the needed files in the Enterprise_UrlRewrite module. The Enterprise_UrlRewrite_Model_Url_Rewrite class contains a method to load rewrites by requestPath. The classgroup string for the getModel factory is enterprise_urlrewrite/url_rewrite.

Ignore the core_url_rewrite table, it's only for CE.

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.