3

I have been stuck on this task all day. I am hoping someone has some insight or is this a bug? I have tried a few different approaches and nothing seems to actually work.

This is how it currently looks like:

enter image description here

This is how I want it to look like:

enter image description here

Magento_Customer\layout\default.xml

<?xml version="1.0"?>

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>

    <referenceBlock name="header.links">

        <block class="Magento\Customer\Block\Account\Link" name="my-account-link" before="-">
            <arguments>
                <argument name="label" xsi:type="string" translate="true">My Account</argument>
                <argument name="sortOrder" xsi:type="number">1</argument>
            </arguments>
        </block>

        <block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-orders-link-top" after="my-account-link">
            <arguments>
                <argument name="path" xsi:type="string">sales/order/history</argument>
                <argument name="label" xsi:type="string" translate="true">My Orders</argument>
                <argument name="sortOrder" xsi:type="number">2</argument>
            </arguments>
        </block>

        <block class="Lof\RequestForQuote\Block\Account\Link" name="my-quote-link" after="customer-account-navigation-orders-link-top">
            <arguments>
                <argument name="label" xsi:type="string" translate="true">My Quotes</argument>
                <argument name="sortOrder" xsi:type="number">3</argument>
            </arguments>
        </block>

        <block class="Magento\Framework\View\Element\Html\Link" name="giftr-top-link" after="my-quote-link">
            <arguments>
                <argument name="path" xsi:type="string">giftr/registry</argument>
                <argument name="label" xsi:type="string" translate="true">My Gift Registry</argument>
                <argument name="sortOrder" xsi:type="number">4</argument>
            </arguments>
        </block>

        <block class="Magento\Wishlist\Block\Link" name="wish-list-link" after="giftr-top-link">
            <arguments>
                <argument name="label" xsi:type="string" translate="true">My Wish List</argument>
                <argument name="sortOrder" xsi:type="number">5</argument>
            </arguments>
        </block>

        <block class="Magento\Customer\Block\Account\AuthorizationLink" name="authorization-link-login" template="Magento_Customer::account/link/authorization.phtml" after="-">
            <arguments>
                <argument name="sortOrder" xsi:type="number">6</argument>
            </arguments>
        </block>

        <block class="Magento\Customer\Block\Account\AuthorizationLink" name="authorization-link" template="Magento_Customer::account/link/authorization.phtml" after="-">
            <arguments>
                <argument name="sortOrder" xsi:type="number">7</argument>
            </arguments>
        </block>

    </referenceBlock>

    <block class="Magento\Theme\Block\Html\Header" name="header" as="header">
        <arguments>
            <argument name="show_part" xsi:type="string">welcome</argument>
        </arguments>
    </block>

    <move element="header" destination="header.links" before="-"/>
    <move element="register-link" destination="header.links"/>
    <move element="top.links" destination="customer"/>
    <move element="my-account-link" destination="top.links" before="-"/>
    <move element="customer-account-navigation-orders-link-top" destination="top.links" after="my-account-link"/>
    <move element="my-quote-link" destination="top.links" after="customer-account-navigation-orders-link-top"/>
    <move element="giftr-top-link" destination="top.links" after="my-quote-link"/>
    <move element="wish-list-link" destination="top.links" after="giftr-top-link"/>
    <move element="authorization-link" destination="top.links" after="-"/>

</body>

I am also overriding Magento\Customer\Block\Account\Navigation.php with the changes I found here:

https://github.com/magento/magento2/pull/14726/commits/1a281c1e5fbf8d81b46585df5eb71386b4c03167

Even with those changes I still can't got the top links to be in the order I want. The before and after tags do not seem working. So I thought I would try sortOrder argument but that also doesn't doing anything.

  • I decided to remove the new code from Navigation.php and now the customer_account.xml sortOrder is backwards! Meaning a high number will be first in order. The only change in top links was My Account and Sign Out switched places. – RLTcode Apr 19 '18 at 16:31
  • Which magento version you are using? – ABHISHEK TRIPATHI Apr 27 '18 at 5:42
  • 2.2.3 currently – RLTcode Apr 27 '18 at 19:24
  • @rltegantvoort, any solution worked for you? – Mohit Kumar Arora Apr 30 '18 at 8:00
1

Traverse at below location

Magento_root/demo/vendor/magento/theme-frontend-luma/Magento_Customer/layout

