Magento override core model - php

I know this has been asked a few times on here, but I've been through the answers and still can't figure out why I can't override a core model in Magento:
I am trying to override the Eav/Attribute/Data/Text.php but it refuses to use my version of the validateValue() function.
Here is my model class /app/code/local/Hailstorm/Eav/Model/Attribute/Data/Text.php
class Hailstorm_Eav_Model_Attribute_Data_Text extends Mage_Eav_Model_Attribute_Data_Text {
public function validateValue($value) {
$attribute = $this->getAttribute();
echo "My validator for |" . $attribute->getAttributeCode() . "|!\n";
if ($attribute->getAttributeCode() == 'postcode') {
$countryId = $this->getExtractedData('country_id');
$optionalZip = Mage::helper('directory')->getCountriesWithOptionalZip();
if (!in_array($countryId, $optionalZip)) {
return parent::validateValue($value);
}
return true;
}
else {
return parent::validateValue($value);
}
}
}
Here is my config.xml /app/code/local/Hailstorm/Eav/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<hailstorm_eav>
<version>0.1.0</version>
</hailstorm_eav>
</modules>
<global>
<models>
<eav>
<rewrite>
<attribute_data_text>Hailstorm_Eav_Model_Attribute_Data_Text</attribute_data_text>
</rewrite>
</eav>
</models>
<hailstorm_eav>
<class>Hailstorm_Eav_Model</class>
</hailstorm_eav>
</global>
</config>
And here is my module xml file
/app/etc/modules/Hailstorm_Eav.xml
<?xml version="1.0"?>
<config>
<modules>
<hailstorm_eav>
<active>true</active>
<codepool>local</codepool>
</hailstorm_eav>
</modules>
</config>
I've been through the tutorials and the answers to other questions like this on here, but I can't see what I'm doing wrong!
Thanks for any help

Use this
<codePool>local</codePool>

There are issue in class declaration of config.xml and Hailstorm_Eav.xml
in Hailstorm_Eav.xml
hailstorm_eav to Hailstorm_Eav
and in config.xml
<hailstorm_eav>
<version>0.1.0</version>
</hailstorm_eav>
Should be
<Hailstorm_Eav>
<version>0.1.0</version>
</Hailstorm_Eav>
And codePool syntax as Vishal Sharma Said

Related

try to override model but not working in magento

Try to override model of Mage_Paypal_Model_Express_Checkout but not working.
I try to override start() in "Mage_Paypal_Model_Express_Checkout" in magento.
The bellow code used but not working.
File : code/local/Live/Paypal/Model/Express/Checkout.php
class Live_Paypal_Model_Express_Checkout extends
Mage_Paypal_Model_Express_Checkout
{
public function start($returnUrl, $cancelUrl, $button = null)
{
echo "fasdfasdf";exit;
}
}
File : code/local/Live/Paypal/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Live_Paypal>
<version>1.0.0</version>
</Live_Paypal>
</modules>
<global>
<models>
<paypal>
<rewrite>
<express_checkout>Live_Paypal_Model_Express_Checkout</express_checkout>
</rewrite>
</paypal>
</models>
</global>
</config>
File : app/etc/modules/Live_Paypal.xml
<?xml version="1.0"?>
<config>
<modules>
<Live_Paypal>
<active>true</active>
<codePool>local</codePool>
</Live_Paypal>
</modules>
</config>

Overriding Mage_Wishlist_IndexController in Magento

Hi i am trying to override magento wishlist IndexController. I have followed all steps but its not working here is my code and path of all directories
app\code\local\XS4Arabia\Wishlist\etc\config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<XS4Arabia_Wishlist>
<version>0.1.0</version>
</XS4Arabia_Wishlist>
</modules>
<frontend>
<routers>
<wishlist>
<args>
<modules>
<XS4Arabia_Wishlist before="Mage_Wishlist">XS4Arabia_Wishlist</XS4Arabia_Wishlist>
</modules>
</args>
</wishlist>
</routers>
</frontend>
</config>
app\code\local\XS4Arabia\Wishlist\controllers\IndexController.php
require_once Mage::getModuleDir('controllers', 'Mage_Wishlist') . DS . 'IndexController.php';
class XS4Arabia_Wishlist_IndexController extends Mage_Wishlist_IndexController
{
public function sendAction()
{
die('local');
}
}
app\etc\modules\XS4arabia_Wishlist.xml
<?xml version="1.0"?>
<config>
<modules>
<XS4Arabia_Wishlist>
<active>true</active>
<codePool>local</codePool>
</XS4Arabia_Wishlist>
</modules>
</config>

Magento Custom module recognised in Admin Panel but not in store

Ive made a custom module in magento. The Admin panel recognises it but not the store.. Ive checked many posts and sources but nothing solves my problem
Code In the app/etc/modules/Firstmagetest_All.xml:
<?xml version = "1.0"?>
<config>
<modules>
<Firstmagetest_Test>
<active>true</active>
<codePool>local</codePool>
</Firstmagetest_Test>
</modules>
</config>
Code in app/code/local/FirstMageTest/Test/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Firstmagetest_Test>
<version>1.0.0</version>
</Firstmagetest_Test>
</modules>
<frontend>
<routers>
<firstmage_test>
<use>standard</use>
<args>
<module>Firstmagetest_Test</module>
<frontName>test</frontName>
</args>
</firstmage_test>
</routers>
</frontend>
</config>
[html]
Code in app/code/local/FirstMageTest/Test/controllers/IndexController.php
<?php
class Firstmagetest_Test_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction ()
{
echo 'test index';
}
public function mamethodeAction ()
{
echo 'test mymethod';
}
}
?>

Magento showConfig module is not working

