2016-11-09 66 views
0

我在prestashop上有多層環境。如果郵政編碼不正確,我使用控制器創建了一個模塊來更改商店。當我使用Tools::redirect($newUrlToRedirect);重定向到我目前的商店時,問題就出現了,我需要它重定向到另一個商店。這是我的代碼:Prestashop控制器 - 更改Multistore上的當前商店

class cartportkeyDeriverModuleFrontController extends ModuleFrontController { 
    public function init(){ 
     //I am in the url http://localhost/shopgroup/shopnameCART/quick-order and 
     //check the postal code, then clicking a link I go to the URL 
     //http://localhost/shopgroup/shopnameNEW/index.php?fc=module&module=cartportkey&controller=deriver&id_cart=XXX&id_shop=YYY 
     parent::init(); 
     $id_cart = (int)Tools::getValue('id_cart'); 
     $id_shop = (int)Tools::getValue('id_shop'); 
     $this->context->cookie->id_cart = $id_cart; 
     $link_order = $this->context->link->getPageLink('order'); 
     $testShop = Context::getContext()->shop; 
     //HERE I OBTAIN THE storeOLD instead storeNEW so I am redirecting again to storeOLD 
     $testShop = json_decode(json_encode($testShop), true); 
     $newUrlToRedirect = "http://".$testShop['domain'].$testShop['physical_uri'].$testShop['virtual_uri'].'quick-order'; 
     //print $newUrlToRedirect; 
     $cart = new Cart(33); 
     $cart->delete(); 
     Tools::redirect($newUrlToRedirect); 
    } 
    public function initContent() { 
     parent::initContent(); 
    } 

} 

我已經在代碼中作了一些說明作爲註釋。問題是,我怎樣才能改變活躍的商店?

回答

0

我找到了自己的答案。而不是獲取上下文$testShop = Context::getContext()->shop;

更改該行:

$testShop = new Shop($id_shop); 
$testShop->getContext(); 

一切都很好。謝謝!