name = 'blockwishlist'; $this->tab = 'Blocks'; $this->version = 0.2; parent::__construct(); $this->displayName = $this->l('Wishlist block'); $this->description = $this->l('Adds a block containing the customer\'s wishlists'); } public function install() { if (!file_exists(dirname(__FILE__).'/'.self::INSTALL_SQL_FILE)) return (false); else if (!$sql = file_get_contents(dirname(__FILE__).'/'.self::INSTALL_SQL_FILE)) return (false); $sql = str_replace('PREFIX_', _DB_PREFIX_, $sql); $sql = preg_split("/;\s*[\r\n]+/", $sql); foreach ($sql AS $query) if($query) if(!Db::getInstance()->Execute(trim($query))) return false; if (!parent::install() OR !$this->registerHook('rightColumn') OR !$this->registerHook('productActions') OR !$this->registerHook('cart') OR !$this->registerHook('customerAccount') OR !$this->registerHook('header') OR !$this->registerHook('adminCustomers') OR !Configuration::updateValue('PS_BLOCK_WISHLIST_ACTIVATED', 1) ) return false; /* This hook is optional */ $this->registerHook('myAccountBlock'); return true; } public function uninstall() { return (Configuration::deleteByName('PS_BLOCK_WISHLIST_ACTIVATED') AND Db::getInstance()->Execute('DROP TABLE '._DB_PREFIX_.'wishlist') AND Db::getInstance()->Execute('DROP TABLE '._DB_PREFIX_.'wishlist_email') AND Db::getInstance()->Execute('DROP TABLE '._DB_PREFIX_.'wishlist_product') AND Db::getInstance()->Execute('DROP TABLE '._DB_PREFIX_.'wishlist_product_cart') AND parent::uninstall()); } public function getContent() { $this->_html = '

'.$this->displayName.'

'; if (Tools::isSubmit('submitSettings')) { $activated = Tools::getValue('activated'); if ($activated != 0 AND $activated != 1) $this->_html .= '
'.$this->l('Activate module : Invalid choice.').'
'; else Configuration::updateValue('PS_BLOCK_WISHLIST_ACTIVATED', intval($activated)); $this->_html .= '
'.$this->l('Confirmation').''.$this->l('Settings updated').'
'; } $this->_displayForm(); return ($this->_html); } private function _displayForm() { $this->_displayFormSettings(); $this->_displayFormView(); } private function _displayFormSettings() { $this->_html .= '
'.$this->l('Settings').'

'.$this->l('Activate module (Add blockwishlist and "Add to my wishlist" button)').'

'; } private function _displayFormView() { global $cookie; $customers = Customer::getCustomers(); if (!sizeof($customers)) return; $id_customer = intval(Tools::getValue('id_customer')); if (!$id_customer) $id_customer = $customers[0]['id_customer']; $this->_html .= '
'.$this->l('Listing').'
'; require_once(dirname(__FILE__).'/WishList.php'); $wishlists = WishList::getByIdCustomer($id_customer); if (!sizeof($wishlists)) return ($this->_html .= '
'); $id_wishlist = false; foreach ($wishlists AS $row) if ($row['id_wishlist'] == Tools::getValue('id_wishlist')) { $id_wishlist = intval(Tools::getValue('id_wishlist')); break; } if (!$id_wishlist) $id_wishlist = $wishlists[0]['id_wishlist']; $this->_html .= '
'; $this->_displayProducts(intval($id_wishlist)); $this->_html .= ' '; } public function hookHeader($params) { return ''; } public function hookRightColumn($params) { global $smarty, $errors; if (Configuration::get('PS_BLOCK_WISHLIST_ACTIVATED') == 0) return (null); require_once(dirname(__FILE__).'/WishList.php'); if ($params['cookie']->isLogged()) { $wishlists = Wishlist::getByIdCustomer($params['cookie']->id_customer); if (empty($params['cookie']->id_wishlist) === true || WishList::exists($params['cookie']->id_wishlist, $params['cookie']->id_customer) === false) { if (!sizeof($wishlists)) $id_wishlist = false; else { $id_wishlist = intval($wishlists[0]['id_wishlist']); $params['cookie']->id_wishlist = intval($id_wishlist); } } else $id_wishlist = $params['cookie']->id_wishlist; $smarty->assign(array( 'id_wishlist' => $id_wishlist, 'isLogged' => true, 'wishlist_products' => ($id_wishlist == false ? false : WishList::getProductByIdCustomer($id_wishlist, $params['cookie']->id_customer, $params['cookie']->id_lang, null, true)), 'wishlists' => $wishlists, 'ptoken' => Tools::getToken(false))); } else $smarty->assign(array('wishlist_products' => false, 'wishlists' => false)); return ($this->display(__FILE__, 'blockwishlist.tpl')); } public function hookLeftColumn($params) { return $this->hookRightColumn($params); } public function hookProductActions($params) { global $smarty; $smarty->assign('id_product', intval(Tools::getValue('id_product'))); return ($this->display(__FILE__, 'blockwishlist-extra.tpl')); } public function hookCustomerAccount($params) { global $smarty; return $this->display(__FILE__, 'my-account.tpl'); } public function hookMyAccountBlock($params) { return $this->hookCustomerAccount($params); } private function _displayProducts($id_wishlist) { global $cookie; include_once(dirname(__FILE__).'/WishList.php'); $wishlist = new WishList(intval($id_wishlist)); $products = WishList::getProductByIdCustomer(intval($id_wishlist), intval($wishlist->id_customer), intval($cookie->id_lang)); for ($i = 0; $i < sizeof($products); ++$i) { $obj = new Product(intval($products[$i]['id_product']), false, intval($cookie->id_lang)); if (!Validate::isLoadedObject($obj)) continue; else { $images = $obj->getImages(intval($cookie->id_lang)); foreach ($images AS $k => $image) { if ($image['cover']) { $products[$i]['cover'] = $obj->id.'-'.$image['id_image']; break; } } if (!isset($products[$i]['cover'])) $products[$i]['cover'] = Language::getIsoById(intval($cookie->id_lang)).'-default'; } } $this->_html .= ' '; $priority = array($this->l('High'), $this->l('Medium'), $this->l('Low')); foreach ($products as $product) { $this->_html .= ' '; } $this->_html .= '
'.$this->l('Product').' '.$this->l('Quantity').' '.$this->l('Priority').'
'.htmlentities($product['name'], ENT_COMPAT, 'UTF-8').' '.$product['name']; if (isset($product['attributes_small'])) $this->_html .= '
'.htmlentities($product['attributes_small'], ENT_COMPAT, 'UTF-8').''; $this->_html .= '
'.intval($product['quantity']).' '.$priority[intval($product['priority']) % 3].'
'; } public function hookAdminCustomers($params) { require_once(dirname(__FILE__).'/WishList.php'); $customer = new Customer(intval($params['id_customer'])); if (!Validate::isLoadedObject($customer)) die (Tools::displayError()); $this->_html = '

'.$this->l('Wishlists').'

'; $wishlists = WishList::getByIdCustomer(intval($customer->id)); if (!sizeof($wishlists)) $this->_html .= $customer->lastname.' '.$customer->firstname.' '.$this->l('had no wishlist'); else { $this->_html .= '
'; $id_wishlist = intval(Tools::getValue('id_wishlist')); if (!$id_wishlist) $id_wishlist = $wishlists[0]['id_wishlist']; $this->_html .= ''.$this->l('Wishlist').': '; $this->_displayProducts(intval($id_wishlist)); $this->_html .= '

'; return $this->_html; } } /* * Display Error from controler */ public function errorLogged() { return $this->l('You need to be logged to manage your wishlist'); } } ?>