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

4

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> 
  • 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 ? – Mohd Alomar Oct 5 '14 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 '14 at 23:58
  • You should accept this answer. Not configuring the model is more critical than misspelling codePool, IMO. – musicliftsme Oct 6 '14 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. – Ecommerce Consultant Oct 6 '14 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 – Mohd Alomar Oct 6 '14 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> 
  • Lol, easy to miss, been there, especially when case in folder path is wrong. – ProxiBlue Oct 5 '14 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 '14 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>
  • why post an identical answer that was done 5 hours ago? – ProxiBlue Oct 6 '14 at 5:16
  • also this is wrong, as the namespace placed in the model is not SALES, but lemerge_sales. – ProxiBlue Oct 6 '14 at 5:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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