Public Member Functions | |
toOptionArray () | |
send () | |
validate () | |
setIp ($ip) | |
setRecipients ($recipients) | |
setProduct ($product) | |
setSender ($sender) | |
getSendCount ($ip, $startTime) | |
getMaxSendsToFriend () | |
getTemplate () | |
getMaxRecipients () | |
canEmailToFriend () | |
register () | |
Public Attributes | |
const | XML_PATH_SENDFRIEND_EMAIL_TEMPLATE = 'sendfriend/email/template' |
Protected Member Functions | |
_construct () | |
Protected Attributes | |
$_names = array() | |
$_emails = array() | |
$_sender = array() | |
$_ip = 0 | |
$_product = null | |
$_period = 3600 | |
$_cookieName = 'stf' |
Definition at line 27 of file Sendfriend.php.
_construct | ( | ) | [protected] |
Enter description here...
Reimplemented from Varien_Object.
Definition at line 44 of file Sendfriend.php.
00045 { 00046 $this->_init('sendfriend/sendfriend'); 00047 }
canEmailToFriend | ( | ) |
Check if user is allowed to email product to a friend
Definition at line 220 of file Sendfriend.php.
00221 { 00222 if (!Mage::getStoreConfig('sendfriend/email/enabled')) { 00223 return false; 00224 } 00225 if (!Mage::getStoreConfig('sendfriend/email/allow_guest') 00226 && !Mage::getSingleton('customer/session')->isLoggedIn()) { 00227 return false; 00228 } 00229 return true; 00230 }
getMaxRecipients | ( | ) |
Get max allowed recipients for "Send to a Friend" function
Definition at line 210 of file Sendfriend.php.
00211 { 00212 return max(0, (int) Mage::getStoreConfig('sendfriend/email/max_recipients')); 00213 }
getMaxSendsToFriend | ( | ) |
Get max allowed uses of "Send to Friend" function per hour
Definition at line 190 of file Sendfriend.php.
00191 { 00192 return max(0, (int) Mage::getStoreConfig('sendfriend/email/max_per_hour')); 00193 }
getSendCount | ( | $ | ip, | |
$ | startTime | |||
) |
Definition at line 179 of file Sendfriend.php.
00180 { 00181 $count = $this->_getResource()->getSendCount($this, $ip, $startTime); 00182 return $count; 00183 }
getTemplate | ( | ) |
Get current "Send to friend" template
Definition at line 200 of file Sendfriend.php.
00201 { 00202 return Mage::getStoreConfig('sendfriend/email/template'); 00203 }
register | ( | ) |
Check and register object
Definition at line 302 of file Sendfriend.php.
00303 { 00304 if (!Mage::registry('send_to_friend_model')) { 00305 Mage::register('send_to_friend_model', $this); 00306 } 00307 return $this; 00308 }
send | ( | ) |
Definition at line 62 of file Sendfriend.php.
00063 { 00064 $translate = Mage::getSingleton('core/translate'); 00065 /* @var $translate Mage_Core_Model_Translate */ 00066 $translate->setTranslateInline(false); 00067 00068 $errors = array(); 00069 00070 $this->_emailModel = Mage::getModel('core/email_template'); 00071 $message = nl2br(htmlspecialchars($this->_sender['message'])); 00072 $sender = array( 00073 'name' => strip_tags($this->_sender['name']), 00074 'email' => strip_tags($this->_sender['email']) 00075 ); 00076 00077 foreach($this->_emails as $key => $email) { 00078 $this->_emailModel->setDesignConfig(array('area'=>'frontend', 'store'=>$this->getStoreId())) 00079 ->sendTransactional( 00080 Mage::getStoreConfig(self::XML_PATH_SENDFRIEND_EMAIL_TEMPLATE), 00081 $sender, 00082 $email, 00083 $this->_names[$key], 00084 array( 00085 'name' => $this->_names[$key], 00086 'email' => $email, 00087 'product_name' => $this->_product->getName(), 00088 'product_url' => $this->_product->getProductUrl(), 00089 'message' => $message, 00090 'sender_name' => strip_tags($this->_sender['name']), 00091 'sender_email' => strip_tags($this->_sender['email']), 00092 'product_image' => Mage::helper('catalog/image')->init($this->_product, 'small_image')->resize(75), 00093 ) 00094 ); 00095 } 00096 00097 $translate->setTranslateInline(true); 00098 00099 return $this; 00100 }
setIp | ( | $ | ip | ) |
setProduct | ( | $ | product | ) |
setRecipients | ( | $ | recipients | ) |
Definition at line 165 of file Sendfriend.php.
00166 { 00167 $this->_emails = array_unique($recipients['email']); 00168 $this->_names = $recipients['name']; 00169 }
setSender | ( | $ | sender | ) |
toOptionArray | ( | ) |
Definition at line 49 of file Sendfriend.php.
00050 { 00051 if(!$collection = Mage::registry('config_system_email_template')) { 00052 $collection = Mage::getResourceModel('core/email_template_collection') 00053 ->load(); 00054 00055 Mage::register('config_system_email_template', $collection); 00056 } 00057 $options = $collection->toOptionArray(); 00058 array_unshift($options, array('value'=>'', 'label'=>'')); 00059 return $options; 00060 }
validate | ( | ) |
Definition at line 102 of file Sendfriend.php.
00103 { 00104 $errors = array(); 00105 $helper = Mage::helper('sendfriend'); 00106 00107 if (empty($this->_sender['name'])) { 00108 $errors[] = $helper->__('Sender name can\'t be empty'); 00109 } 00110 00111 if (!isset($this->_sender['email']) || !Zend_Validate::is($this->_sender['email'], 'EmailAddress')) { 00112 $errors[] = $helper->__('Invalid sender email'); 00113 } 00114 00115 if (empty($this->_sender['message'])) { 00116 $errors[] = $helper->__('Message can\'t be empty'); 00117 } 00118 00119 foreach ($this->_emails as $email) { 00120 if (!Zend_Validate::is($email, 'EmailAddress')) { 00121 $errors[] = $helper->__('You input invalid email address for recipient'); 00122 break; 00123 } 00124 } 00125 00126 if (!$this->canEmailToFriend()) { 00127 $errors[] = $helper->__('You cannot email this product to a friend'); 00128 } 00129 00130 if ($this->_getSendToFriendCheckType()) { 00131 $amount = $this->_amountByCookies(); 00132 } else { 00133 $amount = $this->_amountByIp(); 00134 } 00135 00136 if ($amount >= $this->getMaxSendsToFriend()){ 00137 $errors[] = $helper->__('You have exceeded limit of %d sends in an hour', $this->getMaxSendsToFriend()); 00138 } 00139 00140 $maxRecipients = $this->getMaxRecipients(); 00141 if (count($this->_emails) > $maxRecipients) { 00142 $errors[] = $helper->__('You cannot send more than %d emails at a time', $this->getMaxRecipients()); 00143 } 00144 00145 if (count($this->_emails) < 1) { 00146 $errors[] = $helper->__('You have to specify at least one recipient'); 00147 } 00148 00149 if (!$this->getTemplate()){ 00150 $errors[] = $helper->__('Email template is not specified by administrator'); 00151 } 00152 00153 00154 if (empty($errors)) { 00155 return true; 00156 } 00157 return $errors; 00158 }
$_cookieName = 'stf' [protected] |
Definition at line 42 of file Sendfriend.php.
$_emails = array() [protected] |
Definition at line 35 of file Sendfriend.php.
$_ip = 0 [protected] |
Definition at line 37 of file Sendfriend.php.
$_names = array() [protected] |
Definition at line 34 of file Sendfriend.php.
$_period = 3600 [protected] |
Definition at line 40 of file Sendfriend.php.
$_product = null [protected] |
Definition at line 38 of file Sendfriend.php.
$_sender = array() [protected] |
Definition at line 36 of file Sendfriend.php.
const XML_PATH_SENDFRIEND_EMAIL_TEMPLATE = 'sendfriend/email/template' |
XML configuration paths
Definition at line 32 of file Sendfriend.php.