好的,所以我无法覆盖Magento的核心控制器之一WishList Index Controller。当我在心愿单中添加产品时,我需要Magento重定向回产品页面而不是心愿单。这是我到目前为止所做的事情(请注意标记周围的空格是因为StackOverflow很糟糕的格式化代码而且它弄乱了XML。原始的XML格式正确!):
不,此实例适用于生产之外或RDS免费使用套餐
<?xml version="1.0"?>
<config>
<modules>
<MyCompany_Coreextensions>
<version>0.1.0</version>
</MyCompany_Coreextensions>
</modules>
<frontend>
<routers>
<wishlist>
<args>
<modules>
<MyCompany_Coreextensions before="Mage_Wishlist">
MyCompany_Coreextensions_Wishlist
</MyCompany_Coreextensions>
</modules>
</args>
</wishlist>
</routers>
</frontend>
</config>
在Coreextensions文件夹中,我创建了controllers / Wishlist / IndexController.php,如下所示:
class MyCompany_Coreextensions_Wishlist_IndexController extends Mage_Wishlist_IndexController
{
/**
* Add the item to wish list
*
* @return Mage_Core_Controller_Varien_Action|void
*/
protected function _addItemToWishList()
{
$wishlist = $this->_getWishlist();
if (!$wishlist) {
return $this->norouteAction();
}
$session = Mage::getSingleton('customer/session');
$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 {
$requestParams = $this->getRequest()->getParams();
if ($session->getBeforeWishlistRequest()) {
$requestParams = $session->getBeforeWishlistRequest();
$session->unsBeforeWishlistRequest();
}
$buyRequest = new Varien_Object($requestParams);
$result = $wishlist->addNewItem($product, $buyRequest);
if (is_string($result)) {
Mage::throwException($result);
}
$wishlist->save();
Mage::dispatchEvent(
'wishlist_add_product',
array(
'wishlist' => $wishlist,
'product' => $product,
'item' => $result
)
);
$referer = $session->getBeforeWishlistUrl();
if ($referer) {
$session->setBeforeWishlistUrl(null);
} else {
$referer = $this->_getRefererUrl();
}
/**
* Set referer to avoid referring to the compare popup window
*/
$session->setAddActionReferer($referer);
Mage::helper('wishlist')->calculate();
$message = $this->__('%1$s has been added to your wishlist. Click <a href="%2$s">here</a> to continue shopping.',
$product->getName(), Mage::helper('core')->escapeUrl($referer));
$session->addSuccess($message);
} catch (Mage_Core_Exception $e) {
$session->addError($this->__('An error occurred while adding item to wishlist: %s', $e->getMessage()));
}
catch (Exception $e) {
$session->addError($this->__('An error occurred while adding item to wishlist.'));
}
//$this->_redirect('*', array('wishlist_id' => $wishlist->getId()));
$this->_redirectReferer();
}
}
在app / etc / modules中,我创建了MyCompany_Coreextensions.xml,如下所示:
<?xml version="1.0"?>
<!--we need to enable this module as any other if-->
<!--you wish to do it as standalone module extension-->
<config>
<modules>
<MyCompany_Coreextensions>
<active>true</active>
<codepool>local</codepool>
</MyCompany_Coreextensions>
</modules>
</config>
当然,这不起作用,它让我疯了。如果我在Core文件中进行更改,它可以按照我的意愿运行,但我不想更改Core文件...在你回答之前,让我说YES,我确实清除了缓存!
谢谢!
答案 0 :(得分:2)
如果您使用Magento EE,则应替换:
<MyCompany_Coreextensions before="Mage_Wishlist">
使用:
<MyCompany_Coreextensions before="Enterprise_Wishlist">
答案 1 :(得分:1)
你的步骤是对的,但只有两件事:
require_once Mage::getModuleDir('controllers', 'Mage_Wishlist') . DS . 'IndexController.php';
; MyCompany_Coreextensions_IndexController
代替MyCompany_Coreextensions_Wishlist_IndexController
(您必须将其更改为config.xml - &gt; { {1}}代替<MyCompany_Coreextensions before="Mage_Wishlist">MyCompany_Coreextensions</MyCompany_Coreextensions>
)答案 2 :(得分:0)
此外,您还没有“包含”或“必需”原始(核心)愿望清单的IndexController,您必须在模块的索引控制器文件中执行如下操作:
require_once Mage::getModuleDir('controllers', 'Mage_Wishlist') . DS . 'IndexController.php';
上面的代码应放在模块的IndexController.php文件中的任何类声明之前。
你也有“&lt;”之间的空格和标签名称,所以删除它们或xml结构将破坏,显示magento中的致命错误。
一旦你刷新magento缓存,然后尝试将产品添加到心愿单,你将被重定向到以前的URL。
答案 3 :(得分:-1)
< codepool >local< /codepool >
如果您还没弄明白,则必须将codepool
更改为codePool