Exemplo n.º 1
0
 /**
  * Assign wishlist template
  */
 public function assign()
 {
     $errors = array();
     if ($this->context->customer->isLogged()) {
         $add = Tools::getIsset('add');
         $add = empty($add) === false ? 1 : 0;
         $delete = Tools::getIsset('deleted');
         $delete = empty($delete) === false ? 1 : 0;
         $id_wishlist = Tools::getValue('id_wishlist');
         if (Tools::isSubmit('submitWishlist')) {
             if (Configuration::get('PS_TOKEN_ACTIVATED') == 1 and strcmp(Tools::getToken(), Tools::getValue('token'))) {
                 $errors[] = $this->module->l('Invalid token', 'mywishlist');
             }
             if (!sizeof($errors)) {
                 $name = Tools::getValue('name');
                 if (empty($name)) {
                     $errors[] = $this->module->l('You must specify a name.', 'mywishlist');
                 }
                 if (WishList::isExistsByNameForUser($name)) {
                     $errors[] = $this->module->l('This name is already used by another list.', 'mywishlist');
                 }
                 if (!sizeof($errors)) {
                     $wishlist = new WishList();
                     $wishlist->id_shop = $this->context->shop->id;
                     $wishlist->id_shop_group = $this->context->shop->id_shop_group;
                     $wishlist->name = $name;
                     $wishlist->id_customer = (int) $this->context->customer->id;
                     list($us, $s) = explode(' ', microtime());
                     srand($s * $us);
                     $wishlist->token = strtoupper(substr(sha1(uniqid(rand(), true) . _COOKIE_KEY_ . $this->context->customer->id), 0, 16));
                     $wishlist->add();
                     Mail::Send($this->context->language->id, 'wishlink', Mail::l('Your wishlist\'s link', $this->context->language->id), array('{wishlist}' => $wishlist->name, '{message}' => Tools::getProtocol() . htmlentities($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'modules/blockwishlist/view.php?token=' . $wishlist->token), $this->context->customer->email, $this->context->customer->firstname . ' ' . $this->context->customer->lastname, NULL, strval(Configuration::get('PS_SHOP_NAME')), NULL, NULL, $this->module->getLocalPath() . 'mails/');
                 }
             }
         } else {
             if ($add) {
                 WishList::addCardToWishlist($this->context->customer->id, Tools::getValue('id_wishlist'), $this->context->language->id);
             } else {
                 if ($delete and empty($id_wishlist) === false) {
                     $wishlist = new WishList((int) $id_wishlist);
                     if (Validate::isLoadedObject($wishlist)) {
                         $wishlist->delete();
                     } else {
                         $errors[] = $this->module->l('Cannot delete this wishlist', 'mywishlist');
                     }
                 }
             }
         }
         $this->context->smarty->assign('wishlists', WishList::getByIdCustomer($this->context->customer->id));
         $this->context->smarty->assign('nbProducts', WishList::getInfosByIdCustomer($this->context->customer->id));
     } else {
         Tools::redirect('index.php?controller=authentication&back=' . urlencode($this->context->link->getModuleLink('blockwishlist', 'mywishlist')));
     }
     $this->context->smarty->assign(array('id_customer' => (int) $this->context->customer->id, 'errors' => $errors, 'form_link' => $errors));
     $this->setTemplate('mywishlist.tpl');
 }
Exemplo n.º 2
0
 if (empty($context->cookie->id_wishlist) === true || $context->cookie->id_wishlist == false) {
     $context->smarty->assign('error', true);
 }
 if (($add || $delete) && empty($id_product) === false) {
     if (!isset($context->cookie->id_wishlist) || $context->cookie->id_wishlist == '') {
         $wishlist = new WishList();
         $wishlist->id_shop = $context->shop->id;
         $wishlist->id_shop_group = $context->shop->id_shop_group;
         $wishlist->default = 1;
         $mod_wishlist = new BlockWishList();
         $wishlist->name = $mod_wishlist->default_wishlist_name;
         $wishlist->id_customer = (int) $context->customer->id;
         list($us, $s) = explode(' ', microtime());
         srand($s * $us);
         $wishlist->token = strtoupper(substr(sha1(uniqid(rand(), true) . _COOKIE_KEY_ . $context->customer->id), 0, 16));
         $wishlist->add();
         $context->cookie->id_wishlist = (int) $wishlist->id;
     }
     if ($add && $quantity) {
         WishList::addProduct($context->cookie->id_wishlist, $context->customer->id, $id_product, $id_product_attribute, $quantity);
     } else {
         if ($delete) {
             WishList::removeProduct($context->cookie->id_wishlist, $context->customer->id, $id_product, $id_product_attribute);
         }
     }
 }
 $context->smarty->assign('products', WishList::getProductByIdCustomer($context->cookie->id_wishlist, $context->customer->id, $context->language->id, null, true));
 if (Tools::file_exists_cache(_PS_THEME_DIR_ . 'modules/blockwishlist/blockwishlist-ajax.tpl')) {
     $context->smarty->display(_PS_THEME_DIR_ . 'modules/blockwishlist/blockwishlist-ajax.tpl');
 } elseif (Tools::file_exists_cache(dirname(__FILE__) . '/blockwishlist-ajax.tpl')) {
     $context->smarty->display(dirname(__FILE__) . '/blockwishlist-ajax.tpl');