magento - 如何从销售订单详细信息页面的地址信息块中删除/禁用编辑按钮
问题描述
根据特定的订单状态,我想限制用户更改订单地址,即
我想从地址信息块中禁用或删除帐单和送货地址中的编辑按钮
请检查下面的图片
解决方案
首先,您需要找到负责销售订单视图页面这一部分的模板。您可以通过在Admin-Stores-Configuration-Advanced-Developer-Debug中启用模板调试来做到这一点
这是我们需要的模板 - vendor/magento/module-sales/view/adminhtml/templates/order/view/info.phtml
在第 172 和 181 行,我们有编辑链接渲染
<div class="actions"><?= /* @noEscape */ $block->getAddressEditLink($order->getBillingAddress()); ?></div>
所以我的建议是覆盖这个模板并添加一个 ViewModel 来处理你的自定义逻辑。我将在我的模块中执行此操作 - 供应商:透视,名称:SalesOrderCustomization
创建布局以覆盖模板 - app/code/Perspective/SalesOrderCustomization/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">\Perspective\SalesOrderCustomization\ViewModel\Order\View\Info</argument>
</arguments>
</referenceBlock>
</body>
</page>
将 info.phtml 复制到自定义模块 app/code/Perspective/SalesOrderCustomization/view/adminhtml/templates/order/view/info.phtml
修改模板。在开头添加(对我来说是第 30-31 行):
/** @var \Perspective\SalesOrderCustomization\ViewModel\Order\View\Info $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; ?>
还有我们的 ViewModel:
<?php
namespace Perspective\SalesOrderCustomization\ViewModel\Order\View;
use Magento\Framework\View\Element\Block\ArgumentInterface;
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、registration.php)。
下一步是清理缓存、启用模块、进行安装升级和编译(如果需要)。
PS:您应该用管理员 - 配置菜单(选择或多选)替换静态状态声明。
推荐阅读
- javascript - 如何连接多条贝塞尔曲线?
- r - R Rstudio 使用来自多台计算机的 Git(未启用拉/按钮)
- ruby-on-rails - 参数数量错误(给定 1,预期为 0) - CommerceController#receive 中的 ArgumentError
- php - 只返回没有 html 标签的 php 数据
- mysql - 创建每个值最多出现一次的表
- c - 等待另一个进程
- java - JEXL:如何自定义属性访问器
- php - 如何使用 Codeigniter 框架自动生成代码?为会员卡生成会员号的示例
- python - VSCode在python中调试期间忽略断点
- discord - 我可以从消息中过滤号码吗?