2016-11-09 11 views
0

私は、プレストトップにマルチストア環境を持っています。私は、郵便番号が正しくない場合、店舗を変更するコントローラを備えたモジュールを作成しました。問題は私がTools::redirect($newUrlToRedirect);を使って私の現在の店にリダイレクトしたときに来て、別の店にリダイレクトする必要があります。これは私のコードです:Prestashop Controller - マルチストアの現在の店舗を変更する

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 = new Shop($id_shop); 
$testShop->getContext(); 

すべて:代わりのため$testShop = Context::getContext()->shop;

変更でその行をコンテキストを取得します。ありがとう!

関連する問題