I start study magento from Magento for Developers guide. So I create module with their names. But it is showing following error when i trying http://works.dev/magento/?showConfig=true.
XML Parsing Error: XML or text declaration not at start of entity
Location: http://works.dev/magento/?showConfig=true
Line Number 1, Column 2: <?xml version="1.0"?>
-^
(works.dev is my localhost domain. magento path is working fine.)
This is my configuration files.
app/code/local/Magentotutorial/Configviewer/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Magentotutorial_Configviewer>
<version>0.1.0</version>
</Magentotutorial_Configviewer>
</modules>
<global>
<events>
<controller_front_init_routers>
<observers>
<Magentotutorial_configviewer_model_observer>
<type>singleton</type>
<class>Magentotutorial_Configviewer_Model_Observer</class>
<method>checkForConfigRequest</method>
</Magentotutorial_configviewer_model_observer>
</observers>
</controller_front_init_routers>
</events>
</global>
</config>
app/etc/modules/Magentotutorial_Configviewer.xml
<?xml version="1.0"?>
<config>
<modules>
<Magentotutorial_Configviewer>
<active>true</active>
<codePool>local</codePool>
</Magentotutorial_Configviewer>
</modules>
</config>
app/code/local/Magentotutorial/Configviewer/Model/Observer.php
<?php
class Magentotutorial_Configviewer_Model_Observer {
const FLAG_SHOW_CONFIG = 'showConfig';
const FLAG_SHOW_CONFIG_FORMAT = 'showConfigFormat';
private $request;
public function checkForConfigRequest($observer) {
$this->request = $observer->getEvent()->getData('front')->getRequest();
if($this->request->{self::FLAG_SHOW_CONFIG} === 'true'){
$this->setHeader();
$this->outputConfig();
}
}
private function setHeader() {
$format = isset($this->request->{self::FLAG_SHOW_CONFIG_FORMAT}) ?
$this->request->{self::FLAG_SHOW_CONFIG_FORMAT} : 'xml';
switch($format){
case 'text':
header("Content-Type: text/plain");
break;
default:
header("Content-Type: text/xml");
}
}
private function outputConfig() {
die(Mage::app()->getConfig()->getNode()->asXML());
}
}
I did clear cache and check logs. I cant find problem from those.
According #Jürgen Thelen it was space issue. It had worked after remove space before the
Ausuraya,can you please change config.xml
<global>
<models>
<configviewer>
<class>Magentotutorial_Configviewer_Model</class>
</configviewer>
</models>
<events>
<controller_front_init_routers>
<observers>
<Magentotutorial_configviewer_model_observer>
<type>singleton</type>
<class>configviewer/observer</class>
<method>checkForConfigRequest</method>
</Magentotutorial_configviewer_model_observer>
</observers>
</controller_front_init_routers>
</events>
</global>

Magento extension: How to output a string on a CMS page or block

I'm trying to create my first Magento extension and I'm stuck at the first step already.
When adding {{block type="rick_printer/print" text="Hello world"}} to a CMS page or block, I want "Hello world" to be displayed.
Unfortunately nothing happens. Here's my code:
app\code\local\Rick\Printer\etc\config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Rick_Printer>
<version>0.0.1</version>
</Rick_Printer>
</modules>
<global>
<blocks>
<rick_printer>
<class>Rick_Printer_Block_Print</class>
</rick_printer>
</blocks>
</global>
</config>
app\etc\modules\Rick_Printer.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Rick_Printer>
<active>true</active>
<codePool>local</codePool>
</Rick_Printer>
</modules>
</config>
app\code\local\Rick\Printer\Block\Print.php
class Rick_Printer_Block_Print extends Mage_Core_Block_Abstract
{
protected function _construct()
{
$this->setTemplate('rick/printer/view.phtml');
parent::_construct();
}
public function printIt()
{
$text = $this->getText();
if (!$text) {
$msg = "Please provide a text!";
echo $msg;
return array();
}
return $text;
}
}
app\design\frontend\default\default\template\rick\printer\print.phtml
<?php
$text = $this->spinIt();
echo $text;
?>
I know the code is ugly and I'm probably doing it all wrong.
Any help is highly appreciated!
Thanks
Update: After applying the fix from Vinai's answer my app\code\local\Rick\Printer\etc\config.xml looks now like this:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Rick_Printer>
<version>0.0.1</version>
</Rick_Printer>
</modules>
<global>
<blocks>
<rick_printer>
<class>Rick_Printer_Block</class>
</rick_printer>
</blocks>
</global>
</config>
and I'm getting the following error message when accessing the CMS page (which doesn't show):
class Rick_Printer_Block_Print extends Mage_Core_Block_Abstract
{
protected function _construct()
{
$this->setTemplate('rick/printer/view.phtml');
parent::_construct();
}
public function printIt()
{
$text = $this->getText();
if (!$text) {
$msg = "Please provide a text!";
echo $msg; return array();
}
return $text;
}
}
Fatal error: Class 'Rick_Printer_Block_Print' not found in /home/www/xyz/htdocs/app/code/core/Mage/Core/Model/Layout.php on line 491
First, your block class prefix is wrong. Despite the node name being <class>, what you are actually specifying is a class prefix.
Another way to look at it is that this node declares the directory, in which the blocks for the module are located.
The correct way is
<!-- language: xml -->
<global>
<blocks>
<rick_printer>
<class>Rick_Printer_Block</class>
</rick_printer>
</blocks>
</global>
Second, in your template you are calling $this->spinIt(); instead of $this->printIt();.
Just a typo...
Otherwise the code looks okay.
UPDATE
The error message indicates a file system path to class name mismatch. Check the casing and for typos.
Also, since you want your block to render a template, you want to extend Rick_Printer_Block_Print from Mage_Core_Block_Template instead of the _Abstract block class.

Categories