Example #1
0
 /**
  * Send Email Post Action and increase the counter for the captcha displaying feature
  * Work with the javascript pop-up and not just the normal form
  * redirects to the form if the form key is not valid or the fields validation failed.
  * Otherwise sets body to "success" to reload the page and exit the popup
  *
  *
  * @return void
  */
 public function sendmailAction()
 {
     if (!$this->_validateFormKey()) {
         return $this->_redirect('*/*/send', array('_current' => true));
     }
     /* @var $oProduct Mage_Catalog_Model_Product */
     $oProduct = $this->_initProduct();
     /* @var $oSendToFriendModel Mage_Sendfriend_Model_Sendfriend */
     $oSendToFriendModel = $this->_initSendToFriendModel();
     $aFormData = $this->getRequest()->getPost();
     if (!$oProduct || !$aFormData) {
         $this->_forward('noRoute');
         return;
     }
     $iCategoryId = $this->getRequest()->getParam('cat_id', null);
     if ($iCategoryId) {
         /* @var $oCategory Mage_Catalog_Model_Category */
         $oCategory = Mage::getModel('catalog/category')->load($iCategoryId);
         $oProduct->setCategory($oCategory);
         Mage::register('current_category', $oCategory);
     }
     $aSender = $this->getRequest()->getPost('sender');
     $oSendToFriendModel->setSender($aSender);
     $oSendToFriendModel->setRecipients($this->getRequest()->getPost('recipients'));
     $oSendToFriendModel->setProduct($oProduct);
     try {
         $mValidate = $oSendToFriendModel->validate();
         if ($mValidate === true) {
             $oSendToFriendModel->send();
             Mage::getSingleton('catalog/session')->addSuccess($this->__('The link to a friend was sent.'));
             // increase counter for captcha limits
             if (Mage::helper('captcha')->isSendFriendCaptchaRequired()) {
                 $oCaptchaChecker = Mage::getModel('captcha/captchachecker');
                 $oCaptchaChecker->incCounter(Sitewards_Captcha_Block_Sendfriend_Send::CAPTCHA_BLOCK_ID);
             }
             $this->_redirect('*/*/closepopup', array('id' => $oProduct->getId()));
             return;
         } else {
             if (is_array($mValidate)) {
                 foreach ($mValidate as $sErrorMessage) {
                     Mage::getSingleton('catalog/session')->addError($sErrorMessage);
                 }
             } else {
                 Mage::getSingleton('catalog/session')->addError($this->__('There were some problems with the data.'));
             }
         }
     } catch (Mage_Core_Exception $oException) {
         Mage::getSingleton('catalog/session')->addError($oException->getMessage());
     } catch (Exception $oException) {
         Mage::getSingleton('catalog/session')->addException($oException, $this->__('Some emails were not sent.'));
     }
     // save form data
     Mage::getSingleton('catalog/session')->setSendfriendFormData($aFormData);
     $this->_redirectError(Mage::getURL('*/*/send', array('_current' => true)));
 }
 public function resultAction()
 {
     $this->loadLayout();
     try {
         Mage::getSingleton('catalogsearch/advanced')->addFilters($this->getRequest()->getQuery());
     } catch (Mage_Core_Exception $e) {
         Mage::getSingleton('catalogsearch/session')->addError($e->getMessage());
         $this->_redirectError(Mage::getURL('*/*/'));
     }
     $this->renderLayout();
 }
 /**
  * Send Email Post Action
  *
  */
 public function sendmailAction()
 {
     if (!$this->_validateFormKey()) {
         return $this->_redirect('*/*/send', array('_current' => true));
     }
     $product = $this->_initProduct();
     $model = $this->_initSendToFriendModel();
     $data = $this->getRequest()->getPost();
     if (!$product || !$data) {
         $this->_forward('noRoute');
         return;
     }
     $categoryId = $this->getRequest()->getParam('cat_id', null);
     if ($categoryId) {
         $category = Mage::getModel('catalog/category')->load($categoryId);
         $product->setCategory($category);
         Mage::register('current_category', $category);
     }
     $model->setSender($this->getRequest()->getPost('sender'));
     $model->setRecipients($this->getRequest()->getPost('recipients'));
     $model->setProduct($product);
     try {
         $validate = $model->validate();
         if ($validate === true) {
             $model->send();
             Mage::getSingleton('catalog/session')->addSuccess($this->__('The link to a friend was sent.'));
             header('Location: ' . $product->getProductUrl());
             exit;
             return;
         } else {
             if (is_array($validate)) {
                 foreach ($validate as $errorMessage) {
                     Mage::getSingleton('catalog/session')->addError($errorMessage);
                 }
             } else {
                 Mage::getSingleton('catalog/session')->addError($this->__('There were some problems with the data.'));
             }
         }
     } catch (Mage_Core_Exception $e) {
         Mage::getSingleton('catalog/session')->addError($e->getMessage());
     } catch (Exception $e) {
         Mage::getSingleton('catalog/session')->addException($e, $this->__('Some emails were not sent.'));
     }
     // save form data
     Mage::getSingleton('catalog/session')->setSendfriendFormData($data);
     $this->_redirectError(Mage::getURL('*/*/send', array('_current' => true)));
 }
