Public Member Functions | |
sendAction () | |
sendmailAction () | |
Protected Member Functions | |
_initProduct () | |
_initSendToFriendModel () |
Definition at line 27 of file ProductController.php.
_initProduct | ( | ) | [protected] |
Initialize product instance
Definition at line 34 of file ProductController.php.
00035 { 00036 $productId = (int) $this->getRequest()->getParam('id'); 00037 if (!$productId) { 00038 return false; 00039 } 00040 $product = Mage::getModel('catalog/product') 00041 ->load($productId); 00042 if (!$product->getId()) { 00043 return false; 00044 } 00045 Mage::register('product', $product); 00046 return $product; 00047 }
_initSendToFriendModel | ( | ) | [protected] |
Initialize send friend model
Definition at line 54 of file ProductController.php.
00054 { 00055 $sendToFriendModel = Mage::getModel('sendfriend/sendfriend'); 00056 Mage::register('send_to_friend_model', $sendToFriendModel); 00057 return $sendToFriendModel; 00058 }
sendAction | ( | ) |
check if user is allowed to send product to a friend
Definition at line 60 of file ProductController.php.
00060 { 00061 $product = $this->_initProduct(); 00062 $this->_initSendToFriendModel(); 00063 00064 if (!$product || !$product->isVisibleInCatalog()) { 00065 $this->_forward('noRoute'); 00066 return; 00067 } 00068 00069 $productHelper = Mage::helper('catalog/product'); 00070 $sendToFriendModel = Mage::registry('send_to_friend_model'); 00071 00072 /** 00073 * check if user is allowed to send product to a friend 00074 */ 00075 if (!$sendToFriendModel->canEmailToFriend()) { 00076 Mage::getSingleton('catalog/session')->addError( 00077 $this->__('You cannot email this product to a friend') 00078 ); 00079 $this->_redirectReferer($product->getProductUrl()); 00080 return; 00081 } 00082 00083 $maxSendsToFriend = $sendToFriendModel->getMaxSendsToFriend(); 00084 if ($maxSendsToFriend){ 00085 Mage::getSingleton('catalog/session')->addNotice( 00086 $this->__('You cannot send more than %d times in an hour', $maxSendsToFriend) 00087 ); 00088 } 00089 00090 $this->loadLayout(); 00091 $this->_initLayoutMessages('catalog/session'); 00092 $this->renderLayout(); 00093 Mage::dispatchEvent('sendfriend_product', array('product'=>$product)); 00094 }
sendmailAction | ( | ) |
Definition at line 96 of file ProductController.php.
00097 { 00098 $product = $this->_initProduct(); 00099 $sendToFriendModel = $this->_initSendToFriendModel(); 00100 $data = $this->getRequest()->getPost(); 00101 00102 if (!$product || !$product->isVisibleInCatalog() || !$data) { 00103 $this->_forward('noRoute'); 00104 return; 00105 } 00106 00107 $categoryId = $this->getRequest()->getParam('cat_id', null); 00108 if ($categoryId && $category = Mage::getModel('catalog/category')->load($categoryId)) { 00109 Mage::register('current_category', $category); 00110 } 00111 00112 $sendToFriendModel->setSender($this->getRequest()->getPost('sender')); 00113 $sendToFriendModel->setRecipients($this->getRequest()->getPost('recipients')); 00114 $sendToFriendModel->setIp(Mage::getSingleton('log/visitor')->getRemoteAddr()); 00115 $sendToFriendModel->setProduct($product); 00116 00117 try { 00118 $validateRes = $sendToFriendModel->validate(); 00119 if (true === $validateRes) { 00120 $sendToFriendModel->send(); 00121 Mage::getSingleton('catalog/session')->addSuccess($this->__('Link to a friend was sent.')); 00122 $this->_redirectSuccess($product->getProductUrl()); 00123 return; 00124 } 00125 else { 00126 Mage::getSingleton('catalog/session')->setFormData($data); 00127 if (is_array($validateRes)) { 00128 foreach ($validateRes as $errorMessage) { 00129 Mage::getSingleton('catalog/session')->addError($errorMessage); 00130 } 00131 } else { 00132 Mage::getSingleton('catalog/session')->addError($this->__('Some problems with data.')); 00133 } 00134 } 00135 } catch (Mage_Core_Exception $e) { 00136 Mage::getSingleton('catalog/session')->addError($e->getMessage()); 00137 } catch (Exception $e) { 00138 Mage::getSingleton('catalog/session') 00139 ->addException($e, $this->__('Some emails was not sent')); 00140 } 00141 00142 $this->_redirectError(Mage::getURL('*/*/send',array('id'=>$product->getId()))); 00143 }