我正在为Prestashop 1.7创建一个paymentmodule,我正在尝试使用钩子DisplayPaymentByBinaries,因为我无法使用提交按钮。
下面你会找到我的代码:
public function hookDisplayPaymentByBinaries()
{
if (!Currency::exists('EUR', 0))
{
return '<p class="payment_module" style="color:red;">' .
$this->l('Payment Methods are only available when Euros are activated.') .
'</p>';
}
$issuer_setting = $this->getConfigValue('MY_ISSUERS');
try {
$methods = $this->api->methods->all();
$issuer_list = in_array($issuer_setting, array(self::ISSUERS_ALWAYS_VISIBLE, self::ISSUERS_ON_CLICK)) ? $this->_getIssuerList() : array();
} catch (MY_API_Exception $e) {
$methods = array();
$issuer_list = array();
if ($this->getConfigValue('MY_DEBUG_LOG') == self::DEBUG_LOG_ERRORS)
{
Logger::addLog(__METHOD__ . ' said: ' . $e->getMessage(), My::ERROR);
}
if ($this->getConfigValue('MY_DISPLAY_ERRORS'))
{
return
'<p class="payment_module" style="color:red;">' .
$e->getMessage() .
'</p>'
;
}
}
$this->setBinary = true;
$this->smarty->assign(array(
'methods' => $methods,
'issuers' => $issuer_list,
'issuer_setting' => $issuer_setting,
'images' => $this->getConfigValue('MY_IMAGES'),
'warning' => $this->warning,
'msg_pay_with' => $this->lang['Pay with %s'],
'msg_bankselect' => $this->lang['Select your bank:'],
'module' => $this,
));
return $this->display(__FILE__, 'my_methods.tpl');
}
正如您在上面所读到的,您不能在模块的HTML代码中有一个提交按钮,因为PrestaShop会自动生成它。如果由于某些原因(例如:表单由二进制文件生成)无法从表单中删除提交按钮,我们已经实现了另一种方法来使您的模块PrestaShp 1.7兼容。但请注意,这不是推荐的方法。
为此,您需要实现一个补充钩子:displayPaymentByBinaries。它用于显示付款表单,它将替换结帐中的唯一付款按钮。
我已经实现了我的代码,我的付款选项正在显示,但提交按钮仍然存在。正如你在我的函数中看到的,我使用了:
$this->setBinary = true;
在我添加的文件的标题中:
use PrestaShop\PrestaShop\Core\Payment\PaymentOption;
我调用的setBinary函数(来自paymentoption文件):
public function setBinary($binary)
{
$this->binary = $binary;
return $this;
}
有人可以帮我解决我在这里做错了什么吗?换句话说,我必须更改什么才能删除提交按钮?
事先谢谢大家。
由于@UnLoCo,下面是我工作的awnser。
public function hookPaymentOptions($params)
{
if (!Currency::exists('EUR', 0))
{
return;
}
try {
$methods = $this->api->methods->all();
} catch (My_API_Exception $e) {
$methods = array();
if ($this->getConfigValue('My_DEBUG_LOG') == self::DEBUG_LOG_ERRORS)
{
Logger::addLog(__METHOD__ . ' said: ' . $e->getMessage(), My::ERROR);
}
return;
}
$payment_options = array();
foreach($methods as $method)
{
$newOption = new PaymentOption();
$newOption->setBinary(true);
$payment_options[] = $newOption;
}
return $payment_options;
}
答案 0 :(得分:1)
解决方案是在返回的付款选项中将二进制设置为true
public function hookPaymentOptions($params)
{
//...
$payment_option = new PaymentOption();
$payment_option->setBinary(true);
return array(
$payment_option
);
}