Mage_Review_ProductController Class Reference

Inheritance diagram for Mage_Review_ProductController:

Mage_Core_Controller_Front_Action Mage_Core_Controller_Varien_Action

List of all members.

Public Member Functions

 preDispatch ()
 postAction ()
 listAction ()
 viewAction ()

Protected Member Functions

 _initProduct ()
 _initProductLayout ($product)

Protected Attributes

 $_cookieCheckActions = array('post')


Detailed Description

Definition at line 34 of file ProductController.php.


Member Function Documentation

_initProduct (  )  [protected]

Initialize and check product

Returns:
Mage_Catalog_Model_Product

Definition at line 71 of file ProductController.php.

00072     {
00073         Mage::dispatchEvent('review_controller_product_init_before', array('controller_action'=>$this));
00074         $categoryId = (int) $this->getRequest()->getParam('category', false);
00075         $productId  = (int) $this->getRequest()->getParam('id');
00076 
00077         if (!$productId) {
00078             return false;
00079         }
00080 
00081         $product = Mage::getModel('catalog/product')
00082             ->setStoreId(Mage::app()->getStore()->getId())
00083             ->load($productId);
00084         /* @var $product Mage_Catalog_Model_Product */
00085         if (!$product->getId() || !$product->isVisibleInCatalog() || !$product->isVisibleInSiteVisibility()) {
00086             return false;
00087         }
00088         if ($categoryId) {
00089             $category = Mage::getModel('catalog/category')->load($categoryId);
00090             Mage::register('current_category', $category);
00091         }
00092         Mage::register('current_product', $product);
00093         Mage::register('product', $product);
00094 
00095         try {
00096             Mage::dispatchEvent('review_controller_product_init', array('product'=>$product));
00097             Mage::dispatchEvent('review_controller_product_init_after', array('product'=>$product, 'controller_action' => $this));
00098         } catch (Mage_Core_Exception $e) {
00099             Mage::logException($e);
00100             return false;
00101         }
00102 
00103         return $product;
00104     }

_initProductLayout ( product  )  [protected]

Definition at line 201 of file ProductController.php.

00202     {
00203         $update = $this->getLayout()->getUpdate();
00204 
00205         $update->addHandle('default');
00206         $this->addActionLayoutHandles();
00207 
00208 
00209         $update->addHandle('PRODUCT_TYPE_'.$product->getTypeId());
00210 
00211         if ($product->getPageLayout()) {
00212             $this->getLayout()->helper('page/layout')
00213                 ->applyHandle($product->getPageLayout());
00214         }
00215 
00216         $this->loadLayoutUpdates();
00217         if ($product->getPageLayout()) {
00218             $this->getLayout()->helper('page/layout')
00219                 ->applyTemplate($product->getPageLayout());
00220         }
00221         $update->addUpdate($product->getCustomLayoutUpdate());
00222         $this->generateLayoutXml()->generateLayoutBlocks();
00223     }

listAction (  ) 

Definition at line 171 of file ProductController.php.

00172     {
00173         if ($product = $this->_initProduct()) {
00174             Mage::register('productId', $product->getId());
00175             Mage::getModel('catalog/design')->applyDesign($product, Mage_Catalog_Model_Design::APPLY_FOR_PRODUCT);
00176             $this->_initProductLayout($product);
00177 
00178             // update breadcrumbs
00179             if ($breadcrumbsBlock = $this->getLayout()->getBlock('breadcrumbs')) {
00180                 $breadcrumbsBlock->addCrumb('product', array(
00181                     'label'    => $product->getName(),
00182                     'link'     => $product->getProductUrl(),
00183                     'readonly' => true,
00184                 ));
00185                 $breadcrumbsBlock->addCrumb('reviews', array('label' => Mage::helper('review')->__('Product Reviews')));
00186             }
00187 
00188             $this->renderLayout();
00189         } elseif (!$this->getResponse()->isRedirect()) {
00190             $this->_forward('noRoute');
00191         }
00192     }

postAction (  ) 

Definition at line 106 of file ProductController.php.

