2014-06-23 210 views
0

我試圖覆蓋第三方擴展模型(「Userprofile」功能)的一部分,以包含更多的列和調用來檢索新的信息。這是第三方的config.xml:Magento第三方模型覆蓋

<models> 
      <marketplace> 
       <class>Webkul_Marketplace_Model</class> 
       <resourceModel>marketplace_mysql4</resourceModel> 
      </marketplace> 
      <marketplace_mysql4> 
       <class>Webkul_Marketplace_Model_Mysql4</class> 
       <entities> 
        <product> 
         <table>marketplace_product</table> 
        </product> 
        <userprofile> 
         <table>marketplace_userdata</table> 
        </userprofile> 
        <feedback> 
         <table>marketplace_datafeedback</table> 
        </feedback> 
        <saleperpartner> 
         <table>marketplace_saleperpartner</table> 
        </saleperpartner> 
        <saleslist> 
         <table>marketplace_saleslist</table> 
        </saleslist> 
       </entities> 
      </marketplace_mysql4> 
     </models> 

這是我自己的config.xml:

<models> 
      <zerobars_marketplacepayment> 
       <class>ZeroBars_Marketplacepayment_Model</class> 
     </zerobars_marketplacepayment> 


      <marketplace> 
       <rewrite> 
        <userprofile>ZeroBars_Marketplacepayment_Model_Userprofile</userprofile> 
       </rewrite> 
      </marketplace> 
      <marketplace_mysql4> 
       <rewrite> 
        <userprofile>ZeroBars_Marketplacepayment_Model_Mysql4_Userprofile</userprofile> 
        <userprofile_collection>ZeroBars_Marketplacepayment_Model_Mysql4_Userprofile_Collection</userprofile_collection> 
       </rewrite> 
      </marketplace_mysql4> 

     </models> 

我複製所有文件USERPROFILE到我的模型結構,正是因爲他們在原分機與我自己取代「市場」命名的除外:

<?php 
class ZeroBars_Marketplacepayment_Model_Userprofile extends Mage_Core_Model_Abstract 
{ 
    public function _construct() 
    { 
     parent::_construct(); 
     $this->_init('zerobars_marketplacepayment/userprofile'); 

    } 

    public function getPartnerProfileById($partnerId) { 
     $data = array(); 
     if ($partnerId != '') { 
      $collection = Mage::getModel('zerobars_marketplacepayment/userprofile')->getCollection(); 
      $collection->addFieldToFilter('mageuserid',array('eq'=>$partnerId)); 
      $user = Mage::getModel('customer/customer')->load($partnerId); 

.... 

但是我仍然得到一個「致命錯誤:調用一個成員函數getCollection()在非OB ject in /home/devzerob/public_html/app/code/local/ZeroBars/Marketplacepayment/Model/Userprofile.php on line 14「

該錯誤源於PHP文件的$ collection行。我錯過了什麼?我需要在配置部分中進行任何重寫嗎?

+0

它發生,我認爲我可能需要在此更加緊密地看後添加相應的

線到我的配置。有沒有關於如何做的好文章? – KRay

回答

1

在您打算重寫自定義模型擴展的模型文件中存在一些問題。我會注意到你現在看到的主要問題是什麼。

  • 模型擴展錯誤的類

    你的模型類現在繼承類Mage_Core_Model_Abstract,而你的情況是錯誤的,你需要擴展Webkul_Marketplace_Model_Userprofile。這是因爲你正在覆蓋這門課。所以自定義類應該從這個類本身繼承是至關重要的。

  • 引用到一個錯誤的模型

    現在模型集合由此代碼片段

    $collection = Mage::getModel('zerobars_marketplacepayment/userprofile')->getCollection(); 
    

    這告訴給Magento的那個進行,哎Magento的我需要的所有數據收集從模型ZeroBars_Marketplacepayment_Model_Userprofile 。這個方法肯定會引發一個錯誤,因爲這個模型引用了你的模塊,並且不包含任何集合,資源(我假設如此)。所以,你可能會需要使用

    $collection = Mage::getModel('marketplace/userprofile')->getCollection(); 
    

    現在收集是指Webkul_Marketplace_Model_Userprofile它確實有一個集合,資源定義。我也希望mageuserid是由這個模塊本身定義的。

  • 你可以做什麼?

在你的問題,你提到的是,你需要一些額外的列字段添加到自定義表。爲此,您需要使用一些升級腳本。這裏給出一些參考文獻12。你可能會在那裏獲得更多的教程。

感謝

+0

非常感謝你programmer_rkt!我確實編寫了一個工作正常的升級腳本,以便部分得到照顧。我缺少的重要部分是「擴展擴展」部分。現在一切都很好,我欠你一杯虛擬咖啡或什麼。 :-) – KRay

+0

接受你的咖啡! –