0

I want to to extend the core model class Mage_Sales_Model_Quote_Item located in Mage/Sales/Model/Quote/Item.php I created this directory local/Lemerge/Sales/Model/Quote/Item.php

And I created the config.xml file in local/Lemerge/Sales/etc folder

<?xml version="1.0"?>
<config>
<modules>
    <Lemerge_Sales>
        <version>1.0.1</version>
    </Lemerge_Sales>
</modules>
<global>
   <models>
    <sales>
      <rewrite>
        <quote_item>Lemerge_Sales_Model_Quote_Item</quote_item>
      </rewrite>
    </sales>
   </models>
</global>
</config>

In app/etc/modules I created Lemerge_Sales.xml I don't know even if it necessary

<?xml version="1.0"?>
<config>  
<modules>  
    <Lemerge_Sales>  
        <active>true</active>  
        <codepool>local</codepool>  
    </Lemerge_Sales>  
</modules>  
</config> 

Then I override the setProudct() in Item.php

<?php
class Lemerge_Sales_Model_Quote_Item extends Mage_Sales_Model_Quote_Item
{
   public function setProduct($product)
   {
     //code 
   }
}

But it does not work magento is using the core file instead of the overrided file

3 Answers 3

5

you are missing the following in your config.xml

         <lemerge_sales>
            <class>Lemerge_Sales_Model</class>
        </lemerge_sales>

correct way:

<global>
   <models>
   <lemerge_sales>
        <class>Lemerge_Sales_Model</class>
    </lemerge_sales>
    <sales>
      <rewrite>
        <quote_item>Lemerge_Sales_Model_Quote_Item</quote_item>
      </rewrite>
    </sales>
   </models>
</global>

Also you are misspelling the coodPool in Lemerge_Sales.xml

<codePool>local</codePool>  

correct way:

<config>  
  <modules>  
   <Lemerge_Sales>  
     <active>true</active>  
     <codePool>local</codePool>  
   </Lemerge_Sales>  
  </modules>  
</config> 
5
  • Thanks to tell me the correct way I tried it, but didn't work then I saw the config I figured that I wrote codepool instead of codePool. but also it work without <class>Lemerge_Sales_Model</class> could you please write what will happen when if I wrote it or not ? Oct 5, 2014 at 23:48
  • 1
    You wont be able to instatiate any models in your extention. Thus mage::getModel('lemerge_sales') would not work
    – ProxiBlue
    Oct 5, 2014 at 23:58
  • You should accept this answer. Not configuring the model is more critical than misspelling codePool, IMO.
    – laketuna
    Oct 6, 2014 at 4:32
  • If this answer isn't working for you, then you need to delete the var/cache directory manually. That will completely refresh your system and this should begin working for you. Oct 6, 2014 at 5:01
  • 2
    @laketuna I will accept it, I will edit the answer to write about the misspelling codePool so people can know the whole thing Oct 6, 2014 at 15:22
1

I found a silly mistake that cost me more than 12 hours.

I wrote codepool instead of codePool

Editing Lemerge_Sales.xml to the code below solved the problem

<config>  
  <modules>  
    <Lemerge_Sales>  
       <active>true</active>  
       <codePool>local</codePool>  
    </Lemerge_Sales>  
  </modules>  
</config> 
2
  • Lol, easy to miss, been there, especially when case in folder path is wrong.
    – ProxiBlue
    Oct 5, 2014 at 23:59
  • I can't count the number of times I did this mistake. You would think I would learn after the first 15 times, but NO. I can hardly wait for Magento 2 to get rid of the code pools.
    – Marius
    Oct 6, 2014 at 5:50
-1

I think you have not define model in config.xml try this code

  <models>
     <sales>
         <class>Lemerge_Sales_Model</class>
     </sales>
 </models>

Change in config.xml

<?xml version="1.0"?>
<config>
<modules>
    <Lemerge_Sales>
         <version>1.0.1</version>
    </Lemerge_Sales>
</modules>
<global>
   <models>
     <sales>
         <class>Lemerge_Sales_Model</class>
     </sales>
    <sales>
       <rewrite>
         <quote_item>Lemerge_Sales_Model_Quote_Item</quote_item>
       </rewrite>
    </sales>
</models>
</global>
</config>
2
  • why post an identical answer that was done 5 hours ago?
    – ProxiBlue
    Oct 6, 2014 at 5:16
  • also this is wrong, as the namespace placed in the model is not SALES, but lemerge_sales.
    – ProxiBlue
    Oct 6, 2014 at 5:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.