我在银行电汇订单步骤中获取交货国家时遇到了一些问题。
我在 modules/bankwire/bankwire.php
function __construct()
中尝试使用 Context::getContext();
获取国家名称,如下所示:
$context = Context::getContext();
$this->context->smarty->assign('country_name', $context->country->name[1]);
什么也没有。但在 Cart.php 中,它适用于:
$context = Context::getContext();
if ($context->country->name[1] == 'Germany') {}
我也尝试在相同的 modules/bankwire/bankwire.php
中获取国家名称,如下所示:
$context = Context::getContext();
$delivery = new Address($context->cart->id_address_delivery);
$this->context->smarty->assign('country_name', $delivery->country);
也一无所获。但在 ParentOrderController.php
中,它适用于:
$address = new Address($this->context->cart->id_address_delivery);
$this->context->smarty->assign('country_name', $address->country);
你能告诉我如何在银行电汇中获取国家名称以及如何使用 Context::getContext() 吗?
谢谢
最佳答案
我发现我的错误在哪里了。我应该编辑这个文件 modules/bankwire/controllers/front/payment.php
在这段代码之后:
public function initContent()
{
parent::initContent();
$cart = $this->context->cart;
if (!$this->module->checkCurrency($cart))
Tools::redirect('index.php?controller=order');
$this->context->smarty->assign(array(
'nbProducts' => $cart->nbProducts(),
'cust_currency' => $cart->id_currency,
'currencies' => $this->module->getCurrency((int)$cart->id_currency),
'total' => $cart->getOrderTotal(true, Cart::BOTH),
'this_path' => $this->module->getPathUri(),
'this_path_bw' => $this->module->getPathUri(),
'this_path_ssl' => Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/'.$this->module->name.'/'
));
我将 $this->context->smarty->assign('total'…
更改为我需要的内容。
但是问题Why Context::getContext() doesn't work in bankwire.php? 仍然是开放的。如果有人知道为什么 Context::getContext()
不起作用,我想听听。
谢谢。
关于php - Context::getContext() 如何在 Prestashop Bankwire 模块中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32652120/