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

时间:2015-09-18 12:31:47

标签: 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);

请告诉我如何在bankwire中获取国家/地区名称?如何使用Context :: getContext()?

由于

1 个答案:

答案 0 :(得分:1)

我发现我的错误在哪里。我应该编辑此文件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()不起作用,我希望听到它。

感谢。