0

I have a project where I needed to add a custom link to top.links via XML (This is a product URL). Maybe this is not the correct way to add a product to top.links? The handle customer_logged_out works as expected to add the new desired link, however when I try to remove this link within the handle catalog_product_view it does not remove. Below is my content from my local.xml file Does anyone have any ideas?

<customer_logged_out>
    <reference name="top.links">
        <!-- Add Custom Signup link -->
        <action method="addLink" translate="label title" module="catalog">
            <label>Sign Up</label>
            <url>/individual-membership.html</url> <!-- This is a product URL, maybe there is a better way to call the url?  -->
            <title>Sign Up</title>
            <prepare/>
            <urlParams/>
            <position>20</position>
            <liParams/>
            <aParams>class="btn btn-primary sign-up"</aParams>
            <beforeText><![CDATA[<span>]]></beforeText>
            <afterText><![CDATA[</span>]]></afterText>
        </action>
    </reference>
</customer_logged_out>

<!-- Ideally I'd like to remove by product ID instead of global product view  -->
<catalog_product_view>
    <reference name="top.links">
        <!-- Remove Signup Link from Product Page -->
        <action method="removeLinkByUrl">
            <url>/individual-membership.html</url> <!-- This does not work -->
        </action>
    </reference>
</catalog_product_view>

Please note the below removeLinkByUrl method below works as expected for a different link.

<reference name="top.links">
    <!-- Removes Register link -->
    <action method="removeLinkByUrl"><url helper="customer/getRegisterUrl" /></action>
</reference> 

As requested by the comments below, I've also tried the following without success:

<catalog_product_view>
    <reference name="top.links">
        <!-- Remove Signup Link from Product Page -->
        <action method="removeLinkByUrl">
            <url>/individual-membership</url> <!-- This does not work -->
        </action>
    </reference>
</catalog_product_view>

<catalog_product_view>
    <reference name="top.links">
        <!-- Remove Signup Link from Product Page -->
        <action method="removeLinkByUrl">
            <url>individual-membership</url> <!-- This does not work -->
        </action>
    </reference>
</catalog_product_view>

<catalog_product_view>
    <reference name="top.links">
        <!-- Remove Signup Link from Product Page -->
        <action method="removeLinkByUrl">
            <url>/individual-membership</url> <!-- This does not work -->
        </action>
    </reference>
</catalog_product_view>
  • Try it by removing '/' from URL – Gopal Patel Feb 27 '17 at 20:17
  • Also remove that .html – Gopal Patel Feb 27 '17 at 20:20
  • @gopal, I tried these combinations and these did not work. – Rob Feb 27 '17 at 21:16
1

This is caused by the order Magento combines the XML files and handles. As you probably know magento loops through the XML files and combines them, your local.xml is always at the end.

If you were to look at the complete xml for the page you will see that your layout updates within catalog_product_view are higher up than your customer_logged_out handle updates.

echo $this->getLayout()->getXmlString();

So your removeLinkByUrl is effectively trying to remove something out of the array that doesn't yet exist.

I know this isn't exactly a solution but an explanation for your problem.

If you were to add the link in the customer.xml then the your local.xml should have no problem removing it.

  • Let me give this a shot... I started to lean this way, but I never gave it a try. @nathan – Rob Feb 27 '17 at 23:45
  • This does not work either... I feel I may have multiple problems, every successful removal by URL has a helper that's called. Additionally I don't see any of these working with a product. I don't think this should matter, but I don't use local.xml, I utilize /app/design/etc/theme.xml to define layout overrides. These typically work exactly like local.xml but more modularized. – Rob Feb 28 '17 at 18:32
  • I don't believe this <ur>/individual-membership.html</url> is working as expected in any handle. @nathan, do you have any other ideas? – Rob Feb 28 '17 at 18:35

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.