2014-01-12 49 views
0

我想在Magentos產品/自定義選項區域中構建自定義輸入字段。我開始寫一個新的模塊。 在 「等/模塊」 我創建 「Pi_Customize.xml」Magento無效塊類型

<?xml version="1.0"?> 
<config> 
    <modules> 
     <Pi_Customize> 
      <active>true</active> 
      <codePool>local</codePool> 
     </Pi_Customize> 
    </modules> 
</config> 

在 「應用程序/代碼/本地/ etc」 我創建了 「config.xml中」

<?xml version="1.0"?> 
<config> 
    <modules> 
     <Pi_Customize> 
      <version>0.1</version> 
     </Pi_Customize> 
    </modules> 
    <global> 
     <catalog> 
      <product> 
       <options> 
        <custom> 
         <groups> 
          <custom translate="label" module="customize"> 
           <label>Custom Stuff</label> 
           <render>customize/adminhtml_catalog_product_edit_tab_options_type_custom</render> 
           <types> 
            <custom_type translate="label" module="customize"> 
             <label>Custom Text</label> 
            </custom_type> 
           </types> 
          </custom> 
         </groups> 
        </custom> 
       </options> 
      </product> 
     </catalog> 
    </global> 
</config> 

當我在重新加載後端/產品/自定義選項中我看到新添加的字段,但我得到一個錯誤:

exception 'Mage_Core_Exception' with message 'Invalid block type: Mage_Customize_Block_Adminhtml_Catalog_Product_Edit_Tab_Options_Type_custom' in /home/michi/www/magento/app/Mage.php:595 

我試圖約4小時左右,而不能讓它TOR工作。爲什麼Magento試圖加載「mage」而不是「pi/customize」。文件夾結構應該如何看起來像? B:「Block/catalog ...」
C:另一個?

回答

2

你的文章缺乏一些上下文,目前還不清楚你認爲上述應該做什麼,因此很難完全解決你的問題。

這就是說,你的配置表明要使用以下塊類作爲渲染

<render>customize/adminhtml_catalog_product_edit_tab_options_type_custom</render> 

這意味着Magento的將嘗試實例化一個customize/adminhtml_catalog_product_edit_tab_options_type_custom塊類。在股票Magento系統中沒有customize塊名稱空間,並且您沒有通過您的配置添加一個塊名稱空間。這意味着customize/adminhtml_catalog_product_edit_tab_options_type_custom對應於PHP類

Mage_Customize_Helper_Adminhtml_Catalog_Product_Edit_Tab_Options_Type_Custom 

這個類沒有在Magento存在,你會得到你的錯誤。

雖然你的錯誤也很好奇。小寫自定義(Options_Type_custom)使您看起來好像還有其他事情在您的問題中未提及。

+0

同樣的錯誤也。 Magento也將這些標籤作爲類名的一部分。當我刪除標籤時,它工作正常。錯誤是:異常'Mage_Core_Exception'帶有消息'無效塊類型: Kaushikamdotcom_Pay_Block_History 'in /var/www/kaushikam/magento/app/Mage.php:595 – kaushik

2

感謝您的幫助,我改變了我的config.xml中,像這樣:

<config> 
    <modules> 
     <Pi_Customize> 
      <version>0.1</version> 
     </Pi_Customize> 
    </modules> 
    <global> 
     <blocks> 
      <adminhtml> 
       <rewrite> 
        <catalog_product_edit_tab_options_option> 
         Pi_Customize_Block_Adminhtml_Catalog_Product_Edit_Tab_Options_Option 
        </catalog_product_edit_tab_options_option> 
       </rewrite> 
      </adminhtml> 
      <customize> 
       <class>Pi_Customize_Block</class> 
      </customize> 
     </blocks> 
     <catalog> 
      <product> 
       <options> 
        <custom> 
         <groups> 
          <customize translate="label" module="customize"> 
           <label>Customized Input</label> 
           <render>customize/adminhtml_catalog_product_edit_tab_options_type_customized</render> 
           <types> 
            <customize_type translate="label" module="customize"> 
             <label>custom</label> 
            </customize_type> 
            <!-- the second one 
            <customizedue_type translate="label" module="customize"> 
             <label>due</label> 
            </customizedue_type> 
            --> 
           </types> 
          </customize> 
         </groups> 
        </custom> 
       </options> 
      </product> 
     </catalog> 
    </global> 
</config> 

現在我得到錯誤 「無效塊類型:Pi_Customize_Block_Adminhtml_Catalog_Product_Edit_Tab_Options_Option」。但我的文件存儲在:「app/code/local/Pi/Customize/Block/Adminhtml/Catalog/Product/Edit/Tab/Options/Option.php」。我不知道我做錯了什麼?

編輯: 我發現了錯誤,我輸入

<adminhtml> 
    <rewrite> 
     <class_to_override> 
      my_class 
     </class_to_override> 
    </rewrite> 
</adminhtml> 

,但它必須是:發生在我身上

<adminhtml> 
    <rewrite> 
     <class_to_override>my_class</class_to_override> 
    </rewrite> 
</adminhtml>