我已经创建了一个自定义模块。通过创建自定义模块来重写\ Magento \ Checkout \ Block \ Onepage \ Success类。
我可以在prepareBlockData函数中进行更改,但是我想在成功块构造函数中注入自定义模块的帮助程序类,这是我尝试过的代码。
<?php
namespace Test\Buynow\Block\Magento\Checkout\Onepage;
use Magento\Customer\Model\Context;
use Magento\Sales\Model\Order;
class Success extends \Magento\Checkout\Block\Onepage\Success
{
protected $_checkoutSession;
protected $_orderConfig;
protected $httpContext;
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Sales\Model\Order\Config $orderConfig,
\Magento\Framework\App\Http\Context $httpContext,
\Test\Buynow\Helper\Buynow $buynowHelper, //custom module helper class which i want to inject
array $data = []
) {
parent::__construct($context, $data);
$this->_checkoutSession = $checkoutSession;
$this->_orderConfig = $orderConfig;
$this->_isScopePrivate = true;
$this->httpContext = $httpContext;
$this->buynow = $buynowHelper; //custom module helper class which i want to inject
}
protected function prepareBlockData()
{
$order = $this->_checkoutSession->getLastRealOrder();
$isReference= false;
if($order->getReference()):
$isReference = true;
endif;
$this->addData(
[
'is_order_visible' => $this->isVisible($order),
'view_order_url' => $this->getUrl(
'sales/order/view/',
['order_id' => $order->getEntityId()]
),
'print_url' => $this->getUrl(
'sales/order/print',
['order_id' => $order->getEntityId()]
),
'can_print_order' => $this->isVisible($order),
'can_view_order' => $this->canViewOrder($order),
'order_id' => $order->getIncrementId(),
'reference'=> $isReference
]
);
}
}
执行完此操作后,我已经刷新了缓存并部署了静态内容,但是我遇到了错误。
PHP致命错误:未捕获的TypeError:参数2传递给 Magento \ Checkout \ Block \ Onepage \ Success :: __ construct()必须是 Magento \ Checkout \ Model \ Session的实例,