Aleksandr_A
Aleksandr_A

Reputation: 350

Context::getContext() how to use in Prestashop Bankwire module

I have some problem with getting delivery country on bankwire order step. I try in modules/bankwire/bankwire.php function __construct() with Context::getContext(); get country name like this:

$context = Context::getContext();
$this->context->smarty->assign('country_name', $context->country->name[1]);

and nothing. But in Cart.php it works fine with:

$context = Context::getContext();
if ($context->country->name[1] == 'Germany') {}

Also I try to get country name in same modules/bankwire/bankwire.php like this:

$context = Context::getContext();
$delivery = new Address($context->cart->id_address_delivery);
$this->context->smarty->assign('country_name', $delivery->country);

And get nothing too. But in ParentOrderController.php it works with:

$address = new Address($this->context->cart->id_address_delivery);
$this->context->smarty->assign('country_name', $address->country);

Please can you tell me how can I get country name in bankwire and how can I use Context::getContext()?

Thanks

Upvotes: 3

Views: 6512

Answers (1)

Aleksandr_A
Aleksandr_A

Reputation: 350

I've found where is my mistake. I should edit this file modules/bankwire/controllers/front/payment.php After this code:

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.'/'
    ));

I changed $this->context->smarty->assign('total'… to what I need.

But question Why Context::getContext() doesn't work in bankwire.php? is still open. If anyone have an idea why Context::getContext() doesn't work I would like to hear it.

Thanks.

Upvotes: 1

Related Questions