Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Review_Block_Customer_List
  • Mage_Review_Block_Customer_Recent
  • Mage_Review_Block_Customer_View
  • Mage_Review_Block_Form
  • Mage_Review_Block_Helper
  • Mage_Review_Block_Product_View
  • Mage_Review_Block_Product_View_List
  • Mage_Review_Block_View
  • Mage_Review_CustomerController
  • Mage_Review_Helper_Data
  • Mage_Review_Model_Mysql4_Review
  • Mage_Review_Model_Mysql4_Review_Collection
  • Mage_Review_Model_Mysql4_Review_Product_Collection
  • Mage_Review_Model_Mysql4_Review_Status_Collection
  • Mage_Review_Model_Mysql4_Review_Summary
  • Mage_Review_Model_Mysql4_Review_Summary_Collection
  • Mage_Review_Model_Observer
  • Mage_Review_Model_Resource_Review
  • Mage_Review_Model_Resource_Review_Collection
  • Mage_Review_Model_Resource_Review_Product_Collection
  • Mage_Review_Model_Resource_Review_Status
  • Mage_Review_Model_Resource_Review_Status_Collection
  • Mage_Review_Model_Resource_Review_Summary
  • Mage_Review_Model_Resource_Review_Summary_Collection
  • Mage_Review_Model_Review
  • Mage_Review_Model_Review_Status
  • Mage_Review_Model_Review_Summary
  • Mage_Review_Model_Session
  • Mage_Review_ProductController
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Review
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: /**
 28:  * Review controller
 29:  *
 30:  * @category   Mage
 31:  * @package    Mage_Review
 32:  * @author     Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_Review_ProductController extends Mage_Core_Controller_Front_Action
 35: {
 36: 
 37:     /**
 38:      * Action list where need check enabled cookie
 39:      *
 40:      * @var array
 41:      */
 42:     protected $_cookieCheckActions = array('post');
 43: 
 44:     public function preDispatch()
 45:     {
 46:         parent::preDispatch();
 47: 
 48:         $allowGuest = Mage::helper('review')->getIsGuestAllowToWrite();
 49:         if (!$this->getRequest()->isDispatched()) {
 50:             return;
 51:         }
 52: 
 53:         $action = $this->getRequest()->getActionName();
 54:         if (!$allowGuest && $action == 'post' && $this->getRequest()->isPost()) {
 55:             if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
 56:                 $this->setFlag('', self::FLAG_NO_DISPATCH, true);
 57:                 Mage::getSingleton('customer/session')->setBeforeAuthUrl(Mage::getUrl('*/*/*', array('_current' => true)));
 58:                 Mage::getSingleton('review/session')->setFormData($this->getRequest()->getPost())
 59:                     ->setRedirectUrl($this->_getRefererUrl());
 60:                 $this->_redirectUrl(Mage::helper('customer')->getLoginUrl());
 61:             }
 62:         }
 63: 
 64:         return $this;
 65:     }
 66:     /**
 67:      * Initialize and check product
 68:      *
 69:      * @return Mage_Catalog_Model_Product
 70:      */
 71:     protected function _initProduct()
 72:     {
 73:         Mage::dispatchEvent('review_controller_product_init_before', array('controller_action'=>$this));
 74:         $categoryId = (int) $this->getRequest()->getParam('category', false);
 75:         $productId  = (int) $this->getRequest()->getParam('id');
 76: 
 77:         $product = $this->_loadProduct($productId);
 78:         if (!$product) {
 79:             return false;
 80:         }
 81: 
 82:         if ($categoryId) {
 83:             $category = Mage::getModel('catalog/category')->load($categoryId);
 84:             Mage::register('current_category', $category);
 85:         }
 86: 
 87:         try {
 88:             Mage::dispatchEvent('review_controller_product_init', array('product'=>$product));
 89:             Mage::dispatchEvent('review_controller_product_init_after', array(
 90:                 'product'           => $product,
 91:                 'controller_action' => $this
 92:             ));
 93:         } catch (Mage_Core_Exception $e) {
 94:             Mage::logException($e);
 95:             return false;
 96:         }
 97: 
 98:         return $product;
 99:     }
