Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your question is still a little unclear, so this answer might not address the specific problem you're seeing.</p> <p>Magento's core team hasn't done a great job of communicating these sorts of things over the years, but <code>loadByRequestPath</code> is one of those methods that's best thought of as a "private api". Not in the OOP sense, but in the "this is a method used to implement core system functionality, and probably won't work like you think it should work, so use at your own risk". </p> <p>The PHP code you're trying to use</p> <pre><code>$productRewrite = Mage::getModel('core/url_rewrite') -&gt;loadByRequestPath($product-&gt;getUrlPath()); </code></pre> <p>won't work with a default installation of Magento because the rewrite object doesn't have a store ID set. Trying something like this should work. (assuming the sample data, with an installed store object that has an ID of "1" and that the product in question exists in that store)</p> <pre><code>$productRewrite = Mage::getModel('core/url_rewrite'); $productRewrite-&gt;setStoreId(1); $productRewrite-&gt;loadByRequestPath($product-&gt;getUrlPath()); </code></pre> <p>The <code>loadByRequestPath</code> method assumes that a rewrite already has a store ID set, as it's part of Magento's larger <a href="http://alanstorm.com/magento_dispatch_rewrites_intro" rel="nofollow">dispatching process</a>. (self-link to article describing the role of rewrites in Magento's routing system)</p> <p>All that said, the problem you're describing is somewhat confusing. You say that</p> <pre><code>Zend_Debug::dump($path); </code></pre> <p>returns </p> <blockquote> <p>an array that contains the path to my module</p> </blockquote> <p>While I'm sure <strong>you</strong> know what the phrase "path to my module" means, it's a meaningless term in the larger magento universe. Being more specific about the literal value will help people understand what you mean.</p> <p>Additionally, you also say </p> <blockquote> <p>I have verified that $product->getUrlPath() returns the correct path.</p> </blockquote> <p>but you're not clear on the value of "the correct path".</p> <p>My guess would be the path you're seeing in <code>Zend_Debug::dump</code> is the call that's coming through as a part of the standard dispatch and <strong>not</strong> your later call using <code>$product->getUrlPath()</code>. However, the lack of clarity in your question makes that hard to tell.</p> <p>If setting the store ID doesn't get you what you want, update your question with a full explanation of how you're running your code, and what you see displayed. With that information more people will be able to help you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload