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_Sendfriend_Helper_Data
  • Mage_Sendfriend_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_Sendfriend
 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:  * Email to a Friend Product Controller
 29:  *
 30:  * @category    Mage
 31:  * @package     Mage_Sedfriend
 32:  * @author      Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_Sendfriend_ProductController extends Mage_Core_Controller_Front_Action
 35: {
 36:     /**
 37:      * Predispatch: check is enable module
 38:      * If allow only for customer - redirect to login page
 39:      *
 40:      * @return Mage_Sendfriend_ProductController
 41:      */
 42:     public function preDispatch()
 43:     {
 44:         parent::preDispatch();
 45: 
 46:         /* @var $helper Mage_Sendfriend_Helper_Data */
 47:         $helper = Mage::helper('sendfriend');
 48:         /* @var $session Mage_Customer_Model_Session */
 49:         $session = Mage::getSingleton('customer/session');
 50: 
 51:         if (!$helper->isEnabled()) {
 52:             $this->norouteAction();
 53:             return $this;
 54:         }
 55: 
 56:         if (!$helper->isAllowForGuest() && !$session->authenticate($this)) {
 57:             $this->setFlag('', self::FLAG_NO_DISPATCH, true);
 58:             if ($this->getRequest()->getActionName() == 'sendemail') {
 59:                 $session->setBeforeAuthUrl(Mage::getUrl('*/*/send', array(
 60:                     '_current' => true
 61:                 )));
 62:                 Mage::getSingleton('catalog/session')
 63:                     ->setSendfriendFormData($this->getRequest()->getPost());
 64:             }
 65:         }
 66: 
 67:         return $this;
 68:     }
 69: 
 70:     /**
 71:      * Initialize Product Instance
 72:      *
 73:      * @return Mage_Catalog_Model_Product
 74:      */
 75:     protected function _initProduct()
 76:     {
 77:         $productId  = (int)$this->getRequest()->getParam('id');
 78:         if (!$productId) {
 79:             return false;
 80:         }
 81:         $product = Mage::getModel('catalog/product')
 82:             ->load($productId);
 83:         if (!$product->getId() || !$product->isVisibleInCatalog()) {
 84:             return false;
 85:         }
 86: 
 87:         Mage::register('product', $product);
 88:         return $product;
 89:     }
 90: 
 91:     /**
 92:      * Initialize send friend model
 93:      *
 94:      * @return Mage_Sendfriend_Model_Sendfriend
 95:      */
 96:     protected function _initSendToFriendModel()
 97:     {
 98:         $model  = Mage::getModel('sendfriend/sendfriend');
 99:         $model->setRemoteAddr(Mage::helper('core/http')->getRemoteAddr(true));
100:         $model->setCookie(Mage::app()->getCookie());
101:         $model->setWebsiteId(Mage::app()->getStore()->getWebsiteId());
102: 
103:         Mage::register('send_to_friend_model', $model);
104: 
105:         return $model;
106:     }
107: 
108:     /**
109:      * Show Send to a Friend Form
110:      *
111:      */
112:     public function sendAction()
113:     {
114:         $product    = $this->_initProduct();
115:         $model      = $this->_initSendToFriendModel();
116: 
117:         if (!$product) {
118:             $this->_forward('noRoute');
119:             return;
120:         }
121: 
122:         if ($model->getMaxSendsToFriend() && $model->isExceedLimit()) {
123:             Mage::getSingleton('catalog/session')->addNotice(
124:                 $this->__('The messages cannot be sent more than %d times in an hour', $model->getMaxSendsToFriend())
125:             );
126:         }
127: 
128:         $this->loadLayout();
129:         $this->_initLayoutMessages('catalog/session');
130: 
131:         Mage::dispatchEvent('sendfriend_product', array('product' => $product));
132:         $data = Mage::getSingleton('catalog/session')->getSendfriendFormData();
133:         if ($data) {
134:             Mage::getSingleton('catalog/session')->setSendfriendFormData(true);
135:             $block = $this->getLayout()->getBlock('sendfriend.send');
136:             if ($block) {
137:                 $block->setFormData($data);
138:             }
139:         }
140: 
141:         $this->renderLayout();
142:     }
143: 
144:     /**
145:      * Send Email Post Action
146:      *
147:      */
148:     public function sendmailAction()
149:     {
150:         if (!$this->_validateFormKey()) {
151:             return $this->_redirect('*/*/send', array('_current' => true));
152:         }
153: 
154:         $product    = $this->_initProduct();
155:         $model      = $this->_initSendToFriendModel();
156:         $data       = $this->getRequest()->getPost();
157: 
158:         if (!$product || !$data) {
159:             $this->_forward('noRoute');
160:             return;
161:         }
162: 
163:         $categoryId = $this->getRequest()->getParam('cat_id', null);
164:         if ($categoryId) {
165:             $category = Mage::getModel('catalog/category')
166:                 ->load($categoryId);
167:             $product->setCategory($category);
168:             Mage::register('current_category', $category);
169:         }
170: 
171:         $model->setSender($this->getRequest()->getPost('sender'));
172:         $model->setRecipients($this->getRequest()->getPost('recipients'));
173:         $model->setProduct($product);
174: 
175:         try {
176:             $validate = $model->validate();
177:             if ($validate === true) {
178:                 $model->send();
179:                 Mage::getSingleton('catalog/session')->addSuccess($this->__('The link to a friend was sent.'));
180:                 $this->_redirectSuccess($product->getProductUrl());
181:                 return;
182:             }
183:             else {
184:                 if (is_array($validate)) {
185:                     foreach ($validate as $errorMessage) {
186:                         Mage::getSingleton('catalog/session')->addError($errorMessage);
187:                     }
188:                 }
189:                 else {
190:                     Mage::getSingleton('catalog/session')->addError($this->__('There were some problems with the data.'));
191:                 }
192:             }
193:         }
194:         catch (Mage_Core_Exception $e) {
195:             Mage::getSingleton('catalog/session')->addError($e->getMessage());
196:         }
197:         catch (Exception $e) {
198:             Mage::getSingleton('catalog/session')
199:                 ->addException($e, $this->__('Some emails were not sent.'));
200:         }
201: 
202:         // save form data
203:         Mage::getSingleton('catalog/session')->setSendfriendFormData($data);
204: 
205:         $this->_redirectError(Mage::getURL('*/*/send', array('_current' => true)));
206:     }
207: }
208: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0