Context :: getContext()如何在Prestashop银行电汇模块中使用
问题描述:
我在银行电汇订单步骤中获取交付国家时遇到了一些问题。 我尝试modules/bankwire/bankwire.php
function __construct()
与Context::getContext();
GET国名这样的:Context :: getContext()如何在Prestashop银行电汇模块中使用
$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);
请你能告诉我怎样才能在bankwire得到国家的名字,我怎么可以使用右键::的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'…
我所需要的。
但问题为什么Context :: getContext()在bankwire.php中不起作用?仍然开放。如果有人有一个想法为什么Context::getContext()
不起作用,我想听听它。
谢谢。