2015-09-18 72 views
3

我在銀行電匯訂單步驟中獲取交付國家時遇到了一些問題。 我嘗試modules/bankwire/bankwire.phpfunction __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()?

謝謝

回答

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()不起作用,我想聽聽它。

謝謝。