copy default.xml from above location & paste at this place(below)

Magento_root/app/design/frontend/{Vendor}/{theme}/Magento_Customer/layout

Put below code into it after header block (around at line-23)

Update

    <!-- <move element="authorization-link" destination="top.links" before="wish-list-link"/> -->
        <!--- custom entry -->
                <referenceBlock name="top.links">
                    <referenceBlock name="my-account-link">
                       <arguments>
                            <argument name="label" xsi:type="string" translate="true">My Account</argument>
                        </arguments>
                    </referenceBlock>
                    <block class="Abhishek\Toplink\Block\View\Element\Html\Link" name="my-order-link-top">
                        <arguments>
                            <argument name="path" xsi:type="string">sales/order/history</argument>
                            <argument name="label" xsi:type="string" translate="true">My Orders</argument>
                            <argument name="sortOrder" xsi:type="number">100</argument>
                        </arguments>
                    </block>
                    <block class="Abhishek\Toplink\Block\View\Element\Html\Link" name="my-quote-link-top">
                        <arguments>
                            <argument name="label" xsi:type="string" translate="true">My Quotes</argument>
                            <argument name="sortOrder" xsi:type="number">90</argument>
                        </arguments>
                    </block>
                    <block class="Abhishek\Toplink\Block\View\Element\Html\Link" name="giftr-top-link">
                        <arguments>
                            <argument name="path" xsi:type="string">giftr/registry</argument>
                            <argument name="label" xsi:type="string" translate="true">Donate My Trap Program</argument>
                            <argument name="sortOrder" xsi:type="number">80</argument>
                        </arguments>
                    </block>
                    <block class="Magento\Wishlist\Block\Link" name="wish-list-link">
                        <arguments>
                            <argument name="sortOrder" xsi:type="number">70</argument>
                        </arguments>
                    </block>
                    <block class="Magento\Customer\Block\Account\AuthorizationLink" name="authorization-link" template="Magento_Customer::account/link/authorization.phtml">
                        <arguments>
                            <argument name="sortOrder" xsi:type="number">60</argument>
                        </arguments>
                    </block>
                    <block class="Magento\Customer\Block\Account\RegisterLink" name="register-link">
                        <arguments>
                            <argument name="label" xsi:type="string" translate="true">Create an Account</argument>
                        </arguments>
                    </block>
                </referenceBlock>  
  <!--- custom entry -->

Create a new module as per the magento rules & create block file in your new module & put the below code into it here is my block code located at below location

Abhishek\Toplink\Block\View\Element\Html\Link.php

<?php
namespace Abhishek\Toplink\Block\View\Element\Html;

use Magento\Customer\Block\Account\SortLinkInterface;

class Link extends \Magento\Framework\View\Element\Html\Link implements SortLinkInterface
{
    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        array $data = []
    ){
        parent::__construct($context, $data);
    }

    public function getSortOrder()
    {
        return $this->getData(self::SORT_ORDER);
    }
}

Here Abhishek is my Vendor_Name & Toplink is my Module_Name.

enter image description here enter image description here

Note: While doing this make sure your cache is disabled of run below command from your magento_root through your terminal

php bin/magento c:f

Never do changes into the core file of magento

  • I had already previously tried the code you provided and accomplished my goal but I would prefer to keep the wishlist function – RLTcode Apr 27 '18 at 19:37
  • Suggesting to copy an entire layout.xml file is automatically the wrong answer. – Shawn Abramson Apr 28 '18 at 13:22
0

Try to use this code :-

File path:

app/design/frontend/Vendor_name/module_name/Magento_Customer/layout/customer_account.xml

Code:

<move element="LINK_YOU_WANT_TO_MOVE" destination="customer_account_navigation" AFTER_OR_BEFORE="NEW_POSITION" />   <!-- eg. "My Wish List" move after "My Orders" --> <move element="customer-account-navigation-wish-list-link" destination="customer_account_navigation" after="customer-account-navigation-orders-link" />
  • I am trying to move/reorder the top links. I have already moved the customer_account.xml links no problem and I had to use a different route than what you posted. I tried the move element but it did not work correctly. – RLTcode Apr 17 '18 at 20:50
0

Try to use below code :