Example #4
0
 protected function get3DSecureURL()
 {
     return Mage::getURL('cybersource/payment/cybersourcepayerauthform', array('_forced_secure' => true));
     //return Mage::getURL('cybersource/payment/cybersourcePayerAuthSubmitDebug');
 }
<?php

$now = strtotime("now");
$day = date('D');
if ($day == 'Sat' || $day == 'Sun') {
    $deadline = strtotime("Monday 14:00");
} else {
    $deadline = strtotime("today 14:00");
}
if ($deadline < $now) {
    $deadline = strtotime("tomorrow 14:00");
}
$seconds = abs($deadline - $now);
$hours = floor($seconds / 3600);
$mins = floor(($seconds - $hours * 3600) / 60);
$secs = floor($seconds - $hours * 3600 - $mins * 60);
if ($day != 'Sat' && $day != 'Sun') {
    echo "Order in the next <strong><a href='" . Mage::getURL('') . "shipping'>" . $hours . " hours " . $mins . " minutes</a></strong> for same day despatch (Mon-Fri only)";
}
Example #6
0
 public function sendmailAction()
 {
     if (!$this->_validateFormKey()) {
         return $this->_redirect('*/*/send', array('_current' => true));
     }
     $product = $this->_initProduct();
     $data = $this->getRequest()->getPost();
     if (!$product || !$data) {
         $this->_forward('noRoute');
         return;
     }
     $message = nl2br(htmlspecialchars((string) $this->getRequest()->getPost('message')));
     $subject = nl2br(htmlspecialchars((string) $this->getRequest()->getPost('subject')));
     $from = nl2br(htmlspecialchars((string) $this->getRequest()->getPost('from')));
     $to = nl2br(htmlspecialchars((string) $this->getRequest()->getPost('to')));
     $cc = nl2br(htmlspecialchars((string) $this->getRequest()->getPost('cc')));
     $translate = Mage::getSingleton('core/translate');
     /* @var $translate Mage_Core_Model_Translate */
     $translate->setTranslateInline(false);
     try {
         $customer = Mage::getSingleton('customer/session')->getCustomer();
         /*if share rss added rss feed to email template*/
         /* @var $emailModel Mage_Core_Model_Email_Template */
         $emailModel = Mage::getModel('core/email_template')->loadDefault('sendfriend_email_template');
         $emailModel->setTemplateSubject($subject);
         $emailModel->setSenderEmail($from);
         $emailModel->setSenderName($from);
         $entries_list = $this->getLayout()->createBlock('core/template')->setTemplate('sendfriend/email.phtml')->setProductId((int) $this->getRequest()->getParam('id'))->toHtml();
         if ($cc) {
             $emailModel->getMail()->addCC($cc);
         }
         $email_template_variables = array('entries_list' => $entries_list, 'message' => $message);
         $emails = explode(',', $this->getRequest()->getPost('to'));
         foreach ($emails as $value) {
             $emailModel->send($value, '', $email_template_variables);
         }
         Mage::getSingleton('catalog/session')->addSuccess($this->__('The link to a friend was sent.'));
         $this->_redirectSuccess($product->getProductUrl());
         return;
     } catch (Exception $e) {
         $translate->setTranslateInline(true);
         Mage::getSingleton('catalog/session')->addError($e->getMessage());
         //$this->_redirect('*/*/share');
     }
     /*$categoryId = $this->getRequest()->getParam('cat_id', null);
             if ($categoryId) {
                 $category = Mage::getModel('catalog/category')
                     ->load($categoryId);
                 $product->setCategory($category);
                 Mage::register('current_category', $category);
             }
     
             $model->setSender($this->getRequest()->getPost('sender'));
             $model->setRecipients($this->getRequest()->getPost('recipients'));
             $model->setProduct($product);
     		 * */
     /*try {
           $validate = $model->validate();
           if ($validate === true) {
               $model->send();
               Mage::getSingleton('catalog/session')->addSuccess($this->__('The link to a friend was sent.'));
               $this->_redirectSuccess($product->getProductUrl());
               return;
           }
           else {
               if (is_array($validate)) {
                   foreach ($validate as $errorMessage) {
                       Mage::getSingleton('catalog/session')->addError($errorMessage);
                   }
               }
               else {
                   Mage::getSingleton('catalog/session')->addError($this->__('There were some problems with the data.'));
               }
           }
       }
       catch (Mage_Core_Exception $e) {
           Mage::getSingleton('catalog/session')->addError($e->getMessage());
       }
       catch (Exception $e) {
           Mage::getSingleton('catalog/session')
               ->addException($e, $this->__('Some emails were not sent.'));
       }*/
     // save form data
     Mage::getSingleton('catalog/session')->setSendfriendFormData($data);
     $this->_redirectError(Mage::getURL('*/*/send', array('_current' => true)));
 }
Example #7
0
 public function showbannerAction()
 {
     $post = $this->getRequest()->getPost();
     $voucher_code = Mage::getSingleton('core/session')->getData('voucher_code');
     $ccode = Mage::getSingleton("checkout/session")->getData("ccode");
     if ($ccode == 'valentinesFreeShipping' && Mage::getURL('onepage') != $_SERVER["HTTP_REFERER"] || $post['page'] == 'valentines-day') {
         Mage::getSingleton("checkout/session")->setData("ccode", '');
         Mage::getSingleton("checkout/session")->setData("ccode2", '');
         Mage::getSingleton('checkout/cart')->getQuote()->setCouponCode('')->save();
         Mage::helper('checkout/cart')->getQuote()->setData('coupon_code', '')->save();
         Mage::getSingleton('core/session', array('name' => 'frontend'))->start();
         $quote = Mage::getSingleton('checkout/session')->getQuote();
         $quote->delete();
     }
     if ($ccode == 'valentinesFreeShipping' || $post['page'] == 'valentines-day') {
         die;
     }
     $survey_results = Mage::getSingleton('core/session')->getData('survey_results_saved');
     if ($post['page'] != 'groupon' && $post['page'] != 'survey' && Mage::getURL('onepage') != $_SERVER["HTTP_REFERER"]) {
         if (!empty($voucher_code)) {
             Mage::getSingleton('core/session')->setData('voucher_code', '');
             Mage::getSingleton("checkout/session")->setData("ccode", '');
             Mage::getSingleton('checkout/cart')->getQuote()->setCouponCode('')->save();
             Mage::helper('checkout/cart')->getQuote()->setData('coupon_code', '')->save();
             Mage::getSingleton('core/session', array('name' => 'frontend'))->start();
             $quote = Mage::getSingleton('checkout/session')->getQuote();
             $quote->delete();
             // voucher backup info to restore checkout
             Mage::getSingleton('core/session')->setData('voucher_code_applied', $voucher_code);
         }
     }
     if (Mage::getURL('onepage') == $_SERVER["HTTP_REFERER"] && !empty($voucher_code) || $post['page'] == 'survey' && !empty($voucher_code)) {
         Mage::getSingleton('core/session')->setData('voucher_code_applied', '');
     }
     $ccode2 = Mage::getSingleton("checkout/session")->getData("ccode2");
     $hide_banner = Mage::getSingleton("checkout/session")->getData("hide_banner");
     if (!empty($post['ccode']) || isset($voucher_code)) {
         $hide_banner = 1;
     }
     if ($post['vn'] == 'np') {
         $hide_banner = 0;
     }
     if (!empty($ccode2)) {
         $ccode = $ccode2;
     }
     $codes50F = array('freeshipping50off', '50f');
     $is50F = false;
     $html_banner = '';
     $has_voucher = Mage::getSingleton('core/session')->getData('voucher_code_applied');
     if (!empty($has_voucher)) {
         $html_banner = '<div id="coupon-banner">';
         $html_banner .= '<p class="voucher-msg""><a href="' . Mage::getUrl('applypopupcoupon/index/appply_groupon') . '">Click here</a> to complete your Groupon checkout.</p>';
         $html_banner .= '<a href="#" id="close_coupon_banner" onclick="close_coupon_banner()">x</a>';
         $html_banner .= '</div>';
         echo $html_banner;
         die;
     }
     $oCoupon = Mage::getModel('salesrule/coupon')->load($ccode, 'code');
     $oRule = Mage::getModel('salesrule/rule')->load($oCoupon->getRuleId());
     $discount_amount = (int) $oRule->getDiscountAmount();
     $action = $oRule->getSimpleAction();
     $free_shipping = (int) $oRule->getSimpleFreeShipping();
     $coupon_data = $oRule->getData();
     $discount_text = '$' . $discount_amount;
     if ($coupon_data['simple_action'] == 'by_percent') {
         $discount_text = $discount_amount . '% Off';
     }
     foreach ($codes50F as $code50F) {
         if (strpos(strtolower($ccode), $code50F) !== false) {
             $is50F = true;
         }
     }
     $banner_text = '';
     if ($discount_amount > 0) {
         if ($action == 'by_fixed') {
             $banner_text .= '$';
         }
         $banner_text .= $discount_amount;
         if ($action == 'by_percent') {
             $banner_text .= '%';
         }
     }
     if ($free_shipping != 0 && $discount_amount != 0) {
         $banner_text .= ' &amp; ';
     }
     $banner_text_mobile = $banner_text;
     if ($free_shipping != 0) {
         $banner_text .= 'FREE Shipping on your first order';
         $banner_text_mobile .= 'FREE Shipping';
     } else {
         $banner_text .= ' Off ';
         $banner_text_mobile .= ' Off ';
     }
     $banner_text .= ' coupon has been applied!';
     $banner_text_mobile .= ' coupon has been applied!';
     if ($is50F) {
         $banner_text = "{$discount_text} &amp; FREE Shipping on your first order coupon has been applied!";
         $banner_text_mobile = "<span class=\"large-text\">{$discount_text} &amp; FREE Shipping coupon has been applied!</span>";
     }
     if ($ccode != '' && $hide_banner != 1 && ($discount_amount > 0 || $free_shipping > 0)) {
         $html_banner = '<div id="coupon-banner">';
         $html_banner .= '<p class="desktop_only"><strong>SWEET DEAL!</strong> ' . $banner_text . '</p>';
         $html_banner .= '<p class="mobile_only"><span ' . ($free_shipping != 0 ? 'class="large-text"' : '') . '>' . $banner_text_mobile . '</span></p>';
         $html_banner .= '<a href="#" id="close_coupon_banner" onclick="close_coupon_banner()">x</a>';
         $html_banner .= '</div>';
         echo $html_banner;
     } else {
         echo '';
     }
 }
