KRay
KRay

Reputation: 71

Magento Third Party Model Override

I am attempting to override only one portion of a third party extensions Model (the "Userprofile" functionality) to include a few more columns and calls to retrieve the new info. Here is the third party config.xml:

<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>

Here is my own 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>

I've copied over all of the Userprofile documents into my Model structure exactly as they are in the original extension with the exception of replacing the "marketplace" namespace with my own:

<?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);

....

However I am still getting a "Fatal error: Call to a member function getCollection() on a non-object in /home/devzerob/public_html/app/code/local/ZeroBars/Marketplacepayment/Model/Userprofile.php on line 14"

The error is originating in the $collection line of the PHP file. Am I missing anything? Do I need to do any overriding in the section of the config?

Upvotes: 0

Views: 1225

Answers (1)

Rajeev K Tomy
Rajeev K Tomy

Reputation: 2214

In you model file, through which you are intending to rewrite a custom model extension, has some problems. I will notice you what are the main problem that I can see now.

  • Model extends wrong class

    Your model class now extending class Mage_Core_Model_Abstract, which in your case is wrong you need to extend Webkul_Marketplace_Model_Userprofile. This is because you are overwriting this class. So it is essential that you custom class should inherit from this class itself.

  • Referencing to a wrong model

    Now model collection is carried out by this code snippet

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

    This tells to magento that, hey magento I need all data collection from the model ZeroBars_Marketplacepayment_Model_Userprofile. This method definitely raise an error, since this model refers to your module and does not contain any collection,resources(I assumes so). So you may probably need to use

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

    Now the collection refers to Webkul_Marketplace_Model_Userprofile and it does have a collection,resources defined. I also hope that mageuserid is defined by this module itself.

  • What you can do ?

In your question, you mentioned that, you need to add some extra column fields to custom tables. For that you need to use some upgrade scripts. Some reference for this is given here 1, 2. You may get more tutorials out there.

Thanks

Upvotes: 1

Related Questions