Advertisement
Guest User

mywishlist.php

a guest
May 1st, 2014
787
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.35 KB | None | 0 0
  1. <?php
  2. /*
  3. * 2007-2013 PrestaShop
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Academic Free License (AFL 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/afl-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@prestashop.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 PrestaShop to newer
  18. * versions in the future. If you wish to customize PrestaShop for your
  19. * needs please refer to http://www.prestashop.com for more information.
  20. *
  21. *  @author PrestaShop SA <contact@prestashop.com>
  22. *  @copyright  2007-2013 PrestaShop SA
  23. *  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
  24. *  International Registered Trademark & Property of PrestaShop SA
  25. */
  26.  
  27. /* SSL Management */
  28. $useSSL = true;
  29.  
  30. include(dirname(__FILE__).'/../../config/config.inc.php');
  31. include(dirname(__FILE__).'/../../header.php');
  32. include_once(dirname(__FILE__).'/WishList.php');
  33.  
  34. $context = Context::getContext();
  35. $errors = array();
  36.  
  37. Tools::displayFileAsDeprecated();
  38.  
  39. // Instance of module class for translations
  40. $module = new BlockWishList();
  41.  
  42. if ($context->customer->isLogged())
  43. {
  44.     $add = Tools::getIsset('add');
  45.     $add = (empty($add) === false ? 1 : 0);
  46.     $delete = Tools::getIsset('deleted');
  47.     $delete = (empty($delete) === false ? 1 : 0);
  48.     $id_wishlist = Tools::getValue('id_wishlist');
  49.     if (Tools::isSubmit('submitWishlist'))
  50.     {
  51.         if (Configuration::get('PS_TOKEN_ACTIVATED') == 1 AND
  52.             strcmp(Tools::getToken(), Tools::getValue('token')))
  53.             $errors[] = $module->l('Invalid token', 'mywishlist');
  54.         if (!sizeof($errors))
  55.         {
  56.             $name = Tools::getValue('name');
  57.             if (empty($name))
  58.                 $errors[] = $module->l('You must specify a name.', 'mywishlist');
  59.             if (WishList::isExistsByNameForUser($name))
  60.                 $errors[] = $module->l('This name is already used by another list.', 'mywishlist');
  61.            
  62.             if(!sizeof($errors))
  63.             {
  64.                 $wishlist = new WishList();
  65.                 $wishlist->name = $name;
  66.                 $wishlist->id_customer = (int)$context->customer->id;
  67.                 $wishlist->id_shop = $context->shop->id;
  68.                 $wishlist->id_shop_group = $context->shop->id_shop_group;
  69.                 list($us, $s) = explode(' ', microtime());
  70.                 srand($s * $us);
  71.                 $wishlist->token = strtoupper(substr(sha1(uniqid(rand(), true)._COOKIE_KEY_.$context->customer->id), 0, 16));
  72.                 $wishlist->add();
  73.                 Mail::Send($context->language->id, 'wishlink', Mail::l('Your wishlist\'s link', $context->language->id),
  74.                     array(
  75.                     '{wishlist}' => $wishlist->name,
  76.                     '{message}' => Tools::getProtocol().htmlentities($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__.'modules/blockwishlist/view.php?token='.$wishlist->token),
  77.                     $context->customer->email, $context->customer->firstname.' '.$context->customer->lastname, NULL, strval(Configuration::get('PS_SHOP_NAME')), NULL, NULL, dirname(__FILE__).'/mails/');
  78.             }
  79.         }
  80.     }
  81.     else if ($add)
  82.         WishList::addCardToWishlist($context->customer->id, Tools::getValue('id_wishlist'), $context->language->id);
  83.     else if ($delete AND empty($id_wishlist) === false)
  84.     {
  85.         $wishlist = new WishList((int)($id_wishlist));
  86.         if (Validate::isLoadedObject($wishlist))
  87.             $wishlist->delete();
  88.         else
  89.             $errors[] = $module->l('Cannot delete this wishlist', 'mywishlist');
  90.     }
  91.     $context->smarty->assign('wishlists', WishList::getByIdCustomer($context->customer->id));
  92.     $context->smarty->assign('nbProducts', WishList::getInfosByIdCustomer($context->customer->id));
  93. }
  94. else
  95. {
  96.     Tools::redirect('index.php?controller=authentication&back=modules/blockwishlist/mywishlist.php');
  97. }
  98.  
  99. $context->smarty->assign(array(
  100.     'id_customer' => (int)$context->customer->id,
  101.     'errors' => $errors
  102. ));
  103.  
  104. if (Tools::file_exists_cache(_PS_THEME_DIR_.'modules/blockwishlist/mywishlist.tpl'))
  105.     $context->smarty->display(_PS_THEME_DIR_.'modules/blockwishlist/mywishlist.tpl');
  106. elseif (Tools::file_exists_cache(dirname(__FILE__).'/views/templates/front/mywishlist.tpl'))
  107.     $context->smarty->display(dirname(__FILE__).'/views/templates/front/mywishlist.tpl');
  108. else
  109.     echo $module->l('No template found', 'mywishlist');
  110.  
  111. include(dirname(__FILE__).'/../../footer.php');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement