php - 如何获取外键值并在 Magento 2 的运输和处理信息中显示?
问题描述
我想在管理面板中获取并显示外键值Order > Individual Order > Shipping and Handling Information
。我有两个相互连接的表。即order_sales
(具有stockid_id
链接到的外键collect_in_store
)和collect_in_store
(具有名称的商店列表)。
Company/Module/Block/Adminhtml/Order/View/Custom.php
-
<?php
namespace Company\Module\Block\Adminhtml\Order\View;
class Custom extends \Magento\Framework\View\Element\Template
{
protected $orderRepository;
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
array $data = []
) {
$this->orderRepository = $orderRepository;
parent::__construct($context, $data);
}
public function checkCollectInStore(){
$orderId = $this->getRequest()->getParam('order_id');
$order = $this->orderRepository->get($orderId);
return $order;
}
}
Company/Module/view/adminhtml/layout/sales_order_view.xml
referenceContainer
- 这里的运输块下应该显示什么名称?
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="right">
<referenceContainer name="shipping_info"> //This should be under Shipping block
<block class="Company\Module\Block\Adminhtml\Order\View\Custom" name="sales_order_view_collect_in_store" template="order/view/custom.phtml" />
</referenceContainer>
</referenceContainer>
</body>
</page>
Company/Module/view/adminhtml/templates/order/view/custom.phtml
-
<?php
$check = $block->checkCollectInStore();
$shippingCode = $check->getShippingMethod();
if($shippingCode === 'collectinstore_collectinstore'){
echo 'Collect In Store: '.$check->getStockistId(); //getting id but need to display shop name.
}
?>
现在有了这个代码,我得到stockist_id
但需要显示名称,它应该在详细订单页面的运输块下。如何解决这个问题?
解决方案
推荐阅读
- azure - az login 在“az account clear”之后未列出订阅
- reactjs - 如何使用 Reactjs 在表格中显示数组对象
- android - Android不支持链接电话(Expo react native)
- javascript - 禁用先前时间的时间范围选择框和 javascript
- python - PrettyTable 初始化了超过 1 个变量
- python - 使用 Spark 进行大数据分析
- javascript - 有没有办法在页面完全加载之前显示加载动画?
- pandas - 从另一个数据帧更新数据帧,但仅在值发生变化的情况下
- python - Z3 可以解决 MILP 优化问题吗?能输出top N最好的结果吗?
- python - python动态创建字典