100: 
101:     /**
102:      * Load product model with data by passed id.
103:      * Return false if product was not loaded or has incorrect status.
104:      *
105:      * @param int $productId
106:      * @return bool|Mage_Catalog_Model_Product
107:      */
108:     protected function _loadProduct($productId)
109:     {
110:         if (!$productId) {
111:             return false;
112:         }
113: 
114:         $product = Mage::getModel('catalog/product')
115:             ->setStoreId(Mage::app()->getStore()->getId())
116:             ->load($productId);
117:         /* @var $product Mage_Catalog_Model_Product */
118:         if (!$product->getId() || !$product->isVisibleInCatalog() || !$product->isVisibleInSiteVisibility()) {
119:             return false;
120:         }
121: 
122:         Mage::register('current_product', $product);
123:         Mage::register('product', $product);
124: 
125:         return $product;
126:     }
127: 
128:     /**
129:      * Load review model with data by passed id.
130:      * Return false if review was not loaded or review is not approved.
131:      *
132:      * @param int $productId
133:      * @return bool|Mage_Review_Model_Review
134:      */
135:     protected function _loadReview($reviewId)
136:     {
137:         if (!$reviewId) {
138:             return false;
139:         }
140: 
141:         $review = Mage::getModel('review/review')->load($reviewId);
142:         /* @var $review Mage_Review_Model_Review */
143:         if (!$review->getId() || !$review->isApproved() || !$review->isAvailableOnStore(Mage::app()->getStore())) {
144:             return false;
145:         }
146: 
147:         Mage::register('current_review', $review);
148: 
149:         return $review;
150:     }
151: 
152:     /**
153:      * Submit new review action
154:      *
155:      */
156:     public function postAction()
157:     {
158:         if ($data = Mage::getSingleton('review/session')->getFormData(true)) {
159:             $rating = array();
160:             if (isset($data['ratings']) && is_array($data['ratings'])) {
161:                 $rating = $data['ratings'];
162:             }
163:         } else {
164:             $data   = $this->getRequest()->getPost();
165:             $rating = $this->getRequest()->getParam('ratings', array());
166:         }
167: 
168:         if (($product = $this->_initProduct()) && !empty($data)) {
169:             $session    = Mage::getSingleton('core/session');
170:             /* @var $session Mage_Core_Model_Session */
171:             $review     = Mage::getModel('review/review')->setData($data);
172:             /* @var $review Mage_Review_Model_Review */
173: 
174:             $validate = $review->validate();
175:             if ($validate === true) {
176:                 try {
177:                     $review->setEntityId($review->getEntityIdByCode(Mage_Review_Model_Review::ENTITY_PRODUCT_CODE))
178:                         ->setEntityPkValue($product->getId())
179:                         ->setStatusId(Mage_Review_Model_Review::STATUS_PENDING)
180:                         ->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId())
181:                         ->setStoreId(Mage::app()->getStore()->getId())
182:                         ->setStores(array(Mage::app()->getStore()->getId()))
183:                         ->save();
184: 
185:                     foreach ($rating as $ratingId => $optionId) {
186:                         Mage::getModel('rating/rating')
187:                         ->setRatingId($ratingId)
188:                         ->setReviewId($review->getId())
189:                         ->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId())
190:                         ->addOptionVote($optionId, $product->getId());
191:                     }
192: 
193:                     $review->aggregate();
194:                     $session->addSuccess($this->__('Your review has been accepted for moderation.'));
195:                 }
196:                 catch (Exception $e) {
197:                     $session->setFormData($data);
198:                     $session->addError($this->__('Unable to post the review.'));
199:                 }
200:             }
201:             else {
202:                 $session->setFormData($data);
203:                 if (is_array($validate)) {
204:                     foreach ($validate as $errorMessage) {
205:                         $session->addError($errorMessage);
206:                     }
207:                 }
208:                 else {
209:                     $session->addError($this->__('Unable to post the review.'));
210:                 }
211:             }
212:         }
213: 
214:         if ($redirectUrl = Mage::getSingleton('review/session')->getRedirectUrl(true)) {
215:             $this->_redirectUrl($redirectUrl);
216:             return;
217:         }
218:         $this->_redirectReferer();
219:     }
220: 
221:     /**
222:      * Show list of product's reviews
223:      *
224:      */
225:     public function listAction()
226:     {
227:         if ($product = $this->_initProduct()) {
228:             Mage::register('productId', $product->getId());
229: 
230:             $design = Mage::getSingleton('catalog/design');
231:             $settings = $design->getDesignSettings($product);
232:             if ($settings->getCustomDesign()) {
233:                 $design->applyCustomDesign($settings->getCustomDesign());
234:             }
235:             $this->_initProductLayout($product);
236: 
237:             // update breadcrumbs
238:             if ($breadcrumbsBlock = $this->getLayout()->getBlock('breadcrumbs')) {
239:                 $breadcrumbsBlock->addCrumb('product', array(
240:                     'label'    => $product->getName(),
241:                     'link'     => $product->getProductUrl(),
242:                     'readonly' => true,
243:                 ));
244:                 $breadcrumbsBlock->addCrumb('reviews', array('label' => Mage::helper('review')->__('Product Reviews')));
245:             }
246: 
247:             $this->renderLayout();
248:         } elseif (!$this->getResponse()->isRedirect()) {
249:             $this->_forward('noRoute');
250:         }
251:     }
252: 
253:     /**
254:      * Show details of one review
255:      *
256:      */
257:     public function viewAction()
258:     {
259:         $review = $this->_loadReview((int) $this->getRequest()->getParam('id'));
260:         if (!$review) {
261:             $this->_forward('noroute');
262:             return;
263:         }
264: 
265:         $product = $this->_loadProduct($review->getEntityPkValue());
266:         if (!$product) {
267:             $this->_forward('noroute');
268:             return;
269:         }
270: 
271:         $this->loadLayout();
272:         $this->_initLayoutMessages('review/session');
273:         $this->_initLayoutMessages('catalog/session');
274:         $this->renderLayout();
275:     }
276: 
277:     /**
278:      * Load specific layout handles by product type id
279:      *
280:      */
281:     protected function _initProductLayout($product)
282:     {
283:         $update = $this->getLayout()->getUpdate();
284: 
285:         $update->addHandle('default');
286:         $this->addActionLayoutHandles();
287: 
288: 
289:         $update->addHandle('PRODUCT_TYPE_'.$product->getTypeId());
290: 
291:         if ($product->getPageLayout()) {
292:             $this->getLayout()->helper('page/layout')
293:                 ->applyHandle($product->getPageLayout());
294:         }
295: 
296:         $this->loadLayoutUpdates();
297:         if ($product->getPageLayout()) {
298:             $this->getLayout()->helper('page/layout')
299:                 ->applyTemplate($product->getPageLayout());
300:         }
301:         $update->addUpdate($product->getCustomLayoutUpdate());
302:         $this->generateLayoutXml()->generateLayoutBlocks();
303:     }
304: }
305: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0