5

Hello I Have Created A Custom Module. In This Module I Have To Override Two Core Files.

And Do Some Changes in This FIles.

Path Is.

C:\xampp2\htdocs\mymagento\app\code\core\Mage\CatalogInventory\Model\Stock\Item.php C:\xampp2\htdocs\mymagento\app\code\core\Mage\CatalogInventory\Model\Observer.php

How To Do This? Pls Guide Me..

In The Core Observer File public function checkQuoteItemQty($observer) Function.

That Function I Have To Copy In My Custom module Observer.

Now, How Can I Override This Function in Config.xml?

Using Both The Observer File>

  • What specific methods do you want to override in these classes, or you want to override them all? Magento offers plugins and references, which, respectively, can be used for method and class rewriting. – Joel Apr 14 '17 at 7:00
  • actually, i do out of stock product, is placed an order. So remove validations from this two files, using override method – Rushikesh Solanki Apr 14 '17 at 7:03
3

app/etc/modules/SR_Example.xml

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

app/code/local/SR/Example/etc/config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <SR_Example>
      <version>0.1.0</version>
    </SR_Example>
  </modules>
  <global>
    <helpers>
      <example>
        <class>SR_Example_Helper</class>
      </example>
    </helpers>
    <models>
      <example>
        <class>SR_Example_Model</class>
        <resourceModel>example_mysql4</resourceModel>
      </example>
            <cataloginventory>
                <rewrite>
                    <stock_item>SR_Example_Model_CatalogInventory_Stock_Item</stock_item>
                </rewrite>
            </cataloginventory>
            <cataloginventory>
                <rewrite>
                    <observer>SR_Example_Model_CatalogInventory_Observer</observer>
                </rewrite>
            </cataloginventory>
    </models>
  </global>
</config> 

app/code/local/SR/Example/Helper/Data.php

class SR_Example_Helper_Data extends Mage_Core_Helper_Abstract
{
}

app/code/local/SR/Example/Model/CatalogInventory/Stock/Item.php

class SR_Example_Model_CatalogInventory_Stock_Item extends Mage_CatalogInventory_Model_Stock_Item
{
  // Your Override function
}

app/code/local/SR/Example/Model/CatalogInventory/Observer.php

class SR_Example_Model_CatalogInventory_Observer extends Mage_CatalogInventory_Model_Observer
{
   // Your Override function
}
  • When i override Observer in config.xml Product View Page Give Has Error. Fatal error: Call to a member function getQtyIncrements() on a non-object in C:\xampp2\htdocs\mymagento\app\code\core\Mage\CatalogInventory\Block\Qtyincrements.php on line 72 – Rushikesh Solanki Apr 14 '17 at 10:53
  • Fatal error: Call to a member function getIsInStock() on a non-object in C:\xampp2\htdocs\mymagento\app\code\core\Mage\Sales\Block\Reorder\Sidebar.php on line 103 – Rushikesh Solanki Apr 14 '17 at 11:41
1
<config>
    <global>
        <models>
            <tag>
                <rewrite>
                    <!-- Model -->
                    <tag>Inchoo_Tag_Model_Tag</tag>
                </rewrite>
            </tag>
            <tag_resource>
                <rewrite>
                    <!-- Resource -->
                    <tag>Inchoo_Tag_Model_Resource_Tag</tag>
                    <!-- Collection -->
                    <tag_collection>Inchoo_Tag_Model_Resource_Tag_Collection</tag_collection>
                </rewrite>
            </tag_resource>
        </models>
    </global>
</config>

this code override

app/code/local/Inchoo/Tag/Model/Tag.php
app/code/local/Inchoo/Tag/Model/Resource/Tag.php
app/code/local/Inchoo/Tag/Model/Resource/Tag/Collection.php.

change it with your file to work in your module

0

The most easy solution is to copy them to your local fold and make the changes there. In your case:

C:\xampp2\htdocs\mymagento\app\code\local\Mage\CatalogInventory\Model\Stock\Item.php C:\xampp2\htdocs\mymagento\app\code\local\Mage\CatalogInventory\Model\Observer.php

  • But How To Override it in config.xml that process i don't know – Rushikesh Solanki Apr 14 '17 at 7:15
  • Basically you write a custom module that extends default Magento code. In your module you can specify which methods you want to rewrite. More info in this great article: inchoo.net/magento/… – Niels Apr 14 '17 at 7:32

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.