00107     {
00108         if ($data = Mage::getSingleton('review/session')->getFormData(true)) {
00109             $rating = array();
00110             if (isset($data['ratings']) && is_array($data['ratings'])) {
00111                 $rating = $data['ratings'];
00112             }
00113         } else {
00114             $data   = $this->getRequest()->getPost();
00115             $rating = $this->getRequest()->getParam('ratings', array());
00116         }
00117 
00118         if (($product = $this->_initProduct()) && !empty($data)) {
00119             $session    = Mage::getSingleton('core/session');
00120             /* @var $session Mage_Core_Model_Session */
00121             $review     = Mage::getModel('review/review')->setData($data);
00122             /* @var $review Mage_Review_Model_Review */
00123 
00124             $validate = $review->validate();
00125             if ($validate === true) {
00126                 try {
00127                     $review->setEntityId(Mage_Review_Model_Review::ENTITY_PRODUCT)
00128                         ->setEntityPkValue($product->getId())
00129                         ->setStatusId(Mage_Review_Model_Review::STATUS_PENDING)
00130                         ->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId())
00131                         ->setStoreId(Mage::app()->getStore()->getId())
00132                         ->setStores(array(Mage::app()->getStore()->getId()))
00133                         ->save();
00134 
00135                     foreach ($rating as $ratingId => $optionId) {
00136                         Mage::getModel('rating/rating')
00137                            ->setRatingId($ratingId)
00138                            ->setReviewId($review->getId())
00139                            ->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId())
00140                            ->addOptionVote($optionId, $product->getId());
00141                     }
00142 
00143                     $review->aggregate();
00144                     $session->addSuccess($this->__('Your review has been accepted for moderation'));
00145                 }
00146                 catch (Exception $e) {
00147                     $session->setFormData($data);
00148                     $session->addError($this->__('Unable to post review. Please, try again later.'));
00149                 }
00150             }
00151             else {
00152                 $session->setFormData($data);
00153                 if (is_array($validate)) {
00154                     foreach ($validate as $errorMessage) {
00155                         $session->addError($errorMessage);
00156                     }
00157                 }
00158                 else {
00159                     $session->addError($this->__('Unable to post review. Please, try again later.'));
00160                 }
00161             }
00162         }
00163 
00164         if ($redirectUrl = Mage::getSingleton('review/session')->getRedirectUrl(true)) {
00165             $this->_redirectUrl($redirectUrl);
00166             return;
00167         }
00168         $this->_redirectReferer();
00169     }

preDispatch (  ) 

Predispatch: shoud set layout area

Returns:
Mage_Core_Controller_Front_Action

Reimplemented from Mage_Core_Controller_Front_Action.

Definition at line 44 of file ProductController.php.

00045     {
00046         parent::preDispatch();
00047 
00048         $allowGuest = Mage::helper('review')->getIsGuestAllowToWrite();
00049         if (!$this->getRequest()->isDispatched()) {
00050             return;
00051         }
00052 
00053         $action = $this->getRequest()->getActionName();
00054         if (!$allowGuest && $action == 'post' && $this->getRequest()->isPost()) {
00055             if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
00056                 $this->setFlag('', self::FLAG_NO_DISPATCH, true);
00057                 Mage::getSingleton('customer/session')->setBeforeAuthUrl(Mage::getUrl('*/*/*', array('_current' => true)));
00058                 Mage::getSingleton('review/session')->setFormData($this->getRequest()->getPost())
00059                     ->setRedirectUrl($this->_getRefererUrl());
00060                 $this->_redirectUrl(Mage::helper('customer')->getLoginUrl());
00061             }
00062         }
00063 
00064         return $this;
00065     }

viewAction (  ) 

Definition at line 194 of file ProductController.php.

00195     {
00196         $this->loadLayout();
00197         $this->_initLayoutMessages('review/session');
00198         $this->renderLayout();
00199     }


Member Data Documentation

$_cookieCheckActions = array('post') [protected]

Reimplemented from Mage_Core_Controller_Varien_Action.

Definition at line 42 of file ProductController.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:38 2009 for Magento by  doxygen 1.5.8