This one kept me up all night, and would like to offer these code snippets to save someone else the trouble of automatically approving ratings and reviews. Using this page as a guide:
http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/how_to_overload_a_controller
I created the following items:
1) /app/code/local/Mynamespace/Review/controllers/ProductController.php
2) /app/code/local/Mynamespace/Review/etc/config.xml
3) /app/etc/modules/Mynamespace_Review.xml
Here’s the contents of each file:
1)
<?php /* this is the working version! hoorah */ require_once("Mage/Review/controllers/ProductController.php"); class Mynamespace_Review_ProductController extends Mage_Review_ProductController { public function postAction() { if ($data = Mage::getSingleton('review/session')->getFormData(true)) { $rating = array(); if (isset($data['ratings']) && is_array($data['ratings'])) { $rating = $data['ratings']; } } else { $data = $this->getRequest()->getPost(); $rating = $this->getRequest()->getParam('ratings', array()); } if (($product = $this->_initProduct()) && !empty($data)) { $session = Mage::getSingleton('core/session'); /* @var $session Mage_Core_Model_Session */ $review = Mage::getModel('review/review')->setData($data); /* @var $review Mage_Review_Model_Review */ $validate = $review->validate(); if ($validate === true) { try { $review->setEntityId($review->getEntityIdByCode(Mage_Review_Model_Review::ENTITY_PRODUCT_CODE)) ->setEntityPkValue($product->getId()) ->setStatusId(Mage_Review_Model_Review::STATUS_APPROVED) ->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId()) ->setStoreId(Mage::app()->getStore()->getId()) ->setStores(array(Mage::app()->getStore()->getId())) ->save(); foreach ($rating as $ratingId => $optionId) { Mage::getModel('rating/rating') ->setRatingId($ratingId) ->setReviewId($review->getId()) ->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId()) ->addOptionVote($optionId, $product->getId()); } $review->aggregate(); $session->addSuccess($this->__('Your rating has been approved.')); } catch (Exception $e) { $session->setFormData($data); $session->addError($this->__('Unable to post the review.')); } } else { $session->setFormData($data); if (is_array($validate)) { foreach ($validate as $errorMessage) { $session->addError($errorMessage); } } else { $session->addError($this->__('Unable to post the review.')); } } } if ($redirectUrl = Mage::getSingleton('review/session')->getRedirectUrl(true)) { $this->_redirectUrl($redirectUrl); return; } $this->_redirectReferer(); } } ?>
2)
<?xml version="1.0"?> <config> <modules> <Mynamespace_Review> <version>0.0.1</version> </Mynamespace_Review> </modules> <frontend> <routers> <review> <args> <modules> <Mynamespace_Review before="Mage_Review">Mynamespace_Review</Mynamespace_Review> </modules> </args> </review> </routers> </frontend> </config>
3)
<?xml version="1.0"?> <config> <modules> <Mynamespace_Review> <active>true</active> <codePool>local</codePool> </Mynamespace_Review> </modules> </config>
相关推荐
Where applicable, Media Go will also automatically download and/or convert certain content (e.g. a podcast) into a suitable format. Media Go can also purchase, backup, and restore.
bank-switching function, which reduces flicker and cluttered images by automatically switching between video-memory pages and/or color lookup tables on each vertical retrace. The core can interrupt ...
With the DDX SDK V4, you can write filters that can:· Perform in-place filtering· Process IEEE 32-bit floating point and/or 16-bit integer PCM data.· Process mono and/or stereo data. · Have up to...
video-memory pages and/or color lookup tables on each vertical retrace. The optional hardware cursors provide additional flexibility through two 32x32 16bpp or 64x64 4bpp hardware generated cursors. ...
As reference database, you can apply the included free-of-charge COD database and/or ICSD/Retrieve (if you have a valid licence), use any ICDD PDF product, and/or create a user database based on your ...
能够对word里的汉语和英文进行语法检测,并能够提出修改意见,对于写论文有很大的帮助,快速比较简单。
Many of the LINQ samples require XML files and/or the version of the Northwind sample database that is located in the Data directory. By default the Data directory appears under the same parent folder...
* Backup/Restore a single package or all apps, user data and Internal Storage * Backup your /data/media (virtual SD Card) to your PC for a Full Safe backup of data * Unlock/Re-Lock your Bootloader * ...
can play back AVI files with JPEG, Intel's Indeo, or YUV data and MPEG-1 audio/video files. o Audio Control -- a utility to control volume and port selection for all audio devices. Multimedia ...
estimation calculation task for 16x16 or 8x8 block. MPEG4/JPEG codec will also automatically perform the DCT/quantization, IDCT/inverse quantization, AC/DC prediction, zigzag scan, and VLC/VLD ...
Blat is useful for creating s cripts where mail has to be sent automatically (CGI, backups, etc.), or just as a quick way to send a file or message quickly from the command line. It will store ...
If you don't understand the complexities of RegVac and/or the Registry but you still want a clean Registry, the Novice Mode is for you. The Novice Mode has only two controls on it, a "Clean ...
BoundsChecker automatically pinpoints static, stack and heap memory errors, and resource leaks. Unlike ordinary memory-checking tools, BoundsChecker validates the latest Windows APIs including ...
either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you...
ApiMate tool for automatically showing needed Delphi/C++ code for generating specific .XLS/.XLSX file cells with Flexcel Templates can be embedded inside your exe. No additional files to distribute ...
Server-side validation and/or client-side JavaScript validation Optional search features (Quick, Extended Quick and Advanced) with search result highlight Optional User ID and User Level Advanced ...
// Image.Parent.Invalidate or Image.Parent.Refresh to restore the background. // // This change was made as a result of a email correspondance with // // Tineke Kosmis (http://www.classe.nl/) which ...
Whether you are a novice developer or an experienced .NET developer wishing to learn more about MVC and Entity Framework, author Lee Naylor will teach you how to develop a detailed database driven ...
With ImageDetect you can easily detect and crop faces, texts or barcodes in your image with iOS 11 Vision api. It will automatically create new images containing each object found within a given ...