From 31169e5ff0d0cbb6fa8ddc4213aae5b61ae2d729 Mon Sep 17 00:00:00 2001 From: lLefevre Date: Mon, 21 Nov 2011 17:09:51 +0000 Subject: [PATCH] // fix bug in AdminTrackingController --- controllers/admin/AdminTrackingController.php | 359 ++++++------------ 1 file changed, 106 insertions(+), 253 deletions(-) diff --git a/controllers/admin/AdminTrackingController.php b/controllers/admin/AdminTrackingController.php index fecff63a1..5a8b83f3c 100644 --- a/controllers/admin/AdminTrackingController.php +++ b/controllers/admin/AdminTrackingController.php @@ -25,13 +25,8 @@ * International Registered Trademark & Property of PrestaShop SA */ -class AdminTrackingControllerCore extends AdminController +class AdminTrackingController extends AdminController { - public function __construct() - { - parent::__construct(); - } - public function postprocess() { if (Tools::getValue('id_product') && Tools::isSubmit('statusproduct')) @@ -41,33 +36,29 @@ class AdminTrackingControllerCore extends AdminController $this->action = 'status'; $this->className = 'Product'; } - else - if (Tools::getValue('id_category') && Tools::isSubmit('statuscategory')) + else if (Tools::getValue('id_category') && Tools::isSubmit('statuscategory')) { $this->table = 'category'; $this->identifier = 'id_category'; $this->action = 'status'; $this->className = 'Category'; } + parent::postprocess(); } public function initContent() { - //$tpl_vars['categories'] = $this->getObjects('categories_empty')->displayCategories(); $methods = get_class_methods($this); $tpl_vars['arrayList'] = array(); foreach ($methods as $method_name) if (preg_match('#getCustomList(.+)#', $method_name, $matches)) - $tpl_vars['arrayList'][Tools::toUnderscoreCase($matches[1])] = call_user_func(array($this,$matches[0])); - // $tpl_vars['categories'] = $this->getMonitorCategoriesEmpty(); - // $tpl_vars['products_disabled'] = $this->getObjects('products_disabled')->displayProducts(); - // $tpl_vars['products_nostock'] = $this->getObjects('products_nostock')->displayProducts(); - // attributes no stock is custom - // $tpl_vars['arrayList']['attributes_nostock'] = $this->getObjects('attributes_nostock')->displayAttributes(); - $this->context->smarty->assign($tpl_vars); - $this->display = 'view'; - parent::initContent(); + $this->content .= call_user_func(array($this,$matches[0])); + + $this->context->smarty->assign(array( + 'content' => $this->content, + 'url_post' => self::$currentIndex.'&token='.$this->token, + )); } public function getObjects($type) @@ -83,8 +74,7 @@ class AdminTrackingControllerCore extends AdminController FROM `'._DB_PREFIX_.'category_product` ) '; - // $this->_list['message'] = $this->l('List of empty categories:'); - break ; + break; case 'products_disabled': $sql = ' SELECT * @@ -92,7 +82,8 @@ class AdminTrackingControllerCore extends AdminController WHERE active = 0 '; $this->_list['message'] = $this->l('List of disabled products:'); - break ; + break; + case 'products_nostock': $sql = ' SELECT DISTINCT(id_product) @@ -108,27 +99,36 @@ class AdminTrackingControllerCore extends AdminController ) '; $this->_list['message'] = $this->l('List of out of stock products without attributes:'); - break ; + break; + case 'attributes_nostock': $sql = 'SELECT pa.*, ag.`id_attribute_group`, ag.`is_color_group`, agl.`name` AS group_name, al.`name` AS attribute_name, a.`id_attribute`, m.`name` AS manufacturer_name, pl.`name` AS name, p.`weight` AS product_weight, p.`active` AS active FROM `'._DB_PREFIX_.'product_attribute` pa - LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON pac.`id_product_attribute` = pa.`id_product_attribute` - LEFT JOIN `'._DB_PREFIX_.'attribute` a ON a.`id_attribute` = pac.`id_attribute` - LEFT JOIN `'._DB_PREFIX_.'attribute_group` ag ON ag.`id_attribute_group` = a.`id_attribute_group` - LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)$this->context->language->id.') - LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)$this->context->language->id.') - LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = pa.`id_product`) - LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = p.`id_product` AND pl.`id_lang` = '.(int)$this->context->language->id.$this->context->shop->addSqlRestrictionOnLang('pl').') + LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac + ON pac.`id_product_attribute` = pa.`id_product_attribute` + LEFT JOIN `'._DB_PREFIX_.'attribute` a + ON a.`id_attribute` = pac.`id_attribute` + LEFT JOIN `'._DB_PREFIX_.'attribute_group` ag + ON ag.`id_attribute_group` = a.`id_attribute_group` + LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al + ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)$this->context->language->id.') + LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl + ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)$this->context->language->id.') + LEFT JOIN `'._DB_PREFIX_.'product` p + ON (p.`id_product` = pa.`id_product`) + LEFT JOIN `'._DB_PREFIX_.'product_lang` pl + ON (pl.`id_product` = p.`id_product` AND pl.`id_lang` = '.(int)$this->context->language->id.$this->context->shop->addSqlRestrictionOnLang('pl').') '.Product::sqlStock('p', 'pa').' - LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (p.`id_manufacturer` = m.`id_manufacturer`) + LEFT JOIN `'._DB_PREFIX_.'manufacturer` m + ON (p.`id_manufacturer` = m.`id_manufacturer`) WHERE stock.quantity <= 0 ORDER BY pa.`id_product_attribute`'; $this->_list['message'] = $this->l('List of out of stock products with attributes:'); - break ; + break; } - $this->_list['obj'] = Db::getInstance()->executeS($sql); - return $this; + + return Db::getInstance()->executeS($sql); } public function getCustomListCategoriesEmpty() @@ -139,54 +139,32 @@ class AdminTrackingControllerCore extends AdminController $this->identifier = 'id_category'; $this->_defaultOrderBy = 'id_category'; $this->_defaultOrderWay = 'DESC'; + self::$currentIndex = 'index.php?controller=AdminCategories'; + $this->token = Tools::getAdminTokenLite('AdminCategories'); $this->addRowAction('edit'); $this->addRowAction('delete'); $this->addRowAction('view'); - $this->_filter = ' AND - a.id_category NOT IN ( - SELECT DISTINCT(cp.id_category) - FROM `'._DB_PREFIX_.'category_product` cp)'; - $this->fieldsDisplay = (array( 'id_category' => array('title' => $this->l('ID')), 'name' => array('title' => $this->l('Name')), 'description' => array('title' => $this->l('Description')), - 'active' => array('title' => $this->l('Status'), 'type' => 'bool', 'active' => 'status'), - 'action' => array('title' => $this->l('Actions')) + 'active' => array('title' => $this->l('Status'), 'type' => 'bool', 'active' => 'status') )); + + $this->_filter = ' AND a.id_category NOT IN ( + SELECT DISTINCT(cp.id_category) + FROM `'._DB_PREFIX_.'category_product` cp + )'; + $this->getObjects('categories_empty'); - $this->list_simple_header = 0; - $this->show_toolbar = 0; - $this->list_title = $this->l('List of empty categories:'); - $list = $this->initList(); - $this->_filter = ''; - return $list; - } + $this->tpl_list_vars = array('sub_title' => $this->l('List of empty categories:')); - public function displayCategories() - { - $content = ''; - if (isset($this->_list['obj'])) - { - $nbCategories = sizeof($this->_list['obj']); - $content .= '

