From bd95d03e37a7b11da900d8d76e9f2d0b1feee927 Mon Sep 17 00:00:00 2001 From: Vincent Augagneur Date: Tue, 15 Oct 2013 09:30:26 +0200 Subject: [PATCH] //blockwishlist now use boostrap design --- modules/blockwishlist/blockwishlist.php | 210 ++++++++++++++++-------- 1 file changed, 141 insertions(+), 69 deletions(-) diff --git a/modules/blockwishlist/blockwishlist.php b/modules/blockwishlist/blockwishlist.php index 91bd4a994..4896ead54 100644 --- a/modules/blockwishlist/blockwishlist.php +++ b/modules/blockwishlist/blockwishlist.php @@ -96,76 +96,16 @@ class BlockWishList extends Module $this->_html .= '
'.$this->l('Activate module : Invalid choice.').'
'; $this->_html .= '
'.$this->l('Settings updated').'
'; } - $this->_displayForm(); - return ($this->_html); + + $this->_html .= $this->renderJS(); + $this->_html .= $this->renderForm(); + if (Tools::getValue('id_customer') && Tools::getValue('id_wishlist')) + $this->_html .= $this->renderList((int)Tools::getValue('id_wishlist')); + + + return $this->_html; } - private function _displayForm() - { - $this->_displayFormView(); - } - - private function _displayFormView() - { - $customers = Customer::getCustomers(); - if (!sizeof($customers)) - return; - $id_customer = (int)(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 = (int)(Tools::getValue('id_wishlist')); - break; - } - if (!$id_wishlist) - $id_wishlist = $wishlists[0]['id_wishlist']; - $this->_html .= ' - -
- -
'; - $this->_displayProducts((int)($id_wishlist)); - $this->_html .= ' - '; - } - public function hookHeader($params) { $this->context->controller->addCSS(($this->_path).'blockwishlist.css', 'all'); @@ -332,5 +272,137 @@ class BlockWishList extends Module { return $this->l('You must be logged in to manage your wishlists.'); } -} + + public function renderJS() + { + return ""; + } + + public function renderForm() + { + $customers = Customer::getCustomers(); + foreach ($customers as $key => $val) + $customers[$key]['name'] = $val['firstname'].' '.$val['lastname']; + + $fields_form = array( + 'form' => array( + 'legend' => array( + 'title' => $this->l('Listing'), + 'icon' => 'icon-cogs' + ), + 'input' => array( + array( + 'type' => 'select', + 'label' => $this->l('Customers :'), + 'name' => 'id_customer', + 'options' => array( + 'default' => array('value' => 0, 'label' => $this->l('Choose customer')), + 'query' => $customers, + 'id' => 'id_customer', + 'name' => 'name' + ), + ) + ), + ), + ); + + if ($id_customer = Tools::getValue('id_customer')) + { + require_once(dirname(__FILE__).'/WishList.php'); + $wishlists = WishList::getByIdCustomer($id_customer); + $fields_form['form']['input'][] = array( + 'type' => 'select', + 'label' => $this->l('Wishlist :'), + 'name' => 'id_wishlist', + 'options' => array( + 'default' => array('value' => 0, 'label' => $this->l('Choose wishlist')), + 'query' => $wishlists, + 'id' => 'id_wishlist', + 'name' => 'name' + ), + ); + } + + $helper = new HelperForm(); + $helper->show_toolbar = false; + $helper->table = $this->table; + $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT')); + $helper->default_form_language = $lang->id; + $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0; + $this->fields_form = array(); + $helper->identifier = $this->identifier; + $helper->submit_action = 'submitModule'; + $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name; + $helper->token = Tools::getAdminTokenLite('AdminModules'); + $helper->tpl_vars = array( + 'fields_value' => $this->getConfigFieldsValues(), + 'languages' => $this->context->controller->getLanguages(), + 'id_language' => $this->context->language->id + ); + + return $helper->generateForm(array($fields_form)); + } + + public function getConfigFieldsValues() + { + return array( + 'id_customer' => Tools::getValue('id_customer'), + 'id_wishlist' => Tools::getValue('id_wishlist'), + ); + } + + public function renderList($id_wishlist) + { + $wishlist = new WishList($id_wishlist); + $products = WishList::getProductByIdCustomer($id_wishlist, $wishlist->id_customer, $this->context->language->id); + + foreach ($products as $key => $val) + { + $image = Image::getCover($val['id_product']); + $products[$key]['image'] = $this->context->link->getImageLink($val['link_rewrite'], $image['id_image'], 'small'); + } + + $fields_list = array( + 'image' => array( + 'title' => $this->l('Image'), + 'type' => 'image', + ), + 'name' => array( + 'title' => $this->l('Product'), + 'type' => 'text', + ), + 'attributes_small' => array( + 'title' => $this->l('Combination'), + 'type' => 'text', + ), + 'quantity' => array( + 'title' => $this->l('Quantity'), + 'type' => 'text', + ), + 'priority' => array( + 'title' => $this->l('Priority'), + 'type' => 'priority', + 'values' => array($this->l('High'), $this->l('Medium'), $this->l('Low')), + ) + ); + + + $helper = new HelperList(); + $helper->shopLinkType = ''; + $helper->simple_header = true; + $helper->actions = array(); + $helper->show_toolbar = false; + $helper->module = $this; + $helper->identifier = 'image'; + $helper->title = $this->l('Product list'); + $helper->table = $this->name; + $helper->token = Tools::getAdminTokenLite('AdminModules'); + $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name; + $helper->tpl_vars = array('priority' => array($this->l('High'), $this->l('Medium'), $this->l('Low'))); + + return $helper->generateList($products, $fields_list); + } +} \ No newline at end of file