2013-05-07 52 views
2

如何獲取hookdisplayTop中的當前產品?我怎樣才能得到一個鉤子內的當前產品?

這是當前的方法,我要確保我在 「產品」 頁面:

if (Dispatcher::getInstance()->getController() == "product") { 
    //i'm in the product page 
} 
+0

你到底什麼意思?你想檢測你是否在產品頁面,或者你想獲得當前的產品ID?請清楚,然後我會寫下你如何做到這一點。 – 2013-05-08 06:12:01

+0

如果我在產品頁面中,我想獲取當前產品對象。 – Eduardo 2013-05-08 18:02:35

回答

6

如果您在ProductController的是,你總是可以得到當前產品的PRODUCT_ID無需求助於倍率(如果過度使用這些可以迅速失控的,應該是最後的手段):

if ($id_product = (int)Tools::getValue('id_product')) 
    $product = new Product($id_product, 
          true, 
          $this->context->language->id, 
          $this->context->shop->id); 
if (!Validate:: isLoadedObject($product)) 
    return; 
0

解決:

class ProductController extends ProductControllerCore 
{ 
    public function getProduct() 
    { 
    return $this->product; 
    } 
} 
  1. 創建 「ProductController的」 的覆蓋(代碼如上)
  2. 在hook中調用:$ this-> context-> controller-> getProduct()