如何从销售订单详细信息页面的地址信息块中删除/禁用编辑按钮



根据特定的订单状态,我想限制用户更改订单地址,即

我想从地址信息块的账单和送货地址中禁用或删除编辑按钮

请查看下图

https://i.stack.imgur.com/2BoFC.png

首先,您需要找到负责销售订单视图页面这一部分的模板。您可以通过在管理-存储-配置-高级-开发人员-调试中启用模板调试来执行此操作

这是我们需要的模板 - vendor/magento/module-sales/view/adminhtml/templates/order/view/info.phtml

在第 172 行和第 181 行,我们有编辑链接渲染

<div class="actions"><?= /* @noEscape */ $block->getAddressEditLink($order->getBillingAddress()); ?></div>

所以我的建议是覆盖此模板并向其添加一个 ViewModel 来处理您的自定义逻辑。我将在我的模块中执行此操作 - 供应商:透视图,名称:销售订单自定义

创建布局以覆盖模板 - app/code/Perspective/SalesOrderCustom/view/adminhtml/layout/sales_order_view.xml。您也可以在主题中执行此操作。

<?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="order_info"
template="Perspective_SalesOrderCustomization::order/view/info.phtml">
<arguments>
<argument name="view_model"
xsi:type="object">PerspectiveSalesOrderCustomizationViewModelOrderViewInfo</argument>
</arguments>
</referenceBlock>
</body>
</page>

将 info.phtml 复制到自定义模块 app/code/Perspective/SalesOrderCustom/view/adminhtml/templates/order/view/info.phtml

修改模板。 在开头添加(对我来说是第 30-31 行):

/** @var PerspectiveSalesOrderCustomizationViewModelOrderViewInfo $viewModel */
$viewModel = $block->getData('view_model');

修改编辑链接呈现:

/* Lines 175-177 */    
<?php if ($viewModel->isAddressEditAvailable($order->getStatus())): ?>
<div class="actions"><?= /* @noEscape */ $block->getAddressEditLink($order->getBillingAddress()); ?></div>
<?php endif; ?>
/* Lines 186-188 */
<?php if ($viewModel->isAddressEditAvailable($order->getStatus())): ?>
<div class="actions"><?= /* @noEscape */ $block->getAddressEditLink($order->getShippingAddress()); ?></div>
<?php endif; ?>

而我们的视图模型:

<?php

namespace PerspectiveSalesOrderCustomizationViewModelOrderView;

use MagentoFrameworkViewElementBlockArgumentInterface;
class Info implements ArgumentInterface
{
/**
* @param string $orderStatus
* @return bool
*/
public function isAddressEditAvailable($orderStatus)
{
if ($orderStatus === $this->getNotEditableStatus()) {
return false;
}
return true;
}
protected function getNotEditableStatus()
{
return 'complete';  /* todo: replace with Admin Configuration */
}
}

还要添加所需的文件(etc/modelu.xml,注册.php)。

下一步是清理缓存,启用模块,进行安装程序升级和di编译(如果需要)。

PS:您应该将静态状态声明替换为管理员 - 配置菜单(选择或多选)。

最新更新