<move element="wish-list-link" destination="header.links" before="authorization-link"/>
<move element="authorization-link" destination="header.links" after="-"/>
  • already tried this but does not work. I believe it is a known bug at the moment – RLTcode Apr 27 '18 at 19:37
0

You need to use arguments. This works for me. If I remember correctly, you actually need to run the numbers in reverse order.

You would do this in default.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="my-account-link">
            <arguments>
                <argument name="sortOrder" xsi:type="number">300</argument>
            </arguments>
        </referenceBlock>

        <referenceBlock name="wish-list-link">
            <arguments>
                <argument name="sortOrder" xsi:type="number">200</argument>
            </arguments>
        </referenceBlock>
    </body>
</page>
  • Shawn - for the customer_account.xml Dashboard links I had to run the numbers in reverse, which I was able to rearrange with sortOrder. But in default.xml the sortOrder does not work. You can see in my default.xml file I have already tried what you requested. My code was slightly different so I did attempt to use your code but still nothing. – RLTcode Apr 30 '18 at 15:28
  • @rltegantvoort This is likely due to the order of module loading. You should step into the code of the block class and make not of which sort order arguments are being accepted first. You can always create an "after" plugin to accomplish this goal if needed. – Shawn Abramson Apr 30 '18 at 17:05
0

I had the same issue before and i solved by removing all links then add them again with custom name in the order that i want, you may try this

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
    <referenceBlock name="header.links">


    <referenceBlock name="my-account-link" remove="true"/>
    <referenceBlock name="wish-list-link" remove="true"/>
    <referenceBlock name="customer-account-navigation-orders-link-top" remove="true"/>

    <!-- 
        remove all links here
    -->

        <block class="Magento\Customer\Block\Account\Link" name="my-account-link-custome" before="-">
            <arguments>
                <argument name="label" xsi:type="string" translate="true">My Account</argument>
                <argument name="sortOrder" xsi:type="number">1</argument>
            </arguments>
        </block>

    <!-- 
        add the tabs here in the order you wish with changeing the name (changing the name is very important)
        as you see in this example i change the name of my account from [my-account-link] to [my-account-link-custome]
    -->        
    </referenceBlock>
</body>

It is worked and i used it in my development, Hope this will help you

The main idea is [remove current links and add them again with different name ]

  • tried this as well and remained in the same order as initial post after clearing cache. – RLTcode Apr 30 '18 at 15:56
0

please try my code and customize it for yourself

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
    <referenceBlock name="header.links">
        <block class="Magento\Customer\Block\Account\Customer" name="customer" template="account/customer.phtml" before="-"/>
        <block class="Magento\Customer\Block\Account\Customer" name="custom.link" template="account/custom-link.phtml" after="customer"/>
        <block class="Magento\Customer\Block\Account\AuthorizationLink" name="authorization-link-login" template="account/link/authorization.phtml"/>
    </referenceBlock>
    <block class="Magento\Theme\Block\Html\Header" name="header" as="header">
        <arguments>
            <argument name="show_part" xsi:type="string">welcome</argument>
        </arguments>
    </block>
    <referenceBlock name="top.links">
        <block class="Magento\Customer\Block\Account\SortLinkInterface" name="customer-account-navigation-orders-link-top">
            <arguments>
                <argument name="path" xsi:type="string">sales/order/history</argument>
                <argument name="label" xsi:type="string" translate="true">My Orders</argument>
            </arguments>
        </block>
        <block class="Magento\Wishlist\Block\Link" name="wish-list-link" after="customer-account-navigation-orders-link-top"/>
        <block class="Magento\Customer\Block\Account\SortLinkInterface" name="customer-account-navigation-product-reviews-link-top">
            <arguments>
                <argument name="path" xsi:type="string">review/customer</argument>
                <argument name="label" xsi:type="string" translate="true">My Product Reviews</argument>
            </arguments>
        </block>
    </referenceBlock>
    <move element="header" destination="header.links" before="-"/>
    <move element="register-link" destination="header.links"/>
    <move element="top.links" destination="customer"/>
    <move element="authorization-link" destination="top.links" after="-"/>
</body>

you should change the block class of new links to "Magento\Customer\Block\Account\SortLinkInterface" and move 'wish-list-link' after your last new link block (for you: 'My Donate a Trap Program' block, but for me "customer-account-navigation-orders-link-top"), as you see in my code.

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.