2017-02-21 27 views
0

我正在開發一個項目magento,我試圖在主導航欄中列出一個菜單項。在這個模型中有一個observer。我所要做的是使用現有的觀察者添加另一個菜單項。爲此,我創建了一個功能:當在config.xml中添加兩個項目以顯示導航時。爲什麼它只顯示一個?

class Color_Observer{ 
    // Existing function for "colors" menu item. 
    public function ListMenuItems(){ 
     //code here 
    } 

    // New function for "composite colors" menu item 
    public function MyListMenuItems(){ 
     // 
    } 
} 

,我在​​3210

<frontend> 
     <events> 
     <page_block_html_topmenu_gethtml_before> 
      <observers> 
       <my_color> 
        <class>my_color/observer</class> 
        <method>ListMenuItems</method> 
       </my_color> 
       <my_color_val> 
        <class>my_color/observer</class> 
        <method>MyListMenuItems</method> 
       </my_color_val> 
      </observers> 
     </page_block_html_topmenu_gethtml_before> 
     </events> 
</frontend> 

添加以下代碼此代碼成功創建菜單composite colors,但它取代了現有的color菜單。

任何人都可以請幫助我怎麼回事?我是magento的新手。

+0

嘗試鏈接我希望你的問題可能會解決。 http://inchoo.net/ecommerce/adding-links-to-the-top-menu-in-magento/ – user247217

回答

0

添加觀察者型<type>singleton</type>

<frontend> 
     <events> 
     <page_block_html_topmenu_gethtml_before> 
      <observers> 
       <my_color> 
        <class>my_color/observer</class> 
        <type>singleton</type> 
        <method>ListMenuItems</method> 
       </my_color> 
       <my_color_val> 
        <class>my_color/observer</class> 
        <type>singleton</type> 
        <method>MyListMenuItems</method> 
       </my_color_val> 
      </observers> 
     </page_block_html_topmenu_gethtml_before> 
     </events> 
</frontend> 
相關問題