简体   繁体   中英

How can I disable button in backoffice when make action with another button - HYBRIS?

Hi experts how can I disable button action in backoffice when make action with another button?

For example when I create order from storefront then in backoffice in orders tab for current order i have 2 action button. APROVE and REJECT.

在此处输入图片说明

When approve order I still see Reject button. How can disable this button after approve?

在此处输入图片说明

In your action class ( which implements CockpitAction ), you have to override canPerform method to return true/false based on your business logic.

For instance, you can refer to how Customer's Enable/Disable action works OOTB.

In b2bcommercebackoffice-backoffice-config.xml you can find

<context merge-by="module" type="B2BCustomer" component="editorareaactions">
    <y:actions xmlns:y="http://www.hybris.com/cockpit/config/hybris">
        <y:group qualifier="common">
            <y:label>actiongroup.common</y:label>               
            <y:action action-id="de.hybris.platform.b2bcommerce.backoffice.actions.disableb2bcustomeraction" property="currentObject"/>
            <y:action action-id="de.hybris.platform.b2bcommerce.backoffice.actions.enableb2bcustomeraction" property="currentObject"/>
        </y:group>
    </y:actions>
</context>

Now refer to disableb2bcustomeraction or enableb2bcustomeraction class how they have implemented canPerform method.

eg

public boolean canPerform(ActionContext<B2BCustomerModel> ctx) {
    Object data = ctx.getData();
    if (data != null && data instanceof B2BCustomerModel) {
        B2BCustomerModel b2bCustomerModel = (B2BCustomerModel) data;
        UserModel currentUser = this.userService.getCurrentUser();
        boolean isActive = b2bCustomerModel.getActive();
        boolean isUserMemberOfAdminGroup = this.userService.isMemberOfGroup(currentUser,
                this.userService.getAdminUserGroup());
        boolean isUserMemberOfB2BAdminGroup = this.userService.isMemberOfGroup(currentUser,
                this.userService.getUserGroupForUID("b2badmingroup"));
        return (isUserMemberOfAdminGroup || isUserMemberOfB2BAdminGroup) && isActive;
    } else {
        return false;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM