I am using Mage::helper('addmultiple') where addmultiple is my module name Mycompany_Addmultiple_Helper_Data in Data.php in my modules helper. it gives a fatal error and why it tries to locate Mage_Addmultiple_Helper_Data instead of Mycompany_Addmultiple_Helper_Data
xml entry in my global block
<helpers>
<addmultiple>
<class>Mycompany_Addmultiple_Helper</class>
</addmultiple>
</helpers>
note that when i call this from my block file or controller file from same module it is working.
I am trying to call this from some overridden core template right now.
Try with this.
config.xml
<helpers>
<addmultiple>
<class>Mycompany_Addmultiple_Helper</class>
</addmultiple>
</helpers>
Use a name for your helper class instead of default name 'Data.php'. Here I'm using Test.php as the helper class.
class Mycompany_Addmultiple_Helper_Test extends Mage_Core_Helper_Abstract
{
// some code
}
Now you can call the Test.php helper class as below.
$my_helper = Mage::helper('addmultiple/test');
Related
I have extended Magento core files before but in this case wish to extend a class
//app/code/core/Mage/Tax/Model/Calculation.php
i.e. Mage_Tax_Model_Calculation
into an existing component my company had:
//app/code/local/Mycompany/Model/Companytaxrate.php
i.e. Mycompany_Companytaxrate_Model_Companytaxrate
The module Companytaxrate is already in place as is this file. How would I do this?
You can extend Mage_Tax_Model_Calculation from your new model:
class Mycompany_Companytaxrate_Model_Companytaxrate extends Mage_Tax_Model_Calculation
{
}
From there, you'd rewrite the model inside your /etc/config.xml file:
<global>
<models>
<tax>
<rewrite>
<calculation>Mycompany_Companytaxrate_Model_Companytaxrate</calculation>
</rewrite>
</tax>
</models>
</global>
I have created a custom module which change the template for the bundle product option, it is in the radio.phtml.
I am now overriding the radio.phtml on a new theme xxx/template/bundle/catalog/product/view/type/bundle/option/radio.phtml.
But I want to put the radio.pthml into my custom module folder, that is
template/mycompany/mymodule/radio.phtml
I understand that I can do in the mymodule.xml layout by using <action method="setTemplate">, but how can I know the <reference> name for the radio.phtml?
you need to rewrite this block because the theme are set in block..
Mage_Bundle_Block_Catalog_Product_View_Type_Bundle_Option_Radio
you can in this function
protected function _construct()
{
$this->setTemplate('bundle/catalog/product/view/type/bundle/option/radio.phtml');
}
you can rewrite block module like that
<global>
<blocks>
<bundle>
<rewrite>
<catalog_product_view_type_bundle_option_radio>Spacename_Modulname_Block_Adminhtml_Radio</catalog_product_view_type_bundle_option_radio>
</rewrite>
</bumdle>
</blocks>
</global>
and call your phtml file
class Spacename_Modulname_Block_Adminhtml_Radio extends Mage_Core_Block_Template
{
protected function _construct()
{
$this->setTemplate('test/radio.phtml'); //your file path link here
}
}
I added my contact form.phtml to a cms page with the following code:
{{block type="core/template" name="contactForm" form_action="/contacts/index/post" template="contacts/form.phtml"}}
However when I submit the contact form it will show a 404 error because the URL is being routed to www.domain.de/contacts/index/post, which doesn't exist because I use URL rewrites with store codes (de/en).
So the routing should go to www.domain.de/de/contacts/index/post
This only works when I alter the code as follows:
{{block type="core/template" name="contactForm" form_action="http://domain.de/de/contacts/index/post" template="contacts/form.phtml"}}
Since I am pretty new to magento I didn't find a solution and I dont know if this could be a problem with the .htaccess file.
Did anyone have the same issue and knows how to fix it?
Update:
Just to make sure if I did it correctly:
I created \app\code\local\MARG\ContactForm\etc\config.xml\ with the following content:
<config>
<modules>
<MARG_ContactForm>
<version>0.0.1</version>
</MARG_ContactForm>
</modules>
<global>
<blocks>
<ContactForm>
<class>MARG_ContactForm_Block</class>
</ContactForm>
<blocks>
</global>
</config>
Then I created app\code\local\MARG\ContactForm\Block\ContactForm.php with content:
class MARG_ContactForm_Block_ContactForm extends Mage_Core_Block_Template
{
protected function_construct()
{
$this ->setTemplate('contacts/form.phtml');
parent::_construct();
}
public function getFormAction()
{
return Mage::getUrl('*/*/post', array('_secure' => $this->getRequest()->isSecure()));
}
}
In app\etc\modules\MARG_ContactForm.xmlI put content:
<config>
<modules>
<MARG_ContactForm>
<active>true</active>
<codePool>local</codePool>
</MARG_ContactForm>
</modules>
</config>
In the CMS page I added {{block type="MARG/ContactForm" name="contactForm"}}
Is there something i overlooked?
Edit:
i have done it exactly as described and added {{block type="ContactForm/ContactForm" name="contactForm"}} to the CMS page. However it still shows a blank page the exception.log says
exception 'Mage_Core_Exception' with message 'Invalid block type: Mage_ContactForm_Block_ContactForm' in C:\dev\plain\magento\app\Mage.php:595 Stack trace:
#0 C:\dev\plain\magento\app\code\core\Mage\Core\Model\Layout.php(495): Mage::throwException('Invalid block t...')
#1 C:\dev\plain\magento\app\code\core\Mage\Core\Model\Layout.php(437): Mage_Core_Model_Layout->_getBlockInstance('ContactForm/Con...', Array)
The problem here is that the block is type Mage_Core_Block_Template which doesn't have a function to turn form action into a fully qualified URL. Normally that happens in Mage_Contacts_IndexController but of course your CMS page is not using that controller.
The solution is to make a block type which suits your purpose. I'll assume you know how to make a module and that it's name is "example".
class Example_Example_Block_Contacts extends Mage_Core_Block_Template
{
protected function _construct()
{
$this->setTemplate('contacts/form.phtml');
parent::_construct();
}
public function getFormAction()
{
// copied from Mage_Contacts_IndexController::indexAction()
return Mage::getUrl('contacts/index/post', array('_secure' => $this->getRequest()->isSecure()));
}
}
This makes your CMS page simpler too. It only needs to include:
{{block type="example/contacts" name="contactForm"}}
I'm trying to override this class in order to change the behavior of the function
_applyProductLimitations
and add another new function (so i can filter by two or more categories)
Anyone can help telling me how to override it in order that all the product collection can call my new function without getting the error that it's not defined in
Mage_Catalog_Model_Resource_Product_Collection ?
Thanks :)
add this to the config.xml file of your module under the <global> tag
<models>
<catalog_resource>
<rewrite>
<product_collection>Namespace_Module_Model_Resource_Product_Collection</product_collection>
</rewrite>
</catalog_resource>
</models>
Then create the file app/code/local/Namespace/Module/Model/Resource/Product/Collection.php with the following content.
<?php
class Namespace_Module_Model_Resource_Product_Collection extends Mage_Catalog_Model_Resource_Product_Collection {
protected function _applyProductLimitations(){
//your magic here
}
}
I would like to rename the URL path of the shopping cart from checkout/cart to checkout/adverts.
I have tried the following two methods:
Catalog > URL Rewrite Management: Custom
I have also tried doing it using a custom module, with the following in my config.xml:
<global>
<rewrite>
<mynamespace_mymodule_checkout_cart>
<from><![CDATA[#^/checkout/cart#]]></from>
<to>/checkout/adverts</to>
</mynamespace_mymodule_checkout_cart>
</rewrite>
</global>
Both methods have gone to the correct URL path, but shown a 404 Error page - is there something else I need to do? Magento ver. 1.5.0.1
What happen if you add a empty controller to your custom module
<?php
require_once('Mage/Checkout/controllers/CartController.php');
class Mynamespace_Mymodule_CartController extends Mage_Checkout_CartController
{
}
As R.S said you have to extend CartController.php in your module
<?php
require_once('Mage/Checkout/controllers/CartController.php');
class Mynamespace_Mymodule_CartController extends Mage_Checkout_CartController
{
}
?>
in it copy the indexAction() of Mage/Checkout/controllers/CartController.php
Also in your local.xml write
<mymodule_cart_adverts>
// copy the xml code inside <checkout_cart_index> ... </checkout_cart_index> here
</mymodule_cart_adverts>
I havent tried it but it should work