|
Hi,
I want to override the addAction() function in the IndexController of the Wishlist. I followed the Wiki steps on how to overload the controllers.
I created a MyNameSpace_All.xml in app/etc/modules in which I added:
<?xml version="1.0"?> <config> <modules> <MyNameSpace_MyModule> <active>true</active> <codePool>local</codePool> </MyNameSpace_MyModule> </modules> </config>
Then I created app/code/local/MyNameSpace/MyModule/etc/config.xml with the following content:
<?xml version="1.0"?> <config> <modules> <MyNameSpace_MyModule> <version>0.1.0</version> </MyNameSpace_MyModule> </modules> <global> <rewrite> <mynamespace_mymodule_wishlist_index> <from><![CDATA[#^/wishlist/$#]]></from> <to>/mymodule/wishlist_index/</to> </mynamespace_mymodule_wishlist_index> </rewrite> </global> <frontend> <routers> <mynamespace_mymodule> <use>standard</use> <args> <module>MyNameSpace_MyModule</module> <frontName>wishlist</frontName> </args> </mynamespace_mymodule> </routers> </frontend> </config>
Then I created app/code/local/MyNameSpace/MyModule/Wishlist/IndexController.php with the following content:
<?php # # Controllers are not autoloaded so we will have to do it manually: # require_once 'Mage/Wishlist/controllers/IndexController.php';
class MyNameSpace_MyModule_Wishlist_IndexController extends Mage_Wishlist_IndexController { # Overloaded public function addAction() { error_log('CUSTOM ACTION!'); $session = Mage::getSingleton('customer/session'); $wishlist = $this->_getWishlist(); if (!$wishlist) { $this->_redirect('*/'); return; }
$productId = (int) $this->getRequest()->getParam('product'); if (!$productId) { $this->_redirect('*/'); return; }
$product = Mage::getModel('catalog/product')->load($productId); if (!$product->getId() || !$product->isVisibleInCatalog()) { $session->addError($this->__('Cannot specify product')); $this->_redirect('*/'); return; }
try { $wishlist->addNewItem($product->getId()); Mage::dispatchEvent('wishlist_add_product', array('wishlist'=>$wishlist, 'product'=>$product));
if ($referer = $session->getBeforeWishlistUrl()) { $session->setBeforeWishlistUrl(null); } else { $referer = $this->_getRefererUrl(); } $message = $this->__('%1$s was successfully added to your wishlist. Click <a href="%2$s">here</a> to continue shopping', $product->getName(), $referer); $session->addSuccess($message); } catch (Mage_Core_Exception $e) { $session->addError($this->__('There was an error while adding item to wishlist: %s', $e->getMessage())); } catch (Exception $e) { $session->addError($this->__('There was an error while adding item to wishlist.')); } $this->_redirect('*'); } }
?>
Then I modified app/design/frontend/default/default/layout/wishlist.xml
<!-- Wishlist pages -->
<wishlist_index_index> <!-- Mage_Wishlist --> <update handle="customer_account"/> <reference name="content"> <block type="wishlist/customer_wishlist" name="customer.wishlist" template="wishlist/view.phtml"/> </reference> <reference name="right"> <action method="unsetChild"><name>wishlist_customer_sidebar</name></action> </reference> </wishlist_index_index> <!-- NEW MODULE --> <mymodule_wishlist_index_index> <update handle="customer_account"/> </mymodule_wishlist_index_index>
I am getting a page not found when I go to /wishlist/. What am I doing wrong? Which part of the XML of the layout was I supposed to modify. If there were already handlers there?
Please help since it’s getting really frustrating.
::Sintax
|