0

We have a B2B registration with the options dealer, corporate and employee on our website. Customer can register any one of the option by filling the corresponding form.

Now what I wanted to implement is when a customer completed his/her registration, I want to show separate My Account dashboard with necessary links. How can I do that?

enter image description here

Any help will be appreciated.

  • You mean you want to hide some tabs which is coming in left sidebar for some customer groups and display new tabs for some customers. Am I right ? – Kishan Savaliya Oct 21 '19 at 6:17
  • Yes, you're right. But I want to redirect to the corresponding My Account dashboard when the customer complete registration – Siva Oct 21 '19 at 6:18
  • Okay for tabs you can add conditions, and for dashboard page you can create different phtml template files and you can put conditions based on group and display accordingly. – Kishan Savaliya Oct 21 '19 at 6:22
  • What you want to change in dashboard? Can you please attach screenshots in question? So I can update you. – Kishan Savaliya Oct 21 '19 at 6:52
  • 1
    @KishanSavaliya, I'm working on that. Update you shortly – Siva Oct 22 '19 at 14:38
1

Here, I'll explain you this with one example.

We will need to display My Wishlist link only for B2C Customer and B2C Employee customer groups and not in B2B Dealer and B2B Corporate.

  • All Sidebar links, we can find here in customer_account.xml in different modules under customer_account_navigation container.

Like if you want to find My Wishlist link then you check this file..

vendor/magento/module-wishlist/view/frontend/layout/customer_account.xml

My Account link located here in this file..

vendor/magento/module-customer/view/frontend/layout/customer_account.xml

My Orders link located here in this file..

vendor/magento/module-sales/view/frontend/layout/customer_account.xml

  • So I think now you get idea how sidebar links are working. And you need to add any new links there then you can add that there.

So we will create this file here

app/design/frontend/Vendor/Theme/Magento_Theme/layout/customer_account.xml

Here we need to change Class name for wishlist link and we will add new Class name there. So we can not change class name with referenceBlock so we will override class with block itself. So just copy entire block from there and add that in custom theme's customer_account.xml file and update your class name.

Content for above file is ...

<?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="customer_account_navigation">
            <block class="Vendor\Module\Block\Account\WishlistLink" ifconfig="wishlist/general/active" name="customer-account-navigation-wish-list-link">
                <arguments>
                    <argument name="path" xsi:type="string">wishlist</argument>
                    <argument name="label" xsi:type="string" translate="true">My Wish List</argument>
                    <argument name="sortOrder" xsi:type="number">210</argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>
</page>
  • Here I've changed Block's class name from Magento\Customer\Block\Account\SortLinkInterface to Vendor\Module\Block\Account\WishlistLink.

So now we need to create one Block file in our custom module here

app/code/Vendor/Module/Block/Account/WishlistLink.php

Content for this file is ..

<?php
namespace Vendor\Module\Block\Account;

class WishlistLink extends \Magento\Framework\View\Element\Html\Link\Current
{
    protected $_customerSession;

    protected $customerGroup;

    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Framework\App\DefaultPathInterface $defaultPath,
        \Magento\Customer\Model\Session $customerSession,
        \Magento\Customer\Model\ResourceModel\Group\Collection $customerGroup,
        array $data = []
     ) {
         $this->_customerSession = $customerSession;
         $this->customerGroup = $customerGroup;
         parent::__construct($context, $defaultPath, $data);
     }

    protected function _toHtml()
    {
        $customerGroupId = $this->_customerSession->getCustomerGroupId();
        $customerGroups = $this->customerGroup->toOptionArray();

        foreach ($customerGroups as $customerGroup) {
            if($customerGroup['value'] == $customerGroupId){
                $currentCustomerGroup = $customerGroup['label'];
            }
        }

        if($this->_customerSession->isLoggedIn()) {
            if(in_array($currentCustomerGroup, array("B2C Customer", "B2C Employee"))) {
                return parent::_toHtml();
            } else {
                return; 
            }
        }
        return;
    }
}
  • Here in this file I've added Customer Group's Condition. So now if any customer has B2C Customer and B2C Employee Group that customer only can see "My Wishlist" link in account dashboard page.

You can do same thing for different links same as above. You can create different Block files and you can override multiple block's class name in xml file.

Hope this will help you!

| improve this answer | |
  • Thanks. It's very descriptive. Hopefully I will get the output. Update you once done – Siva Oct 23 '19 at 13:57
  • Okay no problem @Siva – Kishan Savaliya Oct 23 '19 at 14:07
  • What I have to put in value at if($customerGroup['value'] == $customerGroupId){ $currentCustomerGroup = $customerGroup['label']; } – Siva Oct 23 '19 at 18:30
  • 1
    Okay I'll send you a link within few mins. You can download that module and you can check. – Kishan Savaliya Oct 24 '19 at 4:11
  • 1
    Approve my answer and give me an upvote if above solution is helpful to you. Thanks in advance! :) – Kishan Savaliya Oct 26 '19 at 6:53
2

You have multiple options for this approach.

  1. You can override my Account Page and Customize.

    or

  2. You can add new page and set default open to that corresponding page.

    or

  3. You can also create one module for setting up menus visibilty option according to your user group.

Hope this will help you!!

| improve this answer | |
  • Thanks. Since there are multiple approaches, I would like to know which one is good? – Siva Oct 21 '19 at 6:40
  • I think last one approach is good, set menus visibility according to user and also set default page for all of them(according to level). – Oscprofessionals Oct 21 '19 at 6:42
  • I think add new pages and set default open is easy approach. Please guide – Siva Oct 21 '19 at 6:42
  • Yes, you can go with second approach as well, this is very easy and time consuming approach. – Oscprofessionals Oct 21 '19 at 6:43
  • Can you please explain bit more if I go with option 3? – Siva Oct 21 '19 at 11:47

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.