专家,当我用另一个按钮执行操作时,如何在后台禁用按钮操作?
例如,当我从店面创建订单时,在后台的“订单”标签中为当前订单创建订单时,我有2个操作按钮。拒绝并拒绝。
批准订单后,我仍然看到“拒绝”按钮。批准后如何禁用此按钮?
答案 0 :(得分:1)
在您的操作类(实现CockpitAction
)中,您必须重写canPerform
方法以根据业务逻辑返回true / false。
例如,您可以参考“客户的启用/禁用”操作如何在OOTB中工作。
在b2bcommercebackoffice-backoffice-config.xml
中,您可以找到
<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>
现在参考 disableb2bcustomeraction 或 enableb2bcustomeraction 类如何实现 canPerform 方法。
例如
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;
}
}