Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How to overload a Class in app/core/Mage/<Module>/Model? 
 
alanin
Member
 
Total Posts:  67
Joined:  2008-02-25
Nordhausen, Germany
 

Hi there,

i am trying to customize some code, and i were able to get my own files loaded, but just when i try to rewrite the methods for a block.
But i am not able to get my cusomized files under local/MyCompany/Catalog/Model loaded.

I tried alot, but i can figure it out.
Please help me.

this is the part in my local.xml

...
<
modules>
  <
BC_Catalog>
    <
active>true</active>
    <
codePool>local</codePool>
  </
BC_Catalog>
</
modules>
<
blocks>
  <
catalog>
    <
rewrite>
      <!-- 
this works -->
      <
breadcrumbs>BC_Catalog_Block_Breadcrumbs</breadcrumbs>
    </
rewrite>
  </
catalog>
</
blocks>
<
models>
  <
catalog>
   <
rewrite>
      <!-- 
i am not sure what to rewrite and if this works in general -->
      
<???>BC_Catalog_Model_Product</???>
    
</rewrite>
  </
catalog>
</
models>...

Thanks for help.
Alanin // Jörg

 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

Hi,

id did it this way, Moshe gave me the needed hints

<models>
      <!-- 
model group alias to be used in Mage::getModel() -->
      <
heidelpaydebitadvice>
        <!-- 
base class name for the model group -->
        <class>
Mage_Heidelpaydebitadvice_Model</class> 
      </
heidelpaydebitadvice>
      <
sales>
            <
rewrite>
               <
convert_order>Mage_Heidelpaydebitadvice_Model_Convert_Order</convert_order>
               <
convert_quote>Mage_Heidelpaydebitadvice_Model_Convert_Quote</convert_quote>
            </
rewrite>
      </
sales>
    </
models>

I overwrite model sales/model/convert/order and sales/model/convert/quote with my model in folder heidelpaydebitadvice/model/convert/order and .../model/convert/quote

I think for you it would be

<models>
  <
catalog>
   <
rewrite>
      <!-- 
i am not sure what to rewrite and if this works in general -->
      <
product>BC_Catalog_Model_Product</product>
    </
rewrite>
  </
catalog>
</
models>

Hope that helps, my english is too bad to explain more abstract, sorry for that.

 
Magento Community Magento Community
Magento Community
Magento Community
 
alanin
Member
 
Total Posts:  67
Joined:  2008-02-25
Nordhausen, Germany
 

thank you - i am going to try this

Alanin // Jörg

PS: from Germany aswell smile

edit: OMG it worked - woohooooo
Thank you so much. I could bet i’ve tried that, but it was very late the last few days wink

Woohoo, that rox!

 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

Hi,

welcome my deutscher kollege smile

Grüsse

 
Magento Community Magento Community
Magento Community
Magento Community
 
alanin
Member
 
Total Posts:  67
Joined:  2008-02-25
Nordhausen, Germany
 

i think i found out how to do that…

hope that picture explains abit...its kinda obvious, but i think its way to easy to find out myself wink

someone had to poke me to see it…

Image Attachments
local.xml.png
 
Magento Community Magento Community
Magento Community
Magento Community
 
nicolas46
Sr. Member
 
Total Posts:  210
Joined:  2008-04-09
Toulouse
 

I want to overload the method process() from the class Mage_SalesRule_Model_Validator so I create this:

Local/MyFirm/SalesRule/etc/config.xml
Local/MyFirm/SalesRule/Model/Validator.php
Etc/modules/MyFirm_All.xml

Config.xml :

<?xml version="1.0" ?>
<config>
    <
modules>
        < 
MyFirm _SalesRule>
            <
version>0.0.1</version>
        </ 
MyFirm _SalesRule>
    </
modules>
    <global>
    <
models>
        <
salesRule>
        <
rewrite>
               <
validator>MyFirm_SalesRule_Model_Validator</validator>
           </
rewrite>
     </
salesRule>
    </
models>
    </global>
</
config>

Validator.php

<?php
require_once 'Mage/SalesRule/Model/Validator.php';
class 
MyFirm_SalesRule_Model_Validator extends Mage_SalesRule_Model_Validator{
    
    
public function process(Mage_Sales_Model_Quote_Item_Abstract $item)
    
{        ?>
                
<script type="text/javascript">
                <!--
                
alert("It’working !!!   :)");
                
//-->
                
</script>
            <?php    
    }
}

MyFirm_All.xml :

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

I don’t understand why it’s doesn’t work. Any ideas?

 
Magento Community Magento Community
Magento Community
Magento Community
 
glaDiator
Member
 
Avatar
Total Posts:  65
Joined:  2008-03-17
 

<salesRule>
        <
rewrite>
               <
validator>MyFirm_SalesRule_Model_Validator</validator>
           </
rewrite>
</
salesRule>

change it to......

<SalesRule>
        <
rewrite>
               <
validator>MyFirm_SalesRule_Model_Validator</validator>
           </
rewrite>
</
SalesRule>

just change salesRule ----> SalesRule

i am not sure weather this is only the problem..... wink

Let me know if it works........

 
Magento Community Magento Community
Magento Community
Magento Community
 
nicolas46
Sr. Member
 
Total Posts:  210
Joined:  2008-04-09
Toulouse
 

Thanks a lot for your answer but it’s doesn’t work :(

 
Magento Community Magento Community
Magento Community
Magento Community
 
glaDiator
Member
 
Avatar
Total Posts:  65
Joined:  2008-03-17
 

sorry....but i cant find any other problem blank stare
Just for clarifiacation....where is the MyFirm folder ?… it should be in /app/code/local

 
Magento Community Magento Community
Magento Community
Magento Community
 
nicolas46
Sr. Member
 
Total Posts:  210
Joined:  2008-04-09
Toulouse
 

Thanks for trying to help me surprised
I confirm MyFirm folder is in app/code/local

 
Magento Community Magento Community
Magento Community
Magento Community
 
nicolas46
Sr. Member
 
Total Posts:  210
Joined:  2008-04-09
Toulouse
 

I found the solution on an other forum : i just need to change salesRule ----> salesrule

 
Magento Community Magento Community
Magento Community
Magento Community
 
glaDiator
Member
 
Avatar
Total Posts:  65
Joined:  2008-03-17
 

hmm ..... just the reverse of what i guessed cool smirk

 
Magento Community Magento Community
Magento Community
Magento Community
 
NafeX
Member
 
Total Posts:  47
Joined:  2007-12-18
 

How do I OVERwrite the function _getDefaultCollection($sorted=false) in app\code\core\Mage\Catalog\Model\Resource\Eav\Mysql4\Category\Tree.php?

This code in my config.xml file don’t work…

<models>
    <
catalog>
        <
rewrite>
            <
tree>Rove_NewNavigation_Model_Tree</tree>
        </
rewrite>
    </
catalog>
</
models>

and this don’t work too:

<catalog>
    <
rewrite>
        <
resource_eav_mysql4_category_tree>Rove_NewNavigation_Model_Resource_Eav_Mysql4_Category_Tree</resource_eav_mysql4_category_tree>
    </
rewrite>
</
catalog>

Please help
Thank you

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top