Example #8
0
 public function getStore()
 {
     $this->output = '';
     // get state name
     $region_model = Mage::getModel('directory/region');
     if (is_object($region_model)) {
         $state = $region_model->load(Mage::getStoreConfig('shipping/origin/region_id'))->getDefaultName();
     }
     $name = Mage::getStoreConfig('system/store/name');
     $owner = Mage::getStoreConfig('trans_email/ident_general/name');
     $email = Mage::getStoreConfig('trans_email/ident_general/email');
     $country = Mage::getStoreConfig('shipping/origin/country_id');
     $website = Mage::getURL();
     $this->writeShipWorksStart();
     $this->writeStartTag("Store");
     $this->writeElement("Name", $name);
     $this->writeElement("CompanyOrOwner", $owner);
     $this->writeElement("Email", $email);
     $this->writeElement("State", $state);
     $this->writeElement("Country", $country);
     $this->writeElement("Website", $website);
     $this->writeCloseTag("Store");
     $this->writeCloseTag("ShipWorks");
     return $this->output;
 }
 protected function failureURL()
 {
     return Mage::getURL('checkout/cart');
 }
Example #10
0
 /**
  * Generate XML file
  *
  * @return Mage_Sitemap_Model_Sitemap
  */
 public function generateXml()
 {
     $io = new Varien_Io_File();
     $io->setAllowCreateFolders(true);
     $io->open(array('path' => $this->getPath()));
     if ($io->fileExists($this->getSitemapFilename()) && !$io->isWriteable($this->getSitemapFilename())) {
         Mage::throwException(Mage::helper('sitemap')->__('File "%s" cannot be saved. Please, make sure the directory "%s" is writeable by web server.', $this->getSitemapFilename(), $this->getPath()));
     }
     $io->streamOpen($this->getSitemapFilename());
     $io->streamWrite('<?xml version="1.0" encoding="UTF-8"?>' . "\n");
     $io->streamWrite('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:content="http://www.google.com/schemas/sitemap-content/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">' . "\n");
     $storeId = $this->getStoreId();
     $date = Mage::getSingleton('core/date')->gmtDate('Y-m-d');
     $baseUrl = Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
     /**
      * Generate categories sitemap
      */
     $changefreq = (string) Mage::getStoreConfig('sitemap/category/changefreq', $storeId);
     $priority = (string) Mage::getStoreConfig('sitemap/category/priority', $storeId);
     $collection = Mage::getResourceModel('sitemap/catalog_category')->getCollection($storeId);
     foreach ($collection as $item) {
         $xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>' . "\n", htmlspecialchars($baseUrl . $item->getUrl()), $date, $changefreq, $priority);
         $io->streamWrite($xml);
     }
     unset($collection);
     /**
      * Generate products sitemap
      */
     /**
      * Hans2103 override to include images in sitemap
      */
     $changefreq = (string) Mage::getStoreConfig('sitemap/product/changefreq', $storeId);
     $priority = (string) Mage::getStoreConfig('sitemap/product/priority', $storeId);
     $collection = Mage::getResourceModel('sitemap/catalog_product')->getCollection($storeId);
     foreach ($collection as $item) {
         $xml = '<url><loc>' . htmlspecialchars($baseUrl . $item->getUrl()) . '</loc>';
         $image = Mage::getResourceModel('catalog/product')->getAttributeRawValue($item->getId(), 'image', $storeId);
         $imageLoc = '';
         $imageTitle = '';
         if ($image) {
             $imageLoc = str_replace('index.php/', '', Mage::getURL('media/catalog/product') . substr($image, 1));
             $imageTitle = htmlspecialchars(Mage::getResourceModel('catalog/product')->getAttributeRawValue($item->getId(), 'name', $storeId));
             $xml .= '<image:image><image:loc>' . $imageLoc . '</image:loc><image:title>' . $imageTitle . '</image:title></image:image>';
         }
         $product = Mage::getModel('catalog/product')->load($item->getId());
         $_images = $product->getMediaGalleryImages();
         foreach ($_images as $image) {
             $xml .= '<image:image><image:loc>' . $image->getUrl() . '</image:loc></image:image>';
         }
         unset($product);
         $xml .= '<lastmod>' . $date . '</lastmod><changefreq>' . $changefreq . '</changefreq><priority>' . $priority . '</priority></url>' . "\n";
         $io->streamWrite($xml);
     }
     unset($collection);
     /**
      * Generate cms pages sitemap
      */
     $changefreq = (string) Mage::getStoreConfig('sitemap/page/changefreq', $storeId);
     $priority = (string) Mage::getStoreConfig('sitemap/page/priority', $storeId);
     $collection = Mage::getResourceModel('sitemap/cms_page')->getCollection($storeId);
     foreach ($collection as $item) {
         $xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>' . "\n", htmlspecialchars($baseUrl . $item->getUrl()), $date, $changefreq, $priority);
         $io->streamWrite($xml);
     }
     unset($collection);
     $io->streamWrite('</urlset>');
     $io->streamClose();
     $this->setSitemapTime(Mage::getSingleton('core/date')->gmtDate('Y-m-d H:i:s'));
     $this->save();
     return $this;
 }
 public function sendmailAction()
 {
     $this->_initProduct();
     $this->_initSendToFriendModel();
     $product = Mage::registry('product');
     if (!$product->getId() || !$product->isVisibleInCatalog()) {
         $this->_forward('noRoute');
         return;
     }
     $sendToFriendModel = Mage::registry('send_to_friend_model');
     if ($this->getRequest()->getPost()) {
         $sendToFriendModel->setSender($this->getRequest()->getParam('sender'));
         $sendToFriendModel->setRecipients($this->getRequest()->getParam('recipients'));
         $sendToFriendModel->setIp(Mage::getSingleton('log/visitor')->getRemoteAddr());
         $sendToFriendModel->setProduct($product);
         try {
             if ($sendToFriendModel->canSend()) {
                 $sendToFriendModel->send();
                 Mage::getSingleton('catalog/session')->addSuccess($this->__('Link to a friend was sent.'));
                 $this->_redirectSuccess($product->getProductUrl());
                 return;
             }
         } catch (Mage_Core_Exception $e) {
             Mage::getSingleton('catalog/session')->addError($e->getMessage());
         } catch (Exception $e) {
             echo $e;
             Mage::getSingleton('catalog/session')->addException($e, Mage::helper('sendfriend')->__('Some emails was not sent'));
         }
         $this->_redirectError(Mage::getURL('*/*/send', array('id' => $product->getId())));
     } else {
         $this->_forward('noRoute');
     }
 }
 /**
  * Send Email Post Action
  *
  */
 public function sendmailAction()
 {
     if (!$this->_validateFormKey()) {
         return $this->_redirect('*/*/send', array('_current' => true));
     }
     $product = $this->_initProduct();
     $model = $this->_initSendToFriendModel();
     $data = $this->getRequest()->getPost();
     if (!$product || !$data) {
         $this->_forward('noRoute');
         return;
     }
     $categoryId = $this->getRequest()->getParam('cat_id', null);
     if ($categoryId) {
         $category = Mage::getModel('catalog/category')->load($categoryId);
         $product->setCategory($category);
         Mage::register('current_category', $category);
     }
     $model->setSender($this->getRequest()->getPost('sender'));
     $model->setRecipients($this->getRequest()->getPost('recipients'));
     /*force add to customer*/
     $recipients = $this->getRequest()->getPost('recipients');
     $i = 0;
     $names = array();
     foreach ($recipients['name'] as $name) {
         $names[] = $name;
         $i += 1;
     }
     $mails = array();
     foreach ($recipients['email'] as $mail) {
         $mails[] = $mail;
     }
     $write = Mage::getSingleton('core/resource')->getConnection('core_write');
     $read = Mage::getSingleton('core/resource')->getConnection('core_read');
     for ($j = 0; $j < $i; $j++) {
         $email = $mails[$j];
         $select2 = "SELECT * FROM customer_entity WHERE email='" . $email . "' LIMIT 1";
         $isEmail = $read->fetchOne($select2);
         if (!$isEmail) {
             $today = date("Y-m-d H:i:s");
             $sql = "INSERT INTO customer_entity (entity_id, entity_type_id, attribute_set_id, website_id, email,group_id,increment_id,store_id,created_at,updated_at,is_active,disable_auto_group_change) VALUES (NULL, '1', '0', '0', '" . $email . "','1',NULL,'1','" . $today . "','" . $today . "','1','0')";
             $write->query($sql);
             $select = "SELECT entity_id FROM customer_entity ORDER BY entity_id DESC LIMIT 1";
             $id = $read->fetchOne($select);
             $name = $names[$j];
             $nm = explode(" ", $name);
             if ($nm[1] == "") {
                 $nm1[1] = " ";
             }
             $sql1 = "INSERT INTO customer_entity_varchar (value_id, entity_type_id , attribute_id , entity_id,value) VALUES (NULL, '1', '1', '" . $id . "', '" . $nm[0] . "')";
             $sql2 = "INSERT INTO customer_entity_varchar (value_id, entity_type_id , attribute_id , entity_id,value) VALUES (NULL, '1', '2', '" . $id . "', '" . $nm[1] . "')";
             $write->query($sql1);
             $write->query($sql2);
             //echo $sql;
             //echo $sql2;
         } else {
         }
     }
     /**end**/
     $model->setProduct($product);
     try {
         $validate = $model->validate();
         if ($validate === true) {
             $model->send();
             Mage::getSingleton('catalog/session')->addSuccess($this->__('The link to a friend was sent.'));
             $this->_redirectSuccess($product->getProductUrl());
             return;
         } else {
             if (is_array($validate)) {
                 foreach ($validate as $errorMessage) {
                     Mage::getSingleton('catalog/session')->addError($errorMessage);
                 }
             } else {
                 Mage::getSingleton('catalog/session')->addError($this->__('There were some problems with the data.'));
             }
         }
     } catch (Mage_Core_Exception $e) {
         Mage::getSingleton('catalog/session')->addError($e->getMessage());
     } catch (Exception $e) {
         Mage::getSingleton('catalog/session')->addException($e, $this->__('Some emails were not sent.'));
     }
     // save form data
     Mage::getSingleton('catalog/session')->setSendfriendFormData($data);
     $this->_redirectError(Mage::getURL('*/*/send', array('_current' => true)));
 }
 public function sendmailAction()
 {
     $product = $this->_initProduct();
     $sendToFriendModel = $this->_initSendToFriendModel();
     $data = $this->getRequest()->getPost();
     if (!$product || !$product->isVisibleInCatalog() || !$data) {
         $this->_forward('noRoute');
         return;
     }
     $categoryId = $this->getRequest()->getParam('cat_id', null);
     if ($categoryId && ($category = Mage::getModel('catalog/category')->load($categoryId))) {
         Mage::register('current_category', $category);
     }
     $sendToFriendModel->setSender($this->getRequest()->getPost('sender'));
     $sendToFriendModel->setRecipients($this->getRequest()->getPost('recipients'));
     $sendToFriendModel->setIp(Mage::getSingleton('log/visitor')->getRemoteAddr());
     $sendToFriendModel->setProduct($product);
     try {
         $validateRes = $sendToFriendModel->validate();
         if (true === $validateRes) {
             $sendToFriendModel->send();
             Mage::getSingleton('catalog/session')->addSuccess($this->__('Link to a friend was sent.'));
             $this->_redirectSuccess($product->getProductUrl());
             return;
         } else {
             Mage::getSingleton('catalog/session')->setFormData($data);
             if (is_array($validateRes)) {
                 foreach ($validateRes as $errorMessage) {
                     Mage::getSingleton('catalog/session')->addError($errorMessage);
                 }
             } else {
                 Mage::getSingleton('catalog/session')->addError($this->__('Some problems with data.'));
             }
         }
     } catch (Mage_Core_Exception $e) {
         Mage::getSingleton('catalog/session')->addError($e->getMessage());
     } catch (Exception $e) {
         Mage::getSingleton('catalog/session')->addException($e, $this->__('Some emails was not sent'));
     }
     $this->_redirectError(Mage::getURL('*/*/send', array('id' => $product->getId())));
 }