* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 7019 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class AdminTracking extends AdminTab { public function __construct() { $this->table = 'none'; $this->className = 'none'; parent::__construct(); } public function display() { global $currentIndex; echo '

'.$this->l('Catalog tracking').'

'; $this->getObjects('categories_empty'); $this->displayCategories(); $this->getObjects('products_disabled'); $this->displayProducts(); $this->getObjects('products_nostock'); $this->displayProducts(); $this->getObjects('attributes_nostock'); $this->displayAttributes(); } public function getObjects($type) { global $cookie; switch ($type) { case 'categories_empty': $sql = ' SELECT id_category FROM `'._DB_PREFIX_.'category` WHERE id_category NOT IN ( SELECT DISTINCT(id_category) FROM `'._DB_PREFIX_.'category_product` ) '; $this->_list['message'] = $this->l('List of empty categories:'); break ; case 'products_disabled': $sql = ' SELECT * FROM `'._DB_PREFIX_.'product` WHERE active = 0 '; $this->_list['message'] = $this->l('List of disabled products:'); break ; case 'products_nostock': $sql = ' SELECT DISTINCT(id_product) FROM `'._DB_PREFIX_.'product` WHERE 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['message'] = $this->l('List of out of stock products without attributes:'); 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)($cookie->id_lang).') LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)($cookie->id_lang).') 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)($cookie->id_lang).') LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (p.`id_manufacturer` = m.`id_manufacturer`) WHERE pa.quantity <= 0 ORDER BY pa.`id_product_attribute` '; $this->_list['message'] = $this->l('List of out of stock products with attributes:'); break ; } $this->_list['obj'] = Db::getInstance()->ExecuteS($sql); } public function displayCategories() { global $currentIndex; if (isset($this->_list['obj'])) { $nbCategories = sizeof($this->_list['obj']); echo '

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

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


'; } } public function displayProducts() { global $currentIndex, $cookie; if (isset($this->_list['obj'])) { $nbProducts = sizeof($this->_list['obj']); echo '

'.$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')) )); $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); echo ' '; foreach ($this->fieldsDisplay AS $field) echo ''.$field['title'].''; echo ' '; foreach ($this->_list['obj'] AS $k => $prod) { $product = new Product((int)($prod['id_product'])); $product->name = $product->name[(int)($cookie->id_lang)]; $taxrate = Tax::getProductTaxRate($product->id); echo ' '; } echo '
'.$product->id.' '.($product->manufacturer_name != NULL ? stripslashes($product->manufacturer_name) : '--').' '.$product->reference.' '.stripslashes($product->name).' '.Tools::displayPrice($product->getPrice(), $currency).' '.(float)$taxrate.'% '.$product->quantity.' '.$product->weight.' '.Configuration::get('PS_WEIGHT_UNIT').' '.$this->l('Modify this product').'  name)).' ?\');"> '.$this->l('Delete this product').'


'; } } public function displayAttributes() { global $currentIndex, $cookie; if (isset($this->_list['obj'])) { $nbAttributes = sizeof($this->_list['obj']); echo '

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

'; if (!$nbAttributes) 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')) )); $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); echo ' '; foreach ($this->fieldsDisplay AS $field) echo ''.$field['title'].''; echo ' '; $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) { $taxrate = Tax::getProductTaxRate($prod['id_product']); echo ' '; } echo '
'.$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']), $currency).' '.(float)$taxrate.'% '.$prod['quantity'].' '.($prod['weight'] + $prod['product_weight']).' '.Configuration::get('PS_WEIGHT_UNIT').' '.$this->l('Modify this product').'  '.$this->l('Delete this product').'


'; } } }