I need to override class Mage_Paypal_Model_Ipn.
class Budsies_Budsie_Paypal_Model_Ipn extends Mage_Paypal_Model_Ipn
{
protected function _processOrder()
{
Mage::log('Budsies_Budsie_Paypal_Model_Ipn', null, 'processOrder.log');
$orderState = $this->_order->getState();
if ($orderState != Mage_Sales_Model_Order::STATE_COMPLETE &&
$orderState != Mage_Sales_Model_Order::STATE_HOLDED) {
parent::_processOrder();
}
}
}
I added config.xml to my module в global section:
<global>
<models>
<paypal>
<rewrite>
<ipn>Budsies_Budsie_Paypal_Model_Ipn</ipn>
</rewrite>
</paypal>
</models>
</global>
But it doesn't work. What should be config file to make my class to rewrite core class. Could you please tell me what's the problem?
I corrected it, simply it's this section is larger and I made copy paste. But it doesn't work.
Thank you for your help. My rewrite works. The problem was that ipn for that account were not configured, there were not ipn, so this method wasn't called.
If this is really what your XML looks like then it's this:
<global>
<models>
<paypal>
<rewrite>
<ipn>Budsies_Budsie_Paypal_Model_Ipn</ipn>
</rewrite>
</paypal>
</models>
</global>
You had </models> in there twice and didn't have your </global> tag closed.
Related
I am trying to override Mage_Sales_Model_Resource_Order_Collection
My custom module's config:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Abc_Salesextend>
<version>0.1.0</version>
</Abc_Salesextend>
</modules>
<global>
<blocks>
<salesextend>
<class>Abc_Salesextend_Block</class>
</salesextend>
<adminhtml>
<rewrite>
<sales_order_grid>Abc_Salesextend_Block_Sales_Order_Grid</sales_order_grid>
</rewrite>
</adminhtml>
</blocks>
<models>
<salesextend>
<class>Abc_Salesextend_Model</class>
<resourceModel>salesextend_resource</resourceModel>
</salesextend>
<salesextend_resource>
<class>Abc_Salesextend_Model_Resource</class>
</salesextend_resource>
<!-- HERE is i am trying to override-->
<sales_resource>
<rewrite>
<order_collection>Abc_Salesextend_Model_Resource_Order_Collection</order_collection>
</rewrite>
</sales_resource>
</models>
</global>
</config>
It's not giving me any kind of error even if I place the wrong custom class name. So it's not finding my custom class.
Please help
I am not quite sure why the rewrite fails. The rewrite definition looks good. The error can only be related to the wrong class used for rewriting, a cache problem (config.xml cache) or to your module not being active.
I guess you want to just manipulate the collection so instead of a rewrite you should use some event/observer technique.
/**
*
* Sales order grid collection
* #param unknown_type $observer
*/
public function salesOrderGridCollectionLoadBefore($observer){
$collection = $observer->getOrderGridCollection();
$select = $collection->getSelect();
$select->DO_WHATEVER_YOU_WANT...
}
and this method is triggered by:
<events>
<sales_order_grid_collection_load_before>
<observers>
<cartware_modify_grid_adminhtml_collection>
<model>your_module/observer_block</model>
<method>salesOrderGridCollectionLoadBefore</method>
</cartware_modify_grid_adminhtml_collection>
</observers>
</sales_order_grid_collection_load_before>
</events>
</adminhtml>
Good luck!
<sales>
<rewrite>
<resource_order_collection>Abc_Salesextend_Model_YOURFILENAME</resource_order_collection>
</rewrite>
</sales>
just replace with you file name in YOURFILENAME,,,it works...
What is the config required to rewrite a class that is already rewriting another class in magento?
For example, There is a community module doing the following:
<models>
<modulea>
<adminhtml>
<rewrite>
<session>CompanyA_ModuleA_Model_Adminhtml_Session</session>
</rewrite>
</adminhtml>
</modulea>
</models>
I want to rewrite the community module and I am trying the following code which is not working:
<models>
<moduleb>
<class>CompanyB_ModuleB_Model</class>
</moduleb>
<modulea>
<rewrite>
<adminhtml_session>CompanyB_ModuleB_Model_Adminhtml_Session</adminhtml_session>
</rewrite>
</modulea>
</models>
What is wrong with this
Be carefull at your rewrite XML syntax, you have an error. It should like :
<modulea>
<adminhtml>
<rewrite>
<adminhtml_session>CompanyA_ModuleA_Model_Adminhtml_Session</session>
</rewrite>
</adminhtml>
</modulea>
and
<moduleb>
<adminhtml>
<rewrite>
<adminhtml_session>CompanyB_ModuleB_Model_Adminhtml_Session</session>
</rewrite>
</adminhtml>
</moduleb>
Next you'll need to extends the Good PHP class in the good order. FOr example if you want CompanyA extending/rewriting CompanyB :
CompanyA file :
class CompanyA_ModuleA_Model_Adminhtml_Session extends Mage_Adminhtml_Model_Session {
CompanyB Model php file :
class CompanyB_ModuleB_Model_Adminhtml_Session extends CompanyA_ModuleA_Model_Adminhtml_Session {
Last thing, to be sure that the rewrite is done in the good order (when doing a Mage::getModel('adminhtml/session') you want to retrieve the CompanyB class and not the COmpanyA one), you'll need to define which module depends on which. YOu do that in the app/etc/modules/Company_Module.xml file.
add for Company A :
<depends>
<Mage_Adminhtml />
</depends>
add for Company B :
<depends>
<CompanyA_ModuleA />
</depends>
I'm trying to override Mage_Catalog_Block_Layer_View in magento. I have tried to override the Mage_Catalog_Block_Layer_State and it is working properly, but the layer_view rewrite does not. Is this a bug?
<global>
<blocks>
<catalog>
<rewrite>
<layer_view>Mymodule_Catalog_Block_Layer_View</layer_view>
</rewrite>
</catalog>
</blocks>
</global>
<global>
<blocks>
<catalog>
<rewrite>
<layer_state>Mymodule_Catalog_Block_Layer_State</layer_state>
</rewrite>
</catalog>
</blocks>
</global>
please help me out.I'm trying it from hours
Best way to diagnose it is to verify the classname rewrite yourself. In ./demo.php:
<?php
ini_set('display_errors',true);
error_reporting(E_ALL | E_STRICT);
include 'app/Mage.php';
Mage::setIsDeveloperMode(true);
Mage::app();
$layer = Mage::getConfig()->getBlockClassName('catalog/layer_view');
var_dump($layer);
You should see your custom module block classname being returned rather than the core block classname. If that is the case then you need to step through and determine what the issue is. This block is highly coupled to several other block instances and can be a pain to work with.
Also, note that the Mage_CatalogSearch module has a layer_view block which extends from the Mage_Catalog layer_view block, which will not use your override.
Best Way to find which class is used by your .phtml is put echo get_class($this) in it.
Since I am using Enterprise edition, my layered navigation is not use the Mage_Catalog_Block_Layer_View. Instead it uses the Enterprise_Search_Block_Catalog_Block_Layer_View class.
When I override that class every thing was sorted out for me.
I have used below mentioned code:
in config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<PKR_Advmixfilter>
<version>0.1.0</version>
</PKR_Advmixfilter>
</modules>
<global>
<blocks>
<catalog>
<rewrite>
<layer_view>PKR_Advmixfilter_Block_Layer_View</layer_view>
</rewrite>
</catalog>
</blocks>
</global>
</config>
and created a block view file.
class PKR_Advmixfilter_Block_Layer_View extends Mage_Catalog_Block_Layer_View {
public function getFilters()
{
$filters = array();
if ($categoryFilter = $this->_getCategoryFilter()) {
$filters[] = $categoryFilter;
}
$filterableAttributes = $this->_getFilterableAttributes();
foreach ($filterableAttributes as $attribute) {
$filters[] = $this->getChild($attribute->getAttributeCode() . '_filter');
}
return $filters;
}
}
It is working at my end. So there is no bug. :)
I try to rewrite core file from magento.
Somehow it does not overwrite the code. I try to overwrite the function getProduct().
Tipfix/Block/Product/View.php
<?php
class WP_Tipfix_Block_Catalog_Product_View extends Mage_Catalog_Block_Product_View
{
public function getProduct()
{
if (!Mage::registry('product') && $this->getProductId()) {
$product = Mage::getModel('catalog/product')->load($this->getProductId());
Mage::register('product', $product);
}
//return Mage::registry('product');
}
}
Tipfix/etc/config.xml
<blocks>
<WP_Tipfix>
<class>WP_Tipfix_Block</class>
</WP_Tipfix>
<catalog>
<rewrite>
<product_view>WP_Tipfix_Block_Catalog_Product_View</product_view>
</rewrite>
</catalog>
</blocks>
I have know idea what i'm doing wrong.
Gr.
Lex
Your class is WP_Tipfix_Block_Catalog_Product_View which means it must be in the folder WP/Tipfix/Block/Catalog/Product/View.php. You must either move your Product directory into a new directory called Catalog in that place or rename your class (both the class and in the XML) to WP_Tipfix_Block_Product_View. I recommend moving the file.
Please change the config.xml content of your module to this, and I'm sure that it should work:-
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<WP_Tipfix>
<version>1.0.0</version>
</WP_Tipfix>
</modules>
<global>
<blocks>
<wptipfix>
<class>WP_Tipfix_Block</class>
</wptipfix>
<catalog>
<rewrite>
<product_view>WP_Tipfix_Block_Catalog_Product_View</product_view>
</rewrite>
</catalog>
</blocks>
</global>
</config>
Hope it helps.
UPDATE:-
After Ben's comment, I feel that I should have mentioned that the OP must also use the solution as mentioned by Max in his answer. So the OP will need a combined effort to fix his problem.
When I need to rewrite a function in an observer located in the Enterprise section, how will that rewrite bit look like on config.xml.
is it something like this?
<global>
<models>
<enterprise>
<rewrite>
<giftcard>Custom_GiftCard_Model_Observer</giftcard>
</rewrite>
</enterprise>
</models>
</global>
My class is declared as follow:
class Custom_GiftCard_Model_Observer extends Enterprise_GiftCard_Model_Observer {
.....
}
I don't have an enterprise development environment setup at the moment, so this is untested, but it should work as described.
If you look at the Gift Card configuration in
app/code/core/Enterprise/GiftCard/etc/config.xml
You can grep about and discover the class alias for the gift card observer
<class>enterprise_giftcard/observer</class>
So, with a class alias of enterprise_giftcard/observer you have a model group name of enterprise_giftcard, and a model class name of observer.
In your module's configuration file, first you'll create an area for model configuration
<global>
<models>
</models>
</global>
Then, you'll add the group name of the class you want to rewrite, enterprise_giftcard
<global>
<models>
<enterprise_giftcard>
</enterprise_giftcard>
</models>
</global>
Then, you'll add a node saying you want to rewrite the a single class in this group
<global>
<models>
<enterprise_giftcard>
<rewrite>
</rewrite>
</enterprise_giftcard>
</models>
</global>
The, you'll add a node indicating WHICH class in the group you wish to rewrite, using the name portion of the class alias (observer)
<global>
<models>
<enterprise_giftcard>
<rewrite>
<observer></observer>
</rewrite>
</enterprise_giftcard>
</models>
</global>
And finally, within this node, you'll add a text node that's the name of your new class.
<global>
<models>
<enterprise_giftcard>
<rewrite>
<observer>Custom_GiftCard_Model_Observer</observer>
</rewrite>
</enterprise_giftcard>
</models>
</global>
You can test your rewrite by instantiating the observer directly, and checking its class name
$model = Mage::getModel('enterprise_giftcard/observer');
var_dump(get_class($model));