Extension to Hide Credit card option in Myaccount menu

Scenario:
The client wants to hide the Credit card option under the Settings tab and also needs to hide it from the MyAccount Header menu.

Solution:

We can create an extension for this purpose. We can extend the ‘MenuTree.View’ for hiding from my account page and ‘Header.Menu.MyAccount.View’ from the header menu.

Code:

define(
  'ConsuleSolution.HidePaymentOption.HideOption', [
    'MenuTree.View',
    'Header.Menu.MyAccount.View'
  ],
  function(
    MenuTreeView,
    HeaderMenuMyAccountView
  ) {
    'use strict';
    return {
      mountToApp: function mountToApp(container) {
        var layout = container.getComponent('Layout');
        var myAccount = container.getComponent('MyAccountMenu');
        if (layout) {
          _.extend(HeaderMenuMyAccountView.prototype, {
            getContext: _.wrap(HeaderMenuMyAccountView.prototype.getContext, function(fn) {
              var original_Ret = fn.apply(this, _.toArray(arguments).slice(1));
              original_Ret.entries.splice(5, 1);
              original_Ret.entries[4].children.splice(3, 1);
              return original_Ret;
            })
          });
        }
        if (myAccount) {
          _.extend(MenuTreeView.prototype, {
            getContext: _.wrap(MenuTreeView.prototype.getContext, function(fn) {
              var original_Ret = fn.apply(this, _.toArray(arguments).slice(1));
              original_Ret.menuItems.splice(5, 1);
              original_Ret.menuItems[4].children.splice(3, 1);
              return original_Ret;
            })
          });
        }
      }
    };
  });

Leave a comment

Your email address will not be published. Required fields are marked *