php - Context::getContext() 如何在 Prestashop Bankwire 模块中使用

标签 php oop module smarty prestashop-1.6

我在银行电汇订单步骤中获取交货国家时遇到了一些问题。 我在 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/

相关文章:

php - 缓慢的 MySQL 查询 - 将数据缓存在 PHP 数组中?

php - mysql_field_name() 期望参数 1 是资源,

php - 使用for循环在php中生成sql查询

c - linux/init.h : No such file or directory

python - 从 Python 中的模块导入特定函数的要点

php - 是否有禁用 "cannot use temporary expression in write context"错误的开关?

java - 在 Java 中创建对象时避免使用 'new' 关键字的好处

java - 如何优化参数

c++ - 由类析构函数完成的同步

module - 如何制作一个其元素是函数的矩阵,对它们进行运算并且结果仍然是函数?