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
}
}
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 one block inside my custom module but it's not working. My module is working fine but my block is not working when I call my block from footer.phtml file it shows 'Fatal error: Call to a member function setTemplate() on a non-object'. Actually I want to show some message in my frontend using my custom block.I have mentioned my code below
local/Monojit/Custom/controllers/IndexController.php
<?php
class Monojit_Custom_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
$block = $this->getLayout()->createBlock(
'Mage_Core_Block_Template',
'my_block_name_here',
array('template' => 'custom/test.phtml')
);
$this->getLayout()->getBlock('content')->append($block);
$this->renderLayout();
}
}
?>
local/Monojit/Custom/Block/Mycustomblock.php
<?php
class Monojit_Custom_Block_Mycustomblock extends Mage_Core_Block_Template
{
//public function _prepareLayout()
// {
// return parent::_prepareLayout();
// }
public function _construct() {
parent::_construct();
$this->setTemplate('custom/test.phtml');
}
public function getmessage()
{
$msg = "showing my custom block";
return $msg;
}
}
?>
local/Monojit/Custom/etc/config.xml
<config>
<global>
<modules>
<monojit_custom>
<version>0.1.0</version>
</monojit_custom>
</modules>
<blocks>
<custom>
<rewrite>
<custom>Monojit_Custom_Block_Mycustomblock</custom>
</rewrite>
</custom>
</blocks>
<helpers>
<custom>
<class>Monojit_Custom_Helper</class>
</custom>
</helpers>
</global>
<frontend>
<routers>
<custom>
<use>standard</use>
<args>
<module>Monojit_Custom</module>
<frontName>custom</frontName>
</args>
</custom>
</routers>
<layout>
<updates>
<custom>
<file>custom.xml</file>
</custom>
</updates>
</layout>
</frontend>
</config>
I have created one theme (copied modern theme) inside frontend/default/monojit Changed admin design configuration as well,created necessary folder as well inside skin.screenshot pic
design/frontend/default/monojit/template/custom/test.phtml
//want to fetch data from my block
<p>This is your custom block called programatically.</p>
localhost/magento/index.php/custom page shows my message correctly but when I call my block from footer.phtml page
<?php echo $this->getLayout()->createBlock('custom/mycustomblock')->setTemplate('custom/test.phtml')->toHtml(); ?>
It shows 'Fatal error: Call to a member function setTemplate() on a non-object' Do I need to create any layout.xml file? Please help me how can i fix my issue.thanks
Your block was not created, and createBlock return a non-object value. It happens because you don't specify custom namespace class prefix. Your block node in XML config should looks like
<blocks>
<custom>
<class>Monojit_Custom_Block</class>
</custom>
</blocks>
It means everything under custom namespace will be created with Monojit_Custom_Block prefix, so custom/mycustomblock => Monojit_Custom_Block_Mycustomblock.
But using createBlock is usually bad practice, it better to use layout files:
http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-4-magento-layouts-blocks-and-templates
http://www.magentocommerce.com/design_guide/articles/intro-to-layouts
try:
In layout/page.xml set your block, for Example:
<block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml">
<block type="my_module/block_links" name="my_block_name" as="my_block_name" template="page/template/links.phtml"/>
</block>
Use code below in your phtml file
<?php echo $this->getChildHtml('my_block_name') ?>
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 defined a custom block this way:
<frontend>
<layout>
<updates>
<categorylist module="mymodule">
<file>mymodule.xml</file>
</categorylist>
</updates>
</layout>
</frontend>
<global>
<blocks>
<categorylist>
<class>Alias_CategoryList_Block</class>
</categorylist>
</blocks>
</global>
Then I defined the block class this way
class Alias_CategoryList_Block_List extends Mage_Core_Block_Template
{
public $idCategory = NULL;
// Contructor
public function __construct()
{
echo $this->getData('categoryid');
}
}
and the layout this way:
<default translate="label">
<block type="categorylist/list" name="categorylist.list" output="toHtml" after="-" template="mymodule.phtml"/>
I put the block in a CMS this way:
{{block type="categorylist/list" categoryid="10"}}
But sadly the $this->getData('categoryid'); retrieves nothing.
Cannot figure out what's wrong ?
I tryed even $this->getCategoryid; but even nothing.
Anyone can help?
I'm using Magento 1.7
Would it be silly to add a view (phtml) template file that has
<?php echo $this->getCategoryId(); ?>
instead of trying to accomplish that in the constructor? Also then you wouldn't need your own code behind file you could just use core/template.
So your cms would be
{{block type="core/template" template="awesome.phtml" cateogryid="10"}}
The problem was that I assumed that the layout updates configuration will extend the code in the CMS but the code in the CMS should not have block name and template parameters for my purposes. So I fixed it declearing the template in the contructor and removing the layout updates in configuration (since I don't need the block to override existing blocks):
// Contructor
public function __construct()
{
$this->setTemplate('mymodule.xml');
}
Is there any event for "bulk import of products/customers"?
I intend to make a module for my vendors to upload their product information in xml/csv through the backend. When they upload, I need to update my Solr records.
Thanx
You can override the Mage_Catalog_Model_Convert_Adapter_Product::saveRow() as:
1> in config.xml
<global>
<models>
...
<catalog>
<rewrite>
<!-- Override Mage_Catalog_Model_Convert_Adapter_Product -->
<convert_adapter_product>MagePsycho_Productimport_Model_Convert_Adapter_Product</convert_adapter_product>
</rewrite>
</catalog>
...
</models>
</global>
2> create class file as
class MagePsycho_Productimport_Model_Convert_Adapter_Product extends Mage_Catalog_Model_Convert_Adapter_Product
{
public function saveRow(array $importData)
{
parent::saveRow($importData);
//do your extra stuffs here..
}
}
Note: This is just an idea, you need to develop full working module by yourself.
Thanks
Regards
MagePsycho