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
Related
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 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');
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');
}
I am trying to create my first Magento module which would allow an attribute (yes/no) on a product page to alter the styling of the grouped products options on a product view page.
I'm probably starting a little too deep here but this is my understanding of how to do this:
Create an attribute and assign to default attribute set (Alternative Group View alt_group_view).
Create an alternative grouped.phtml file in /template/catalog/product/view/type - groupedAlt.phtml
Create a basic module structure that initialises my module. I should really have the module create the attribute, but I havent a clue about that yet!!!
Then this is where I get stuck. Essentially I need to right the logic within the module file that looks for the attribute on the product - if its set I then need to code that tells the layout block presumably something that extends this:
<PRODUCT_TYPE_grouped translate="label" module="catalog">
<reference name="product.info">
<block type="catalog/product_view_type_grouped" name="product.info.grouped" as="product_type_data" template="catalog/product/view/type/grouped.phtml">
</reference>
</PRODUCT_TYPE_grouped translate="label" module="catalog">
Hopefully that makes sense to someone?
I'm not sure that I can realisticly acheive this as Im just starting with module development although I have quite a lot of knowledge with the frontend and admin areas of Magento.
Any advice would be much appreciated.
Regards,
Steve
You should handle this through an observer. The event to observe is :
controller_action_layout_generate_blocks_after
1°) In your module, in etc/config.xml, add your event handler :
<frontend>
<events>
<controller_action_layout_generate_blocks_after>
<observers>
<yourmodule_generate_blocks_after>
<type>singleton</type>
<class>mymodule/observer</class>
<method>generateBlocksAfter</method>
</yourmodule_generate_blocks_after>
</observers>
</controller_action_layout_generate_blocks_after>
</events>
</frontend>
Then create a Model named Observer.php in your Model directory (MyCompany/MyModule/Model/Observer.php)
In this model, add your generateBlocksAfter() method like this :
public function generateBlocksAfter($event)
{
$controller = $event->getAction();
//limit to the product view page
if($controller->getFullActionName() != 'catalog_product_view')
{
return;
}
$layout = $controller->getLayout();
$myblock = $layout->getBlock('product.info.grouped');
$_product = Mage::registry('current_product');
if ($_product->getAltGroupView()) {
$myblock->setTemplate('catalog/product/view/type/groupedalt.phtml');
}
}
And here you are.
I have read several posts on stack overflow
Overriding a Magento Adminhtml template file
Magento - overriding Adminhtml block
and a couple threads on the magento forum
http://www.magentocommerce.com/boards/viewthread/21978/
However, None of these posts attempt to do what I am trying to do
I would like to override the
app/design/adminhtml/default/default/template/widget/grid.phtml
file, as this file contains a portion of html that allows anyone to export from the sales->order view.
Note: We have disabled all of the export options for this user role in the permissions->role view
The code that displays the "Export to: " -> "CSV/Excel XML" feature is included in the path I have listed above. I would like to remove that chunk of html and override the file included with Magento.
Adminhtml uses the same theming fallback as the frontend, therefore you need only declare a custom template theme for your installation in module config XML:
<stores>
<admin>
<design>
<theme>
<template>custom</template>
</theme>
</design>
</admin>
</stores>
Then you can create app/design/adminhtml/default/custom/template/widget/grid.phtml with any customizations you like, and this file will be used in preference to the one from the default/default adminhtml theme. Your solution then would be to add an ACL check in the logic which renders the export control:
<?php if($this->getExportTypes() && {ACL LOGIC}}): ?>
<td class="export a-right">
<img src="<?php echo $this->getSkinUrl('images/icon_export.gif') ?>" alt="" class="v-middle"/> <?php echo $this->__('Export to:') ?>
<select name="<?php echo $this->getId() ?>_export" id="<?php echo $this->getId() ?>_export" style="width:8em;">
<?php foreach ($this->getExportTypes() as $_type): ?>
<option value="<?php echo $_type->getUrl() ?>"><?php echo $_type->getLabel() ?></option>
<?php endforeach; ?>
</select>
<?php echo $this->getExportButtonHtml() ?>
</td>
<?php endif; ?>
While this logic might be more appropriately implemented in the block class, the class rewrite system does not accommodate rewriting of parent classes, leaving you to rewrite every subclass. In this instance, obeying DRY outweighs embedding too much logic in templates. Moreover, the change is obvious and easily maintained.
Ideally the core team would have implemented this check in the Mage_Adminhtml_Block_Widget_Grid class or at least provided a public setter for the _exportTypes property, which would have made this logic a bit cleaner to implement.
It might seem the simplest solution to rewrite the block but that's more of a dirty hack than a clean solution. Class rewrites should be used very carefully and always avoided if possible. Otherwise you will quickly run into conflicts and also updating Magento gets a hell.
Usually you can change templates by a custom layout update (i.e. in your local.xml), but in this case it is a widget, which are not configured via layout XML.
So, enter observers: create a module that contains the following in its config.xml
<adminhtml>
<events>
<adminhtml_block_html_before>
<observers>
<yourmodulename_observer>
<class>yourmodulename/observer</class>
<method>changeWidgetTemplate</method>
</yourmodulename_observer>
</observers>
</adminhtml_block_html_before>
</events>
</adminhtml>
If you don't understand any of the above, read about Magento Events and Observers.
Now you will need the observer itself to actually change the template, but only for this block type:
class Your_Modulename_Observer
{
public function changeWidgetTemplate(Varien_Event_Observer $observer)
{
$block = $observer->getEvent()->getBlock();
if ($block instanceof Mage_Adminhtml_Block_Widget_Grid) {
// consider getting the template name from configuration
$template = '...';
$block->setTemplate($template);
}
}
}
Magento - Override adminhtml template file
add below code to config.xml file of extension (you created)
<stores>
<admin>
<design>
<theme>
<default>default</default>
<template>rwd</template>
</theme>
</design>
</admin>
</stores>
Now create rwd folder under adminhtml/default/rwd package.
and create template and layout file as you want to override.
like we want to override order comment history.phtml file.
<root>\app\design\adminhtml\default\default\template\sales\order\view\history.phtml
<root>\app\design\adminhtml\default\rwd\template\sales\order\view\history.phtml
Template definition can be found here
class Mage_Adminhtml_Block_Widget_Grid extends Mage_Adminhtml_Block_Widget
in
public function __construct($attributes=array())
So you need to rewrite sales grid block if you want to remove export csv from Sales Order Grid (use this guide if you don't know how http://www.magentocommerce.com/wiki/groups/174/changing_and_customizing_magento_code) and to change __construct to be like
public function __construct($attributes=array())
{
parent::__construct($attributes);
$this->setTemplate('...'); //here is your template
}