0

After much fighting with my layouts to add a link to my customer account page in a way that matches the design I finally succeeded in making the link show up and link to an actual page that also matches the design.

Of course, now I need to remove the link, but only on certain store views.

I've found this question but that removes it from all stores.

Initially, I tried using an observer as so:

<?php

namespace Vendor\Module\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

class RemoveBlockForNonWholeSale implements ObserverInterface
{
    protected $logger;
    protected $store;

    public function __construct(
        \Magento\Store\Model\StoreManagerInterface $storeManager 
    )
    {
        $this->_storeManager = $storeManager;
    }
    
    public function execute(Observer $observer)
    {
        $layout = $observer->getLayout();
        $store_code = $this->_storeManager->getStore()->getCode();
        
        $wh_stores = array('wh','wh_b2b');
        if (!in_array($store_code, $wh_stores)) 
        {
            $layout->unsetElement('customer_account_dashboard_b2b_status');
        }
    }
}

Here I am attempting to only show the link on the wh and wh_b2b store/account views.

The link still shows up though. If there is a better way to do this let me know, copied below is my layout xml.

<?xml version="1.0"?>
<page layout = "2column-left" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation = "urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="customer_account"/>
    <body>
        <referenceBlock name="customer_account_navigation">
            <block class="Magento\Customer\Block\Account\SortLinkInterface" name="customer-account-navigation-b2b-order-status-link">
                <arguments>
                    <argument name="path" xsi:type="string">b2b/status</argument>
                    <argument name="label" xsi:type="string" translate="true">Check Order Status</argument>
                    <argument name="sortOrder" xsi:type="number">45</argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>
</page>

2 Answers 2

1

Create child theme for your b2b store and add layout changes you have found in other answer only in your child theme used by b2b store.

This way all other stores will have one set of links and for b2b you can add/remove links how you wish.

This way you don't need to create module, use observers etc.

More about themes: https://devdocs.magento.com/guides/v2.4/frontend-dev-guide/themes/theme-inherit.html

2
  • I just had the wrong element ID, the solution I have used above only requires me to add one line to the observer that is already existing so I am going to stick with that method.
    – joeybab3
    Commented Aug 18, 2020 at 16:06
  • Sure. If you have already this module/files created then there is no sense to create child theme just for this. However it is usually very useful to have child themes - depending how much/what kind of customization you will have in your project. Commented Aug 18, 2020 at 16:27
0

14 minutes more is apparently all it took to figure this out on my own...

My issue was using the wrong element name.

I was using the element name from my page layout file rather than the customer_account.xml file:

customer-account-navigation-b2b-order-status-link

vs

customer_account_dashboard_b2b_status

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.