En magento 2.0, ¿cómo puedo agregar nuevos enlaces principales y eliminar uno existente usando xml?

9

app / design / frontend / Amydus / test / Magento_Theme / 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>
        <referenceContainer name="header.container">            
            <block class="Magento\Framework\View\Element\Html\Myblock" name="header.myblock">
                <arguments>
                    <argument name="css_class" xsi:type="string">header links</argument>
                </arguments>
            </block>
        </referenceContainer>
        <referenceBlock name="top.links">
            <block class="Magento\Framework\View\Element\Template" name="tlink.them" before="-" template="Magento_Theme::html/header.phtml"/>
        </referenceBlock>
        <referenceBlock name="logo">
            <arguments>
                <argument name="logo_img_width" xsi:type="number">148</argument>
                <argument name="logo_img_height" xsi:type="number">43</argument>
            </arguments>
        </referenceBlock>
        <referenceContainer name="footer">
            <block class="Magento\Store\Block\Switcher" name="store_switcher" as="store_switcher" after="footer_links" template="switch/stores.phtml"/>
        </referenceContainer>
        <referenceBlock name="report.bugs" remove="true"/>
        <move element="copyright" destination="before.body.end"/>
    </body>
</page>

app / design / frontend / Amydus / test / Magento_Theme / templates / html / header.phtml

<?php 
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $custSession = $objectManager->get('Magento\Customer\Model\Session');
?>
<?php switch ($block->getShowPart()):
    case 'welcome': ?>
        <!-- <li class="greet welcome" data-bind="scope: 'customer'">
            <span data-bind="text: customer().fullname ? $t('Welcome, %1!').replace('%1', customer().fullname) : '<?=$block->escapeHtml($welcomeMessage) ?>'"></span>
        </li> -->
        <li><a style="margin: 3px 0 0 8px;" href="#"><span>CALL US AT - 9560740007</span></a></li>
        <li class=" login_seprator"> | </li>
        <li class="easy-return" ><a style="margin: 3px 0 0 8px;" href="#">  <span >EASY RETURNS & EXCHANGE</span></a>
        </li>
        <li class=" login_seprator"> | </li>                        
        <?php if(!$custSession->isLoggedIn()): ?>
            <li class="hi_li"><span class="guest-color">HI GUEST</span></li>
        <?php else: ?>
            <li class="hi_li"><span><?php echo 'Hi '.$custSession->getCustomer()->getName(); ?></span></li>
        <?php endif; ?>
        <li class=" login_seprator"> | </li>
        <li class="first last top-links-a">
            <?php if($custSession->isLoggedIn()): ?>
                <a class="" title="Log Out" href="#">LOG OUT</a>
            <?php else: ?>
                <a class="" title="Log In" href="#">LOGIN</a>
            <?php endif; ?>
        </li> 

        <script type="text/x-magento-init">
        {
            "*": {
                "Magento_Ui/js/core/app": {
                    "components": {
                        "customer": {
                            "component": "Magento_Customer/js/view/customer"
                        }
                    }
                }
            }
        }
        </script>
    <?php break; ?>

    <?php case 'other': ?>
        <?php echo $block->getChildHtml(); ?>
    <?php break; ?>

<?php endswitch; ?>
Priyanka Saini
fuente

Respuestas:

29

Si extendiste el tema de Luma

app / design / frontend / Amydus / test / Magento_Theme / layout / default.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
       <!--  you can easly add New links with following code -->
        <referenceBlock name="header.links">
               <!-- Contact us Link -->
            <block class="Magento\Framework\View\Element\Html\Link" name="contactus.link" after="register-link">
                <arguments>
                    <argument name="label" xsi:type="string" translate="false">Constact Us</argument>
                    <argument name="path" xsi:type="string" translate="false">contact-us</argument>
                </arguments>
            </block>
            <!-- CMS Page Link Link -->
            <block class="Magento\Framework\View\Element\Html\Link" name="aboutus.link" after="contactus.link">
                <arguments>
                    <argument name="label" xsi:type="string" translate="false">about Us</argument>
                    <argument name="path" xsi:type="string" translate="false">about-us</argument>
                </arguments>
            </block>

             <!--  you can easly Remove  links with following code -->
            <referenceBlock name="register-link" remove="true" />           <!--for Create Account Link-->
            <referenceBlock name="authorization-link" remove="true" />      <!--for Sign In Link  -->
            <referenceBlock name="wish-list-link" remove="true" />          <!--for WishList Link-->
            <referenceBlock name="my-account-link" remove="true" />         <!--for My Account Link-->

        </referenceBlock>
    </body>
</page>

Si extendió el tema en blanco

app / design / frontend / Amydus / test / Magento_Theme / layout / default.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
       <!--  you can easly add New links with following code -->
        <referenceBlock name="top.links">
               <!-- Contact us Link -->
            <block class="Magento\Framework\View\Element\Html\Link" name="contactus.link" after="register-link">
                <arguments>
                    <argument name="label" xsi:type="string" translate="false">Constact Us</argument>
                    <argument name="path" xsi:type="string" translate="false">contact-us</argument>
                </arguments>
            </block>
            <!-- CMS Page Link Link -->
            <block class="Magento\Framework\View\Element\Html\Link" name="aboutus.link" after="contactus.link">
                <arguments>
                    <argument name="label" xsi:type="string" translate="false">about Us</argument>
                    <argument name="path" xsi:type="string" translate="false">about-us</argument>
                </arguments>
            </block>

             <!--  you can easly Remove  links with following code -->
            <referenceBlock name="register-link" remove="true" />           <!--for Create Account Link-->
            <referenceBlock name="authorization-link" remove="true" />      <!--for Sign In Link  -->
            <referenceBlock name="wish-list-link" remove="true" />          <!--for WishList Link-->
            <referenceBlock name="my-account-link" remove="true" />         <!--for My Account Link-->

        </referenceBlock>
    </body>
</page>
Satish Rana
fuente
De todos modos, en Magento 2.1.3, el enlace de registro desaparece al usar su solución. ¿Alguna idea de por qué?
Max
¿Qué hay de mover esos enlaces dentro del <div class="header content"></div>elemento, donde está el logotipo? ¿Cómo lo harías tú?
Razvan Zamfir
para eliminar el inicio de sesión, debe usar "autorización-enlace-inicio de sesión"
Sagar Parikh SGR
5

También puede usar la Magento\Customer\Block\Account\SortLinkInterfaceclase de bloque, que le permite ordenar enlaces en el bloque top.links.

<referenceBlock name="top.links">
<block class="Magento\Customer\Block\Account\SortLinkInterface" name="newsletter_subscription_top_link">
    <arguments>
        <argument name="label" xsi:type="string" translate="true">Newsletter Subscription</argument>
        <argument name="path" xsi:type="string" translate="true">newsletter/manage</argument>
        <argument name="sortOrder" xsi:type="number">10</argument>
    </arguments>
</block>
</referenceBlock>
Acebo
fuente