'.$this->_list['message'].' '.$nbCategories.' '.$this->l('found').'

'; - if (!$nbCategories) - return $content; - $content .= ' - '; - $irow = 0; - foreach ($this->_list['obj'] AS $k => $category) - $content .= ''; - $content .= '
'.rtrim(getPath('index.php?controller=AdminCategory', $category['id_category']), ' >').'


'; - } - return $content; + return parent::initList(); } - public function getCustomListProductsAttributesNoStock() - { { $this->clearListOptions(); $this->table = 'product'; @@ -194,111 +172,36 @@ class AdminTrackingControllerCore extends AdminController $this->identifier = 'id_product'; $this->_defaultOrderBy = 'id_product'; $this->_defaultOrderWay = 'DESC'; - $this->fieldsDisplay = array( - 'ID' => array('title' => $this->l('ID')), - 'manufacturer' => array('title' => $this->l('Manufacturer')), - 'reference' => array('title' => $this->l('Reference')), - 'name' => array('title' => $this->l('Name')), - 'price' => array('title' => $this->l('Price')), - 'tax' => array('title' => $this->l('Tax')), - 'stock' => array('title' => $this->l('Stock')), - 'weight' => array('title' => $this->l('Weight')), - 'active' => array('title' => $this->l('Status'), 'type' => 'bool', 'active' => 'status'), - 'action' => array('title' => $this->l('Actions') - )); - $this->_join = ''; + self::$currentIndex = 'index.php?controller=AdminProducts'; + $this->token = Tools::getAdminTokenLite('AdminProducts'); + $this->show_toolbar = false; + $this->fieldsDisplay = array( + 'ID' => array('title' => $this->l('ID')), + 'manufacturer' => array('title' => $this->l('Manufacturer')), + 'reference' => array('title' => $this->l('Reference')), + 'name' => array('title' => $this->l('Name')), + 'price' => array('title' => $this->l('Price')), + 'tax' => array('title' => $this->l('Tax')), + 'stock' => array('title' => $this->l('Stock')), + 'weight' => array('title' => $this->l('Weight')), + 'active' => array('title' => $this->l('Status'), 'type' => 'bool', 'active' => 'status') + ); + $this->_filter = 'AND a.id_product IN ( - SELECT id_product - FROM `'._DB_PREFIX_.'product` - WHERE id_product IN ( - SELECT DISTINCT(id_product) - FROM `'._DB_PREFIX_.'product_attribute` - ) - AND quantity <= 0)'; - $this->list_title = $this->l('Product out of stock with attributes'); - $this->list_simple_header = 1; + SELECT id_product + FROM `'._DB_PREFIX_.'product` + WHERE id_product IN ( + SELECT DISTINCT(id_product) + FROM `'._DB_PREFIX_.'product_attribute` + ) + AND quantity <= 0 + )'; - $list = $this->initList(); - $this->_filter = ''; - return $list; + $this->tpl_list_vars = array('sub_title' => $this->l('List of out of stock products without attributes:')); + + return parent::initList(); } - $this->clearListOptions(); - $content = ''; - $this->table = 'attribute'; - $this->lang = true; - $this->identifier = 'id_attribute'; - $this->_defaultOrderBy = 'id_attribute'; - $this->_defaultOrderWay = 'DESC'; - if (isset($this->_list['obj'])) - { - $nbAttributes = sizeof($this->_list['obj']); - $content .= '

'.$this->_list['message'].' '.$nbAttributes.' '.$this->l('found').'

'; - if (!$nbAttributes) - return $content; - $this->fieldsDisplay = array( - 'ID' => array('title' => $this->l('ID')), - 'manufacturer' => array('title' => $this->l('Manufacturer')), - 'reference' => array('title' => $this->l('Reference')), - 'name' => array('title' => $this->l('Name')), - 'price' => array('title' => $this->l('Price')), - 'tax' => array('title' => $this->l('Tax')), - 'stock' => array('title' => $this->l('Stock')), - 'weight' => array('title' => $this->l('Weight')), - 'status' => array('title' => $this->l('Status')), - 'action' => array('title' => $this->l('Actions')) - ); - - $content .= ' - - '; - foreach ($this->fieldsDisplay AS $field) - $content .= ''.$field['title'].''; - $content .= ' - '; - - $attributes = array(); - $prevAttributeId = ''; - foreach ($this->_list['obj'] AS $prod) - { - if ($prevAttributeId == $prod['id_product_attribute']) - $prod['combination_name'] = $attributes[$prod['id_product_attribute']]['combination_name'].', '.$prod['group_name'].' : '.$prod['attribute_name']; - else - $prod['combination_name'] = $prod['group_name'].' : '.$prod['attribute_name']; - - - $attributes[$prod['id_product_attribute']] = $prod; - $prevAttributeId = $prod['id_product_attribute']; - } - - foreach ($attributes AS $prod) - { - $product = new Product((int)$prod['id_product'], false); - $tax_rate = $product->getTaxesRate(); - - $content .= ' - - - - - - - - - - - - '; - } - $content .= '
'.$prod['id_product'].''.($prod['manufacturer_name'] != NULL ? stripslashes($prod['manufacturer_name']) : '--').''.$prod['reference'].''.stripslashes($prod['name']).' ('.$prod['combination_name'].')'.''.Tools::displayPrice(Product::getPriceStatic((int)($prod['id_product']), true, $prod['id_product_attribute']), $this->context->currency).''.(float)$tax_rate.'% '.$prod['quantity'].''.($prod['weight'] + $prod['product_weight']).' '.Configuration::get('PS_WEIGHT_UNIT').' - - '.$this->l('Modify this product').'  - - '.$this->l('Delete this product').' -


'; - } - return $content; - } public function getCustomListProductsNoStock() { $this->clearListOptions(); @@ -307,38 +210,40 @@ class AdminTrackingControllerCore extends AdminController $this->identifier = 'id_product'; $this->_defaultOrderBy = 'id_product'; $this->_defaultOrderWay = 'DESC'; - $this->fieldsDisplay = array( - 'ID' => array('title' => $this->l('ID')), - 'manufacturer' => array('title' => $this->l('Manufacturer')), - 'reference' => array('title' => $this->l('Reference')), - 'name' => array('title' => $this->l('Name')), - 'price' => array('title' => $this->l('Price')), - 'tax' => array('title' => $this->l('Tax')), - 'stock' => array('title' => $this->l('Stock')), - 'weight' => array('title' => $this->l('Weight')), - 'active' => array('title' => $this->l('Status'), 'type' => 'bool', 'active' => 'status'), - 'action' => array('title' => $this->l('Actions') - )); - $this->_join = ''; - $this->_filter = 'AND a.id_product IN ( - SELECT id_product - FROM `'._DB_PREFIX_.'product` - WHERE id_product NOT IN ( - SELECT DISTINCT(id_product) - FROM `'._DB_PREFIX_.'product_attribute` - ) - AND quantity <= 0)'; - $this->list_title = $this->l('Product out of stock'); - $this->list_simple_header = true; + $this->show_toolbar = false; + self::$currentIndex = 'index.php?controller=AdminProducts'; + $this->token = Tools::getAdminTokenLite('AdminProducts'); - $list = $this->initList(); - $this->_filter = ''; - return $list; + $this->fieldsDisplay = array( + 'ID' => array('title' => $this->l('ID')), + 'manufacturer' => array('title' => $this->l('Manufacturer')), + 'reference' => array('title' => $this->l('Reference')), + 'name' => array('title' => $this->l('Name')), + 'price' => array('title' => $this->l('Price')), + 'tax' => array('title' => $this->l('Tax')), + 'stock' => array('title' => $this->l('Stock')), + 'weight' => array('title' => $this->l('Weight')), + 'active' => array('title' => $this->l('Status'), 'type' => 'bool', 'active' => 'status') + ); + + $this->_filter = 'AND a.id_product IN ( + SELECT id_product + FROM `'._DB_PREFIX_.'product` + WHERE id_product NOT IN ( + SELECT DISTINCT(id_product) + FROM `'._DB_PREFIX_.'product_attribute` + ) + AND quantity <= 0 + )'; + + $this->tpl_list_vars = array('sub_title' => $this->l('List of out of stock products with attributes:')); + + return parent::initList(); } + public function getCustomListProductsDisabled() { $this->clearListOptions(); - $content = ''; $this->table = 'product'; $this->lang = true; $this->identifier = 'id_product'; @@ -346,68 +251,16 @@ class AdminTrackingControllerCore extends AdminController $this->_defaultOrderWay = 'DESC'; $this->_filter = 'AND active = 0'; $this->list_no_filter = true; - $this->list_title = $this->l('Product disabled'); - $this->list_simple_header = true; - $list = $this->initList(); - $this->_filter = ''; - return $list; + $this->tpl_list_vars = array('sub_title' => $this->l('List of disabled products:')); + $this->show_toolbar = false; + self::$currentIndex = 'index.php?controller=AdminProducts'; + $this->token = Tools::getAdminTokenLite('AdminProducts'); - if (isset($this->_list['obj'])) - { - $nbProducts = sizeof($this->_list['obj']); - $content .= '

'.$this->_list['message'].' '.$nbProducts.' '.$this->l('found').'

'; - if (!$nbProducts) - return ; - $this->fieldsDisplay = (array( - 'ID' => array('title' => $this->l('ID')), - 'manufacturer' => array('title' => $this->l('Manufacturer')), - 'reference' => array('title' => $this->l('Reference')), - 'name' => array('title' => $this->l('Name')), - 'price' => array('title' => $this->l('Price')), - 'tax' => array('title' => $this->l('Tax')), - 'stock' => array('title' => $this->l('Stock')), - 'weight' => array('title' => $this->l('Weight')), - 'status' => array('title' => $this->l('Status')), - 'action' => array('title' => $this->l('Actions')) - )); - $content .= ' - - '; - foreach ($this->fieldsDisplay AS $field) - $content .= ''.$field['title'].''; - $content .= ' - '; - foreach ($this->_list['obj'] AS $k => $prod) - { - $product = new Product((int)$prod['id_product'], false); - $product->name = $product->name[(int)$this->context->language->id]; - $taxrate = $product->getTaxesRate(); - - $content .= ' - - - - - - - - - - - - '; - } - $content .= '
'.$product->id.''.($product->manufacturer_name != NULL ? stripslashes($product->manufacturer_name) : '--').''.$product->reference.''.stripslashes($product->name).''.Tools::displayPrice($product->getPrice(), $this->context->currency).''.(float)$taxrate.'% '.$product->quantity.''.$product->weight.' '.Configuration::get('PS_WEIGHT_UNIT').' - - '.$this->l('Modify this product').'  - name)).' ?\');"> - '.$this->l('Delete this product').' -


'; - } - return $content; + return parent::initList(); } - public function clearListOptions(){ + public function clearListOptions() + { $this->table = ''; $this->lang = false; $this->identifier = '';