I need to override a method in a Magento core file, I am pretty sure I have done it the correct way and it is working on someone else's machine, but it's just not working on my own machine. We have the same environment. It's pretty weird I couldn't find out why and I have checked the file permissions, still don't see any light in solving the problem. Wonder has anyone run into the same problem? I am running 1.7
Many thanks!
--Update--
My custom block class (app/code/local/Company/Cms/Block/Page.php)
require_once("Mage/Cms/Block/Page.php");
class Company_Cms_Block_Page extends Mage_Cms_Block_Page
{
protected function _prepareLayout()
{
// my code
}
}
app/code/local/Company/Cms/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Company_Cms>
<version>0.0.1</version>
</Company_Cms>
</modules>
<global>
<blocks>
<cms>
<rewrite>
<page>Company_Cms_Block_Page</page>
</rewrite>
</cms>
</blocks>
</global>
</config>
app/etc/modules/Company_Cms.xml
<?xml version="1.0"?>
<config>
<modules>
<Company_Cms>
<active>true</active>
<codePool>local</codePool>
</Company_Cms>
</modules>
</config>
This custom module isn't being executed at all as nothing changes unless I change code in core block class.
Related
I would like to introduce my own entities into particular Magento module namespaces for example I might want to be able to call
Mage::getModel('catalog/brand')->load(1);
Brand is not currently a model included in the catalog module. I don't want to modify core files nor do I want to hack the core by just adding a Mage folder to the local directory.
I was thinking perhaps syntax inside of my namespaces config file similar to this:
<models>
<catalog>
<args>
<modules>
<AJW_Catalog before="Mage_Catalog">AJW_Catalog</AJW_Catalog>
</modules>
</args>
</catalog>
<ajw_catalog>
<class>AJW_Catalog_Model</class>
</ajw_catalog>
</models>
but it does not seem to work.
Does anyone know how this can be accomplished?
Maybe possible with some trickery, but not officially supported, and generally a bad idea. The before= syntax you've used only works for the routers node. There's no framework code to let you do what you're trying to do. Also, there's a strong bias in the Magento framework code towards individual modules "owning" their namespace/package name. Defining new models in an existing namespace (catalog) introduces the theoretical possibility that your code may conflicts with a future version of Magento's code.
This may be a possible fix (brain fart)
Create a module named Customnamespace_Catalog and then just rewrite the catalog module with a node that doesnt exist in the default mage module:
<?xml version="1.0"?>
<config>
<modules>
<Namespace_Catalog>
<version>0.1.0</version>
</Namespace_Catalog>
</modules>
<global>
<models>
<catalog>
<rewrite>
<brand>Namespace_Brand_Model_Brand</brand>
</rewrite>
</catalog>
</models>
</global>
</config>
Followed by an additional module:
<?xml version="1.0"?>
<config>
<modules>
<Namespace_Brand>
<version>0.1.0</version>
</Namespace_Brand>
</modules>
<global>
<models>
<brand>
<class>Namespace_Brand_Model</class>
</brand>
</models>
</global>
</config>
This will allow you to call Mage::getModel('catalog/brand')
echo get_class(Mage::getModel('catalog/brand'); // Namespace_Brand_Model_Brand
Tyring to create a module where i can create a product dynamically using catalog->products model, and redirect control to the product's review page. Need only single controller with single action. No blocks, helpers, templates.... nothing required.
But it seems like controller action is not properly routed, there is some mistake in code or configuration ... getting 404 not found error
Trying this url:
http://localhost/magento_test/dynamicproduct/index/index
Namespace: Waqasalieee
Module name: Dynamicproduct
Magento version: 1.7.0.2
Here are the file contents:
local/Waqasalieee/Dynamicproduct/controllers/IndexController.php
<?php
class Waqasalieee_Dynamicproduct_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction() {
die('working in index');
}
}
?>
local/Waqasalieee/Dynamicproduct/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Waqasalieee_Dynamicproduct>
<version>1.0</version>
</Waqasalieee_Dynamicproduct>
</modules>
<frontend>
<routers>
<dynamicproduct>
<use>standard</use>
<args>
<module>Waqasalieee_Dynamicproduct</module>
<frontName>dynamicproduct</frontName>
</args>
</dynamicproduct>
</routers>
</frontend>
</config>
app/etc/modules/Waqasalieee_Dynamicproduct.xml
<?xml version='1.0'?>
<config>
<modules>
<Waqasalieee_Dynamicproduct>
<codepool>local</codepool>
<active>true</active>
</Waqasalieee_Dynamicproduct>
</modules>
</config>
It should show some error or 'working in index' (string) but its giving 404 not found error.
I was having the same sympton and landed here. For me the error was not a erroneous XML config but that the Store Code was actually added to the URL (that's a magento feature, not a bug) and so my controller was only accessible by adding a valid store code to the URL like http://mystore/<storecode>/<controller>/<action>.
In my case http://mage.localhost/en/customer/check
In your config.xml use codePool instead of codepool.
<?xml version='1.0'?>
<config>
<modules>
<Waqasalieee_Dynamicproduct>
<codePool>local</codePool>
<active>true</active>
</Waqasalieee_Dynamicproduct>
</modules>
</config>
I'm try to overriding Mage_Core_Block_Messages
I'm create module
Mycompany_Core.xml and save in path app/etc/modules/Mycompany_Core.xml
<?xml version="1.0"?>
<config>
<modules>
<Mycompany_Core>
<active>true</active>
<codepool>local</codepool>
</Mycompany_Core>
</modules>
</config>
next I was create in app/code/local/Mycompany/Core/Block/Messages.php
class Mycompany_Core_Block_Messages extends Mage_Core_Block_Messages
{
//update method
}
and add config.xml in app/code/local/Mycompany/Core/etc/config.xml
<config>
<modules>
<Mycompany_Core>
<version>0.0.1</version>
</Mycompany_Core>
</modules>
<global>
<blocks>
<core>
<rewrite>
<messages>Softdk_Core_Block_Messages</messages>
</rewrite>
</core>
</blocks>
</global>
</config>
But i don't see any result on frontend, I'm wonder where I'm make mistake.
Thx for help.
There are two things that caught my eye.
1.) In your module's registration file, it should be codePool and not codepool (as also said by David in comments)
2.) What is Softdk? If that is the name of your new module, then replace Mycompany with Softdk everywhere in your module.
Clear cache and voila!
I tried the tutorial on http://www.satollo.net/magento-pdf-invoices-customer-dashboard/comment-page-1#comment-47565.
This allows a user to view invoices as PDF on the frontend of my Magento store. The problem is, when I click on the link which points to Pdfinvoice/index/invoices/order_id/5/ it shows a 404 error.
I registered the module as followed:
(renamed to module to Pdfinvoice to avoid conflict with another module)
<?xml version="1.0"?>
<config>
<modules>
<Pdfinvoice>
<active>true</active>
<codePool>local</codePool>
</Pdfinvoice>
</modules>
</config>
app/etc/modules/Pdfinvoice.xml
I am breaking my head over this.
Maybe the module isn't registered? I've tried googling it, but I can't get it to work.
Does anyone know a solution to this problem?
When you rename the module in the module definition xml, make sure you do the same with your local folder (app/code/local/Pdfinvoice), your config.xml:
app/code/local/Pdfinvoice/etc/config.xml
<config>
<modules>
<Pdfinvoice>
<version>1.0.0</version>
</Pdfinvoice>
</modules>
<frontend>
<routers>
<pdf>
<use>standard</use>
<args>
<module>Pdfinvoice</module>
<frontName>pdfinvoice</frontName>
</args>
</pdf>
</routers>
</frontend>
.. and your new controller:
app/code/local/Pdfinvoice/controllers/IndexController.php
<?php
class Pdfinvoice_IndexController extends Mage_Core_Controller_Front_Action {
public function invoicesAction() {
...
Works flawless, I installed the module in minutes.
I'm stuck. Been messing with this all day. To me this looks like it should work but It's not, and its not outputting any errors to magento error log.
What I tried to do was simply override the getPriceHtml() function in Catalog/Block/Product.php. The module is active from the 'Advanced' tab via the system configuration.
My config.xml in app/code/local/Brian/Pricefix/etc/config.xml:
<config>
<modules>
<Brian_Pricefix>
<version>1.0</version>
</Brian_Pricefix>
</modules>
<global>
<blocks>
<catalog>
<rewrite>
<product>Brian_Pricefix_Catalog_Block_Product</product>
</rewrite>
</catalog>
</blocks>
</global>
</config>
My Brian_Pricefix.xml in app/etc/modules:
<config>
<modules>
<Brian_Pricefix>
<active>true</active>
<codePool>local</codePool>
</Brian_Pricefix>
</modules>
</config>
My Product.php in app/code/local/Brian/Pricefix/Catalog/Block/Product.php
class Brian_Pricefix_Catalog_Block_Product extends Mage_Catalog_Block_Product
{
public function getPriceHtml($product)
{
Mage::log("IM IN YOUR MODULEZ");
$this->setTemplate('catalog/product/price_fix.phtml');
$this->setProduct($product);
return $this->toHtml();
}
}
The new module isn't taking, its not logging anything or outputting price_fix.phtml
Any suggestions? I've done a few hours or research and this appears to be the right way to extend a block, so i'm not sure whats going on. The lack of error output is frustrating.
Thanks.
Looks like Mage_Catalog_Block_Product is not used anywhere.
catalog.xml contains mainly Mage_Catalog_Block_Product_View or Mage_Catalog_Block_Product_List calls.
You config looks fine. Try overriding another block.
Can you precise the page you are testing on?